]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: callback: add a kill interface
authorMike Frysinger <vapier@gentoo.org>
Mon, 21 Jun 2021 03:06:10 +0000 (23:06 -0400)
committerMike Frysinger <vapier@gentoo.org>
Thu, 24 Jun 2021 00:05:14 +0000 (20:05 -0400)
This will make it easier to emulate the syscall.  If the kill target
is the sim itself, don't do anything.  This forces the higher layers
to make a decision as to how to handle this event: like halting the
overall engine process.

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

index b98631b37e5a5b08dd0414d38d9771e4800cb963..3faea5828942ca5a2573ecebe7245337adfd9b17 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-23  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim/callback.h (struct host_callback_struct): Add kill.
+
 2021-06-22  Mike Frysinger  <vapier@gentoo.org>
 
        * sim/callback.h (struct host_callback_struct): Add getpid.
index a6c536b1be1c4d9be60cfa53ce57cb151b56f121..8d61ebb879e8c5a204b7667ff7ac12398ee11f0e 100644 (file)
@@ -92,6 +92,7 @@ struct host_callback_struct
   int (*ftruncate) (host_callback *, int, int64_t);
   int (*truncate) (host_callback *, const char *, int64_t);
   int (*getpid) (host_callback *);
+  int (*kill) (host_callback *, int, int);
   int (*pipe) (host_callback *, int *);
 
   /* Called by the framework when a read call has emptied a pipe buffer.  */
index bb1a967c298cae0afdcb07a3616809b6ee9116cc..c32e7475a80c64f4bfedbbbd26cd449b8b4d2eb4 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-23  Mike Frysinger  <vapier@gentoo.org>
+
+       * callback.c (os_kill): New function.
+       (default_callback): Add os_kill.
+       * syscall.c (cb_syscall): Handle CB_SYS_kill.
+
 2021-06-23  Mike Frysinger  <vapier@gentoo.org>
 
        * Make-common.in (srcdir): Change to abs_srcdir.
index 06d76b47724576bce9d6ad1daa6426771b520045..c0ace6e4c8e58753af83df10bb1a1645c75071a8 100644 (file)
@@ -569,6 +569,16 @@ os_getpid (host_callback *p)
   return result;
 }
 
+static int
+os_kill (host_callback *p, int pid, int signum)
+{
+  int result;
+
+  result = kill (pid, signum);
+  p->last_errno = errno;
+  return result;
+}
+
 static int
 os_pipe (host_callback *p, int *filedes)
 {
@@ -752,6 +762,7 @@ host_callback default_callback =
   os_truncate,
 
   os_getpid,
+  os_kill,
 
   os_pipe,
   os_pipe_empty,
index 7ef34b95e9cfcf2db2a2450093dcb9f3de681ca3..6efddcfecde80abc0da203b153e8090e71f06713 100644 (file)
@@ -583,6 +583,24 @@ cb_syscall (host_callback *cb, CB_SYSCALL *sc)
       result = (*cb->getpid) (cb);
       break;
 
+    case CB_SYS_kill:
+      /* If killing self, leave it to the caller to process so it can send the
+        signal to the engine.  */
+      if (sc->arg1 == (*cb->getpid) (cb))
+       {
+         result = -1;
+         errcode = ENOSYS;
+       }
+      else
+       {
+         int signum = cb_target_to_host_signal (cb, sc->arg2);
+
+         result = (*cb->kill) (cb, sc->arg1, signum);
+         cb->last_errno = errno;
+         goto ErrorFinish;
+       }
+      break;
+
     case CB_SYS_time :
       {
        /* FIXME: May wish to change CB_SYS_time to something else.