I have built OpenSC from master branch on Github.com/OpenSC/OpenSC. I am trying to verify its memory usage with valgrind. I am trying to execute command valgrind pkcs11-tool -t -l to perform pkcs11 tests. It fails with this assertion: valgrind: m_syswrap/syswrap-amd64-darwin.c:507 (void wqthread_hijack(Addr, Addr, Addr, Addr, Int, Addr)): Assertion 'tst->os_state.pthread - magic_delta == self' failed Reproducible: Always Steps to Reproduce: 1. On Mac OS X 10.11.4 with Xcode-7.3.1 install valgrind via Macports. 2. Clone, build and install https://Github.com/OpenSC/OpenSC.git 3. Run "valgrind pkcs11-tool -t -l" Actual Results: $ valgrind pkcs11-tool -t -l ==23584== Memcheck, a memory error detector ==23584== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==23584== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==23584== Command: pkcs11-tool -t -l ==23584== --23584-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option --23584-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times) --23584-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times) valgrind: m_syswrap/syswrap-amd64-darwin.c:507 (void wqthread_hijack(Addr, Addr, Addr, Addr, Int, Addr)): Assertion 'tst->os_state.pthread - magic_delta == self' failed. host stacktrace: ==23584== at 0x23803FC97: ??? ==23584== by 0x238040094: ??? ==23584== by 0x238040077: ??? ==23584== by 0x2380DE3E1: ??? sched status: running_tid=0 Thread 1: status = VgTs_WaitSys (lwpid 2567) ==23584== at 0x1007C8FAE: semaphore_wait_trap (in /usr/lib/system/libsystem_kernel.dylib) ==23584== by 0x1005D7CB1: _dispatch_semaphore_wait_slow (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x100986EA4: xpc_connection_send_message_with_reply_sync (in /usr/lib/system/libxpc.dylib) ==23584== by 0x1015877FD: transact (in /System/Library/Frameworks/PCSC.framework/Versions/A/PCSC) ==23584== by 0x1000806AC: pcsc_detect_readers (in /Library/OpenSC/lib/libopensc.4.dylib) ==23584== by 0x10003596D: sc_ctx_detect_readers (in /Library/OpenSC/lib/libopensc.4.dylib) ==23584== by 0x100035D80: sc_context_create (in /Library/OpenSC/lib/libopensc.4.dylib) ==23584== by 0x10154FBC4: C_Initialize (in /Library/OpenSC/lib/opensc-pkcs11.so) ==23584== by 0x100001CAF: main (in /usr/local/bin/pkcs11-tool) Thread 2: status = VgTs_WaitSys (lwpid 3587) ==23584== at 0x1007CF5E2: __workq_kernreturn (in /usr/lib/system/libsystem_kernel.dylib) ==23584== by 0x2380DE3E1: ??? ==23584== by 0x2382001AF: ??? ==23584== by 0x70000311EDAF: ??? ==23584== by 0x70000000BABF: ??? Thread 3: status = VgTs_WaitSys (lwpid 6147) ==23584== at 0x1007C8F72: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib) ==23584== by 0x1007C83B2: mach_msg (in /usr/lib/system/libsystem_kernel.dylib) ==23584== by 0x1007BE03B: _kernelrpc_mach_port_request_notification (in /usr/lib/system/libsystem_kernel.dylib) ==23584== by 0x1005D4FCC: _dispatch_kevent_mach_notify_resume (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D51BC: _dispatch_kevent_unregister (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D3FD1: _dispatch_mach_msg_send (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D3A20: _dispatch_mach_msg_send (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D4B23: _dispatch_mach_send_drain (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D3458: _dispatch_mach_invoke (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D11FF: _dispatch_queue_drain (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D21DE: _dispatch_mgr_queue_drain (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D20B9: _dispatch_mgr_invoke (in /usr/lib/system/libdispatch.dylib) ==23584== by 0x1005D1DCC: _dispatch_mgr_thread (in /usr/lib/system/libdispatch.dylib) Note: see also the FAQ in the source distribution. It contains workarounds to several common problems. In particular, if Valgrind aborted or crashed after identifying problems in your program, there's a good chance that fixing those problems will prevent Valgrind aborting or crashing, especially if it happened in m_mallocfree.c. If that doesn't help, please report this bug to: www.valgrind.org In the bug report, send all the above text, the valgrind version, and what OS and version you are using. Thanks. $ Expected Results: Valgrind analysis of memory usage by pkcs11-tool and dynamic libraries it loads. Mac OS X 10.11.4. Xcode-7.3.1. OpenSC master branch (probably less relevant). Valgrind-3.11.0 installed by Macports.
$ uname -a Darwin Uris-MacBook-Air.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64 $ valgrind -v pkcs11-tool -t -l ==23708== Memcheck, a memory error detector ==23708== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==23708== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==23708== Command: pkcs11-tool -t -l ==23708== --23708-- Valgrind options: --23708-- -v --23708-- Output from sysctl({CTL_KERN,KERN_VERSION}): --23708-- Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 --23708-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi --23708-- Page sizes: currently 4096, max supported 4096 --23708-- Valgrind library directory: /opt/local/lib/valgrind --23708-- /usr/local/bin/pkcs11-tool (rx at 0x100000000, rw at 0x10001b000) --23708-- reading syms from primary file (20 142) --23708-- /usr/lib/dyld (rx at 0x7fff5fc00000, rw at 0x7fff5fc38000) --23708-- reading syms from primary file (6 1226) --23708-- Scheduler: using generic scheduler lock implementation. --23708-- Reading suppressions file: /opt/local/lib/valgrind/default.supp ==23708== embedded gdbserver: reading from /var/folders/pd/mxn5kp_55jg23x7jjd10gtwm0000gn/T//vgdb-pipe-from-vgdb-to-23708-by-uri-on-??? ==23708== embedded gdbserver: writing to /var/folders/pd/mxn5kp_55jg23x7jjd10gtwm0000gn/T//vgdb-pipe-to-vgdb-from-23708-by-uri-on-??? ==23708== embedded gdbserver: shared mem /var/folders/pd/mxn5kp_55jg23x7jjd10gtwm0000gn/T//vgdb-pipe-shared-mem-vgdb-23708-by-uri-on-??? ==23708== ==23708== TO CONTROL THIS PROCESS USING vgdb (which you probably ==23708== don't want to do, unless you know exactly what you're doing, ==23708== or are doing some strange experiment): ==23708== /opt/local/lib/valgrind/../../bin/vgdb --pid=23708 ...command... ==23708== ==23708== TO DEBUG THIS PROCESS USING GDB: start GDB like this ==23708== /path/to/gdb pkcs11-tool ==23708== and then give GDB the following command ==23708== target remote | /opt/local/lib/valgrind/../../bin/vgdb --pid=23708 ==23708== --pid is optional if only one valgrind process is running ==23708== --23708-- REDIR: 0x7fff5fc1e679 (dyld:arc4random) redirected to 0x23805a8de (???) --23708-- REDIR: 0x7fff5fc24840 (dyld:strcmp) redirected to 0x23805a840 (???) --23708-- REDIR: 0x7fff5fc21ddf (dyld:strlcat) redirected to 0x23805a879 (???) --23708-- REDIR: 0x7fff5fc1e440 (dyld:strlen) redirected to 0x23805a80f (???) --23708-- REDIR: 0x7fff5fc1e3a0 (dyld:strcpy) redirected to 0x23805a85c (???) --23708-- REDIR: 0x7fff5fc21d9f (dyld:strcat) redirected to 0x23805a820 (???) --23708-- /opt/local/lib/valgrind/vgpreload_core-amd64-darwin.so (rx at 0x100022000, rw at 0x100024000) --23708-- reading syms from primary file (3 47) --23708-- dSYM= /opt/local/lib/valgrind/vgpreload_core-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_core-amd64-darwin.so --23708-- reading dwarf3 from dsyms file --23708-- /opt/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so (rx at 0x100026000, rw at 0x10002c000) --23708-- reading syms from primary file (72 356) --23708-- dSYM= /opt/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_memcheck-amd64-darwin.so --23708-- reading dwarf3 from dsyms file --23708-- /Library/OpenSC/lib/libopensc.4.dylib (rx at 0x100032000, rw at 0x100245000) --23708-- reading syms from primary file (335 2738) --23708-- /opt/local/lib/libssl.1.0.0.dylib (rx at 0x100282000, rw at 0x1002c6000) --23708-- reading syms from primary file (592 154) --23708-- /opt/local/lib/libcrypto.1.0.0.dylib (rx at 0x1002e1000, rw at 0x100463000) --23708-- reading syms from primary file (4157 1869) --23708-- /opt/local/lib/libz.1.2.8.dylib (rx at 0x1004d8000, rw at 0x1004e9000) --23708-- reading syms from primary file (80 65) --23708-- /usr/lib/libSystem.B.dylib (rx at 0x1004ec000, rw at 0x1004ee000) --23708-- reading syms from primary file (31 5) --23708-- /usr/lib/system/libcache.dylib (rx at 0x1004f3000, rw at 0x1004f8000) --23708-- reading syms from primary file (32 30) --23708-- /usr/lib/system/libcommonCrypto.dylib (rx at 0x1004fd000, rw at 0x100509000) --23708-- reading syms from primary file (214 188) --23708-- /usr/lib/system/libcompiler_rt.dylib (rx at 0x100516000, rw at 0x10051e000) --23708-- reading syms from primary file (510 8) --23708-- /usr/lib/system/libcopyfile.dylib (rx at 0x10052b000, rw at 0x100534000) --23708-- reading syms from primary file (13 35) --23708-- /usr/lib/system/libcorecrypto.dylib (rx at 0x10053a000, rw at 0x1005b2000) --23708-- reading syms from primary file (430 601) --23708-- /usr/lib/system/libdispatch.dylib (rx at 0x1005ca000, rw at 0x1005f8000) --23708-- reading syms from primary file (215 832) --23708-- /usr/lib/system/libdyld.dylib (rx at 0x100621000, rw at 0x100625000) --23708-- reading syms from primary file (80 109) --23708-- /usr/lib/system/libkeymgr.dylib (rx at 0x10062c000, rw at 0x10062d000) --23708-- reading syms from primary file (12 3) --23708-- /usr/lib/system/libmacho.dylib (rx at 0x100638000, rw at 0x10063e000) --23708-- reading syms from primary file (97 1) --23708-- /usr/lib/system/libquarantine.dylib (rx at 0x100644000, rw at 0x100647000) --23708-- reading syms from primary file (67 32) --23708-- /usr/lib/system/libremovefile.dylib (rx at 0x10064d000, rw at 0x10064f000) --23708-- reading syms from primary file (15 4) --23708-- /usr/lib/system/libsystem_asl.dylib (rx at 0x100654000, rw at 0x10066c000) --23708-- reading syms from primary file (222 225) --23708-- /usr/lib/system/libsystem_blocks.dylib (rx at 0x100679000, rw at 0x10067b000) --23708-- reading syms from primary file (25 22) --23708-- /usr/lib/system/libsystem_c.dylib (rx at 0x10067f000, rw at 0x10070d000) --23708-- reading syms from primary file (1303 748) --23708-- /usr/lib/system/libsystem_configuration.dylib (rx at 0x100738000, rw at 0x10073b000) --23708-- reading syms from primary file (28 57) --23708-- /usr/lib/system/libsystem_coreservices.dylib (rx at 0x100741000, rw at 0x100744000) --23708-- reading syms from primary file (13 30) --23708-- /usr/lib/system/libsystem_coretls.dylib (rx at 0x100749000, rw at 0x100761000) --23708-- reading syms from primary file (118 233) --23708-- /usr/lib/system/libsystem_dnssd.dylib (rx at 0x10076a000, rw at 0x100773000) --23708-- reading syms from primary file (68 33) --23708-- /usr/lib/system/libsystem_info.dylib (rx at 0x100779000, rw at 0x1007a3000) --23708-- reading syms from primary file (526 527) --23708-- /usr/lib/system/libsystem_kernel.dylib (rx at 0x1007b8000, rw at 0x1007d7000) --23708-- reading syms from primary file (1069 84) --23708-- /usr/lib/system/libsystem_m.dylib (rx at 0x1007ec000, rw at 0x10081c000) --23708-- reading syms from primary file (593 1) --23708-- /usr/lib/system/libsystem_malloc.dylib (rx at 0x100828000, rw at 0x100845000) --23708-- reading syms from primary file (102 201) --23708-- /usr/lib/system/libsystem_network.dylib (rx at 0x10084e000, rw at 0x1008b5000) --23708-- reading syms from primary file (686 2055) --23708-- /usr/lib/system/libsystem_networkextension.dylib (rx at 0x1008ec000, rw at 0x1008f5000) --23708-- reading syms from primary file (85 236) --23708-- /usr/lib/system/libsystem_notify.dylib (rx at 0x100900000, rw at 0x10090a000) --23708-- reading syms from primary file (136 53) --23708-- /usr/lib/system/libsystem_platform.dylib (rx at 0x100912000, rw at 0x10091b000) --23708-- reading syms from primary file (142 158) --23708-- /usr/lib/system/libsystem_pthread.dylib (rx at 0x100923000, rw at 0x10092d000) --23708-- reading syms from primary file (163 70) --23708-- /usr/lib/system/libsystem_sandbox.dylib (rx at 0x10093a000, rw at 0x10093e000) --23708-- reading syms from primary file (80 7) --23708-- /usr/lib/system/libsystem_secinit.dylib (rx at 0x100944000, rw at 0x100946000) --23708-- reading syms from primary file (3 6) --23708-- /usr/lib/system/libsystem_trace.dylib (rx at 0x10094b000, rw at 0x10095d000) --23708-- reading syms from primary file (94 351) --23708-- /usr/lib/system/libunwind.dylib (rx at 0x10096f000, rw at 0x100975000) --23708-- reading syms from primary file (102 52) --23708-- /usr/lib/system/libxpc.dylib (rx at 0x10097c000, rw at 0x1009a6000) --23708-- reading syms from primary file (503 833) --23708-- /usr/lib/libobjc.A.dylib (rx at 0x1009c4000, rw at 0x100d27000) --23708-- reading syms from primary file (347 935) --23708-- /usr/lib/libauto.dylib (rx at 0x100e03000, rw at 0x100e4a000) --23708-- reading syms from primary file (68 658) --23708-- /usr/lib/libc++abi.dylib (rx at 0x100e5f000, rw at 0x100e89000) --23708-- reading syms from primary file (337 181) --23708-- /usr/lib/libc++.1.dylib (rx at 0x100e97000, rw at 0x100eeb000) --23708-- reading syms from primary file (1960 1590) --23708-- /usr/lib/libDiagnosticMessagesClient.dylib (rx at 0x100f47000, rw at 0x100f49000) --23708-- reading syms from primary file (21 14) --23708-- REDIR: 0x100912ba0 (libsystem_platform.dylib:_platform_memchr$VARIANT$Haswell) redirected to 0x100029b57 (_platform_memchr$VARIANT$Haswell) --23708-- REDIR: 0x100912c80 (libsystem_platform.dylib:_platform_memcmp) redirected to 0x10002a093 (_platform_memcmp) --23708-- REDIR: 0x100913220 (libsystem_platform.dylib:_platform_strncmp) redirected to 0x100029a09 (_platform_strncmp) --23708-- REDIR: 0x1008290a2 (libsystem_malloc.dylib:malloc) redirected to 0x100027e0a (malloc) --23708-- REDIR: 0x100680140 (libsystem_c.dylib:strlen) redirected to 0x100029684 (strlen) --23708-- REDIR: 0x100913800 (libsystem_platform.dylib:_platform_strcmp) redirected to 0x100029aa9 (_platform_strcmp) --23708-- REDIR: 0x10082be98 (libsystem_malloc.dylib:free) redirected to 0x10002824a (free) --23708-- REDIR: 0x10082e431 (libsystem_malloc.dylib:calloc) redirected to 0x1000284c2 (calloc) --23708-- REDIR: 0x10082d939 (libsystem_malloc.dylib:malloc_default_zone) redirected to 0x100029274 (malloc_default_zone) --23708-- REDIR: 0x10082a55a (libsystem_malloc.dylib:malloc_zone_malloc) redirected to 0x1000280be (malloc_zone_malloc) --23708-- REDIR: 0x10082d958 (libsystem_malloc.dylib:malloc_zone_calloc) redirected to 0x1000286c4 (malloc_zone_calloc) --23708-- REDIR: 0x10082da12 (libsystem_malloc.dylib:malloc_zone_from_ptr) redirected to 0x1000292b5 (malloc_zone_from_ptr) --23708-- REDIR: 0x100913400 (libsystem_platform.dylib:_platform_strchr$VARIANT$Haswell) redirected to 0x10002954a (_platform_strchr$VARIANT$Haswell) --23708-- REDIR: 0x10082e634 (libsystem_malloc.dylib:realloc) redirected to 0x100028866 (realloc) --23708-- REDIR: 0x1008309e0 (libsystem_malloc.dylib:malloc_zone_memalign) redirected to 0x100028e0c (malloc_zone_memalign) --23708-- /Library/OpenSC/lib/opensc-pkcs11.so (rx at 0x10154f000, rw at 0x10157a000) --23708-- reading syms from primary file (68 350) --23708-- /System/Library/Frameworks/PCSC.framework/Versions/A/PCSC (rx at 0x101586000, rw at 0x101591000) --23708-- reading syms from primary file (103 109) --23708-- /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (rx at 0x101599000, rw at 0x101a10000) --23708-- reading syms from primary file (2653 7425) --23708-- /usr/lib/libicucore.A.dylib (rx at 0x101c8e000, rw at 0x101e9c000) --23708-- reading syms from primary file (6525 1) --23708-- /usr/lib/libz.1.dylib (rx at 0x101f62000, rw at 0x101f74000) --23708-- reading syms from primary file (65 1) --23708-- REDIR: 0x1006db01a (libsystem_c.dylib:strrchr) redirected to 0x1000294d4 (strrchr) --23708-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option --23708-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times) --23708-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times) valgrind: m_syswrap/syswrap-amd64-darwin.c:507 (void wqthread_hijack(Addr, Addr, Addr, Addr, Int, Addr)): Assertion 'tst->os_state.pthread - magic_delta == self' failed. host stacktrace: ==23708== at 0x23803FC97: ??? ==23708== by 0x238040094: ??? ==23708== by 0x238040077: ??? ==23708== by 0x2380DE3E1: ??? sched status: running_tid=0 Thread 1: status = VgTs_WaitSys (lwpid 2567) ==23708== at 0x1007C8FAE: semaphore_wait_trap (in /usr/lib/system/libsystem_kernel.dylib) ==23708== by 0x1005D7CB1: _dispatch_semaphore_wait_slow (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x100986EA4: xpc_connection_send_message_with_reply_sync (in /usr/lib/system/libxpc.dylib) ==23708== by 0x1015877FD: transact (in /System/Library/Frameworks/PCSC.framework/Versions/A/PCSC) ==23708== by 0x1000806AC: pcsc_detect_readers (in /Library/OpenSC/lib/libopensc.4.dylib) ==23708== by 0x10003596D: sc_ctx_detect_readers (in /Library/OpenSC/lib/libopensc.4.dylib) ==23708== by 0x100035D80: sc_context_create (in /Library/OpenSC/lib/libopensc.4.dylib) ==23708== by 0x10154FBC4: C_Initialize (in /Library/OpenSC/lib/opensc-pkcs11.so) ==23708== by 0x100001CAF: main (in /usr/local/bin/pkcs11-tool) Thread 2: status = VgTs_WaitSys (lwpid 3587) ==23708== at 0x1007CF5E2: __workq_kernreturn (in /usr/lib/system/libsystem_kernel.dylib) ==23708== by 0x2380DE3E1: ??? ==23708== by 0x2382001AF: ??? ==23708== by 0x70000311EDAF: ??? ==23708== by 0x70000000BB1F: ??? Thread 3: status = VgTs_WaitSys (lwpid 6147) ==23708== at 0x1007C8F72: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib) ==23708== by 0x1007C83B2: mach_msg (in /usr/lib/system/libsystem_kernel.dylib) ==23708== by 0x1007BE03B: _kernelrpc_mach_port_request_notification (in /usr/lib/system/libsystem_kernel.dylib) ==23708== by 0x1005D4FCC: _dispatch_kevent_mach_notify_resume (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D51BC: _dispatch_kevent_unregister (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D3FD1: _dispatch_mach_msg_send (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D3A20: _dispatch_mach_msg_send (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D4B23: _dispatch_mach_send_drain (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D3458: _dispatch_mach_invoke (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D11FF: _dispatch_queue_drain (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D21DE: _dispatch_mgr_queue_drain (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D20B9: _dispatch_mgr_invoke (in /usr/lib/system/libdispatch.dylib) ==23708== by 0x1005D1DCC: _dispatch_mgr_thread (in /usr/lib/system/libdispatch.dylib) Note: see also the FAQ in the source distribution. It contains workarounds to several common problems. In particular, if Valgrind aborted or crashed after identifying problems in your program, there's a good chance that fixing those problems will prevent Valgrind aborting or crashing, especially if it happened in m_mallocfree.c. If that doesn't help, please report this bug to: www.valgrind.org In the bug report, send all the above text, the valgrind version, and what OS and version you are using. Thanks. $
Hello Uri, Thanks for the report. This is a known bug. Closing and adding a reference to the main bug tracking this #354883 *** This bug has been marked as a duplicate of bug 354883 ***