PERFORCE change 152802 for review

Peter Wemm peter at FreeBSD.org
Tue Nov 11 00:34:41 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=152802

Change 152802 by peter at peter_hammer on 2008/11/11 08:34:25

	Add thr_kill / thr_kill2

Affected files ...

.. //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#16 edit
.. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#30 edit

Differences ...

==== //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#16 (text+ko) ====

@@ -259,6 +259,8 @@
 DECL_TEMPLATE(freebsd, sys_posix_openpt);
 DECL_TEMPLATE(freebsd, sys_uuidgen);
 DECL_TEMPLATE(freebsd, sys_thr_new);
+DECL_TEMPLATE(freebsd, sys_thr_kill);
+DECL_TEMPLATE(freebsd, sys_thr_kill2);
 #endif   // __PRIV_SYSWRAP_FREEBSD_H
 
 /*--------------------------------------------------------------------*/

==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#30 (text+ko) ====

@@ -1820,6 +1820,87 @@
    PRE_MEM_RASCIIZ( "sys_thr_set_name(threadname)", ARG2);
 }
 
+PRE(sys_thr_kill)
+{
+   PRINT("sys_thr_kill ( %ld, %ld )", ARG1,ARG2);
+   PRE_REG_READ2(long, "thr_kill", long, id, int, sig);
+   if (!ML_(client_signal_OK)(ARG2)) {
+      SET_STATUS_Failure( VKI_EINVAL );
+      return;
+   }
+
+   /* Check to see if this kill gave us a pending signal */
+   *flags |= SfPollAfter;
+
+   if (VG_(clo_trace_signals))
+      VG_(message)(Vg_DebugMsg, "thr_kill: sending signal %ld to tid %ld",
+                   ARG2, ARG1);
+
+   /* If we're sending SIGKILL, check to see if the target is one of
+      our threads and handle it specially. */
+   if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) {
+      SET_STATUS_Success(0);
+      return;
+   }
+
+   /* Ask to handle this syscall via the slow route, since that's the
+      only one that sets tst->status to VgTs_WaitSys.  If the result
+      of doing the syscall is an immediate run of
+      async_signalhandler() in m_signals, then we need the thread to
+      be properly tidied away.  I have the impression the previous
+      version of this wrapper worked on x86/amd64 only because the
+      kernel did not immediately deliver the async signal to this
+      thread (on ppc it did, which broke the assertion re tst->status
+      at the top of async_signalhandler()). */
+   *flags |= SfMayBlock;
+}
+POST(sys_thr_kill)
+{
+   if (VG_(clo_trace_signals))
+      VG_(message)(Vg_DebugMsg, "thr_kill: sent signal %ld to tid %ld",
+                   ARG2, ARG1);
+}
+PRE(sys_thr_kill2)
+{
+   PRINT("sys_thr_kill2 ( %ld, %ld, %ld )", ARG1,ARG2,ARG3);
+   PRE_REG_READ3(long, "tgkill", int, pid, long, tid, int, sig);
+   if (!ML_(client_signal_OK)(ARG3)) {
+      SET_STATUS_Failure( VKI_EINVAL );
+      return;
+   }
+
+   /* Check to see if this kill gave us a pending signal */
+   *flags |= SfPollAfter;
+
+   if (VG_(clo_trace_signals))
+      VG_(message)(Vg_DebugMsg, "thr_kill2: sending signal %ld to pid %ld/%ld",
+                   ARG3, ARG1, ARG2);
+
+   /* If we're sending SIGKILL, check to see if the target is one of
+      our threads and handle it specially. */
+   if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) {
+      SET_STATUS_Success(0);
+      return;
+   }
+
+   /* Ask to handle this syscall via the slow route, since that's the
+      only one that sets tst->status to VgTs_WaitSys.  If the result
+      of doing the syscall is an immediate run of
+      async_signalhandler() in m_signals, then we need the thread to
+      be properly tidied away.  I have the impression the previous
+      version of this wrapper worked on x86/amd64 only because the
+      kernel did not immediately deliver the async signal to this
+      thread (on ppc it did, which broke the assertion re tst->status
+      at the top of async_signalhandler()). */
+   *flags |= SfMayBlock;
+}
+POST(sys_thr_kill2)
+{
+   if (VG_(clo_trace_signals))
+      VG_(message)(Vg_DebugMsg, "thr_kill2: sent signal %ld to pid %ld/%ld",
+                   ARG3, ARG1, ARG2);
+}
+
 /* ---------------------------------------------------------------------
    umtx* wrappers
    ------------------------------------------------------------------ */
@@ -3505,7 +3586,7 @@
    BSDX_(__NR_thr_exit,			sys_thr_exit),			// 431
 
    BSDXY(__NR_thr_self, 		sys_thr_self),			// 432
-   // thr_kill								   433
+   BSDXY(__NR_thr_kill,                 sys_thr_kill),			// 433
    BSDXY(__NR__umtx_lock,		sys__umtx_lock),		// 434
    BSDXY(__NR__umtx_unlock,		sys__umtx_unlock),		// 435
 
@@ -3565,7 +3646,7 @@
    BSDX_(__NR_truncate7,		sys_truncate7),			// 479
 
    BSDX_(__NR_ftruncate7,		sys_ftruncate7),		// 480
-   // thr_kill2								   481
+   BSDXY(__NR_thr_kill2,                sys_thr_kill2),			// 481
    // shm_open								   482
    // shm_unlink							   483
 


More information about the p4-projects mailing list