public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] sim: callback: add a getpid interface
@ 2021-06-21  3:55 Mike Frysinger
  2021-06-21  3:55 ` [PATCH 2/3] sim: callback: generate signal map Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mike Frysinger @ 2021-06-21  3:55 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-21 23:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21  3:55 [PATCH 1/3] sim: callback: add a getpid interface Mike Frysinger
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

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).