From 042441c57f68a204b9bb3f3c9295c56c7f73dc96 Mon Sep 17 00:00:00 2001 From: Rhys Kidd Date: Sun, 12 Jul 2015 06:54:56 +0000 Subject: [PATCH] Fix Valgrind does not support pthread_sigmask() on OS X bz#201216 On OS X 10.10 Before: == 592 tests, 220 stderr failures, 15 stdout failures, 0 stderrB failures, 0 stdoutB failures, 30 post failures == After: == 592 tests, 219 stderr failures, 15 stdout failures, 0 stderrB failures, 0 stdoutB failures, 30 post failures == git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15410 --- NEWS | 1 + coregrind/m_syswrap/syscall-x86-darwin.S | 4 +-- coregrind/m_syswrap/syswrap-darwin.c | 44 +++++++++++++++++++++--- memcheck/tests/darwin/scalar.c | 4 ++- memcheck/tests/darwin/scalar.stderr.exp | 9 +++++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index a4627598af..b4c9f03237 100644 --- a/NEWS +++ b/NEWS @@ -103,6 +103,7 @@ where XXXXXX is the bug number as listed below. 155125 avoid cutting away file:lineno after long function name 197259 Unsupported arch_prtctl PR_SET_GS option 201152 ppc64: Assertion in ppc32g_dirtyhelper_MFSPR_268_269 +201216 Fix Valgrind does not support pthread_sigmask() on OS X 201435 Fix Darwin: -v does not show kernel version 208217 "Warning: noted but unhandled ioctl 0x2000747b" on Mac OS X 211256 Fixed an outdated comment regarding the default platform. diff --git a/coregrind/m_syswrap/syscall-x86-darwin.S b/coregrind/m_syswrap/syscall-x86-darwin.S index 288520d093..73d1b2d8c3 100644 --- a/coregrind/m_syswrap/syscall-x86-darwin.S +++ b/coregrind/m_syswrap/syscall-x86-darwin.S @@ -89,9 +89,9 @@ L_$0_1: /* Even though we can't take a signal until the __pthread_sigmask completes, start the range early. - If eip is in the range [1,2), the syscall hasn't been started yet */ + If eip is in the range [1,2), the syscall hasn't been started yet */ - /* Set the signal mask which should be current during the syscall. */ + /* Set the signal mask which should be current during the syscall. */ /* Set up for __pthread_sigmask(SIG_SETMASK, sysmask, postmask) */ pushl 20(%ebp) pushl 16(%ebp) diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index 38f823d418..f804ade25c 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -2142,11 +2142,45 @@ PRE(__pthread_kill) PRE(__pthread_sigmask) { - // GrP fixme - // JRS: arguments are identical to sigprocmask - // (how, sigset_t*, sigset_t*). Perhaps behave identically? - log_decaying("UNKNOWN __pthread_sigmask is unsupported."); - SET_STATUS_Success( 0 ); + // arguments are identical to sigprocmask (how, sigset_t*, sigset_t*). + UWord arg1; + PRINT("__pthread_sigmask ( %ld, %#lx, %#lx )", ARG1, ARG2, ARG3); + PRE_REG_READ3(long, "__pthread_sigmask", + int, how, vki_sigset_t *, set, vki_sigset_t *, oldset); + if (ARG2 != 0) + PRE_MEM_READ( "__pthread_sigmask(set)", ARG2, sizeof(vki_sigset_t)); + if (ARG3 != 0) + PRE_MEM_WRITE( "__pthread_sigmask(oldset)", ARG3, sizeof(vki_sigset_t)); + + /* Massage ARG1 ('how'). If ARG2 (the new mask) is NULL then the + value of 'how' is irrelevant, and it appears that Darwin's libc + passes zero, which is not equal to any of + SIG_{BLOCK,UNBLOCK,SETMASK}. This causes + VG_(do_sys_sigprocmask) to complain, since it checks the 'how' + value independently of the other args. Solution: in this case, + simply pass a valid (but irrelevant) value for 'how'. */ + /* Also, in this case the new set is passed to the kernel by + reference, not value, as in some other sigmask related Darwin + syscalls. */ + arg1 = ARG1; + if (ARG2 == 0 /* the new-set is NULL */ + && ARG1 != VKI_SIG_BLOCK + && ARG1 != VKI_SIG_UNBLOCK && ARG1 != VKI_SIG_SETMASK) { + arg1 = VKI_SIG_SETMASK; + } + SET_STATUS_from_SysRes( + VG_(do_sys_sigprocmask) ( tid, arg1, (vki_sigset_t*)ARG2, + (vki_sigset_t*)ARG3 ) + ); + + if (SUCCESS) + *flags |= SfPollAfter; +} +POST(__pthread_sigmask) +{ + vg_assert(SUCCESS); + if (RES == 0 && ARG3 != 0) + POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t)); } diff --git a/memcheck/tests/darwin/scalar.c b/memcheck/tests/darwin/scalar.c index 5b8a3fb21a..af4def4d32 100644 --- a/memcheck/tests/darwin/scalar.c +++ b/memcheck/tests/darwin/scalar.c @@ -589,7 +589,9 @@ int main(void) GO(__NR___pthread_kill, 328, "2s 0m"); SY(__NR___pthread_kill, x0, x0); FAIL; - // __NR___pthread_sigmask 329 + GO(__NR___pthread_sigmask, 329, "3s 0m"); + SY(__NR___pthread_sigmask, x0, x0, x0); SUCC; + // __NR___sigwait 330 // __NR_sigwait 330) // GrP fixme hack // __NR___disable_threadsignal 331 diff --git a/memcheck/tests/darwin/scalar.stderr.exp b/memcheck/tests/darwin/scalar.stderr.exp index 6278d25222..00ee89bd16 100644 --- a/memcheck/tests/darwin/scalar.stderr.exp +++ b/memcheck/tests/darwin/scalar.stderr.exp @@ -861,6 +861,15 @@ Syscall param __pthread_kill(thread) contains uninitialised byte(s) Syscall param __pthread_kill(sig) contains uninitialised byte(s) ... +----------------------------------------------------- +x2000149(329):__NR___pthread_sigmask 3s 0m +----------------------------------------------------- +Syscall param __pthread_sigmask(set) contains uninitialised byte(s) + ... + +Syscall param __pthread_sigmask(oldset) contains uninitialised byte(s) + ... + ----------------------------------------------------- (335): old utrace ----------------------------------------------------- -- 2.47.2