From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] sim: callback: add a getpid interface
Date: Sun, 20 Jun 2021 23:55:03 -0400 [thread overview]
Message-ID: <20210621035505.29431-1-vapier@gentoo.org> (raw)
Rather than hit the OS interface directly, use the existing callback
layer so the instantiator can decide behavior.
---
include/sim/callback.h | 1 +
sim/common/callback.c | 13 +++++++++++++
sim/common/syscall.c | 3 ++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/sim/callback.h b/include/sim/callback.h
index 4c162bc145ea..a6c536b1be1c 100644
--- a/include/sim/callback.h
+++ b/include/sim/callback.h
@@ -91,6 +91,7 @@ struct host_callback_struct
int (*to_lstat) (host_callback *, const char *, struct stat *);
int (*ftruncate) (host_callback *, int, int64_t);
int (*truncate) (host_callback *, const char *, int64_t);
+ int (*getpid) (host_callback *);
int (*pipe) (host_callback *, int *);
/* Called by the framework when a read call has emptied a pipe buffer. */
diff --git a/sim/common/callback.c b/sim/common/callback.c
index f2587a452540..071e7b149b97 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -556,6 +556,17 @@ os_truncate (host_callback *p, const char *file, int64_t len)
#endif
}
+static int
+os_getpid (host_callback *p)
+{
+ int result;
+
+ result = getpid ();
+ /* POSIX says getpid always succeeds. */
+ p->last_errno = 0;
+ return result;
+}
+
static int
os_pipe (host_callback *p, int *filedes)
{
@@ -737,6 +748,8 @@ host_callback default_callback =
os_ftruncate,
os_truncate,
+ os_getpid,
+
os_pipe,
os_pipe_empty,
os_pipe_nonempty,
diff --git a/sim/common/syscall.c b/sim/common/syscall.c
index 4e76d2008a30..7ef34b95e9cf 100644
--- a/sim/common/syscall.c
+++ b/sim/common/syscall.c
@@ -579,7 +579,8 @@ cb_syscall (host_callback *cb, CB_SYSCALL *sc)
break;
case CB_SYS_getpid:
- result = getpid ();
+ /* POSIX says getpid always succeeds. */
+ result = (*cb->getpid) (cb);
break;
case CB_SYS_time :
--
2.31.1
next reply other threads:[~2021-06-21 3:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-21 3:55 Mike Frysinger [this message]
2021-06-21 3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
2021-06-21 3:55 ` [PATCH 3/3] sim: callback: add missing cb_target_to_host_signal Mike Frysinger
2021-06-21 22:58 ` [PATCH 1/3] sim: callback: add a getpid interface Christian Biesinger
2021-06-21 23:50 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210621035505.29431-1-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).