[binutils-gdb] sim: callback: add a getpid interface

Michael Frysinger vapier@sourceware.org
Tue Jun 22 23:36:33 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c45cffdbe1a1b816fd9a88f88bb83bd7078a1e4e

commit c45cffdbe1a1b816fd9a88f88bb83bd7078a1e4e
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Sun Jun 20 12:38:27 2021 -0400

    sim: callback: add a getpid interface
    
    Rather than hit the OS interface directly, use the existing callback
    layer so the instantiator can decide behavior.

Diff:
---
 include/sim/ChangeLog  |  4 ++++
 include/sim/callback.h |  1 +
 sim/common/ChangeLog   |  6 ++++++
 sim/common/callback.c  | 13 +++++++++++++
 sim/common/syscall.c   |  3 ++-
 5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/include/sim/ChangeLog b/include/sim/ChangeLog
index 4fe3bc02403..b98631b37e5 100644
--- a/include/sim/ChangeLog
+++ b/include/sim/ChangeLog
@@ -1,3 +1,7 @@
+2021-06-22  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim/callback.h (struct host_callback_struct): Add getpid.
+
 2021-05-14  Mike Frysinger  <vapier@gentoo.org>
 
 	* sim/callback.h (struct host_callback_struct): Change lseek return and
diff --git a/include/sim/callback.h b/include/sim/callback.h
index 4c162bc145e..a6c536b1be1 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/ChangeLog b/sim/common/ChangeLog
index bcf92420fd9..55457719029 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,9 @@
+2021-06-22  Mike Frysinger  <vapier@gentoo.org>
+
+	* callback.c (os_getpid): New function.
+	(default_callback): Add os_getpid.
+	* syscall.c (cb_syscall): Change getpid to cb->getpid.
+
 2021-06-22  Mike Frysinger  <vapier@gentoo.org>
 
 	* Make-common.in (VPATH): Use $(srcdir).
diff --git a/sim/common/callback.c b/sim/common/callback.c
index f2587a45254..071e7b149b9 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 4e76d2008a3..7ef34b95e9c 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 :


More information about the Binutils-cvs mailing list