]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: callback: add a getpid interface
authorMike Frysinger <vapier@gentoo.org>
Sun, 20 Jun 2021 16:38:27 +0000 (12:38 -0400)
committerMike Frysinger <vapier@gentoo.org>
Tue, 22 Jun 2021 23:36:28 +0000 (19:36 -0400)
Rather than hit the OS interface directly, use the existing callback
layer so the instantiator can decide behavior.

include/sim/ChangeLog
include/sim/callback.h
sim/common/ChangeLog
sim/common/callback.c
sim/common/syscall.c

index 4fe3bc0240326eb92e7ac21b6e8a4f39f3b6179b..b98631b37e5a5b08dd0414d38d9771e4800cb963 100644 (file)
@@ -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
index 4c162bc145eaf494f46876a41de45d2e2c0f5cf3..a6c536b1be1c4d9be60cfa53ce57cb151b56f121 100644 (file)
@@ -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.  */
index bcf92420fd967213bcd6bb5d9ea3cb5a94d3bbaa..5545771902967f51a7c93b0120854a5def64afce 100644 (file)
@@ -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).
index f2587a4525403e5dcd92dc2f4d73c5cdf6780d98..071e7b149b97fcc896bb8a84f46b5b62aa17e155 100644 (file)
@@ -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,
index 4e76d2008a30d3287a6594b51fdfdadbde0c7015..7ef34b95e9cfcf2db2a2450093dcb9f3de681ca3 100644 (file)
@@ -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 :