From: Julian Seward Date: Sun, 12 Oct 2014 13:47:30 +0000 (+0000) Subject: Fix the thread-name facility and associated test on Darwin. X-Git-Tag: svn/VALGRIND_3_11_0~924 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77791188fc259eb9869e255524d0a61a73e8068e;p=thirdparty%2Fvalgrind.git Fix the thread-name facility and associated test on Darwin. Patch from Rhys Kidd (rhyskidd@gmail.com). Fixes #339442. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14622 --- diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index 4bb88b3722..e04e39acf0 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -3915,9 +3915,41 @@ POST(proc_info) { #if VG_WORDSIZE == 4 vg_assert(SUCCESS); + + // Intercept internal call to proc_setcontrol() where flavor = 2, arg = 0 + if (ARG1 == 5 && ARG3 == 2 && LOHI64(ARG4,ARG5) == 0 ) + { + const HChar* new_name = (const HChar*) ARG6; + if (new_name) { // Paranoia + ThreadState* tst = VG_(get_ThreadState)(tid); + SizeT new_len = VG_(strlen)(new_name); + + /* Don't bother reusing the memory. This is a rare event. */ + tst->thread_name = + VG_(realloc)("syscall(proc_info)", tst->thread_name, new_len + 1); + VG_(strcpy)(tst->thread_name, new_name); + } + } + POST_MEM_WRITE(ARG6, ARG7); #else vg_assert(SUCCESS); + + // Intercept internal call to proc_setcontrol() where flavor = 2, arg = 0 + if (ARG1 == 5 && ARG3 == 2 && ARG4 == 0 ) + { + const HChar* new_name = (const HChar*) ARG5; + if (new_name) { // Paranoia + ThreadState* tst = VG_(get_ThreadState)(tid); + SizeT new_len = VG_(strlen)(new_name); + + /* Don't bother reusing the memory. This is a rare event. */ + tst->thread_name = + VG_(realloc)("syscall(proc_info)", tst->thread_name, new_len + 1); + VG_(strcpy)(tst->thread_name, new_name); + } + } + POST_MEM_WRITE(ARG5, ARG6); #endif } diff --git a/memcheck/tests/threadname.c b/memcheck/tests/threadname.c index c08f8d825e..91e7f833eb 100644 --- a/memcheck/tests/threadname.c +++ b/memcheck/tests/threadname.c @@ -21,7 +21,11 @@ void* child_fn_2 ( void* arg ) { const char* threadname = "012345678901234"; +# if !defined(VGO_darwin) pthread_setname_np(pthread_self(), threadname); +# else + pthread_setname_np(threadname); +# endif bad_things(4); @@ -33,7 +37,11 @@ void* child_fn_1 ( void* arg ) const char* threadname = "try1"; int r; +# if !defined(VGO_darwin) pthread_setname_np(pthread_self(), threadname); +# else + pthread_setname_np(threadname); +# endif bad_things(3); diff --git a/memcheck/tests/threadname.stderr.exp b/memcheck/tests/threadname.stderr.exp index 8ee6752979..1cf2313756 100644 --- a/memcheck/tests/threadname.stderr.exp +++ b/memcheck/tests/threadname.stderr.exp @@ -1,50 +1,50 @@ Invalid write of size 1 at 0x........: bad_things (threadname.c:16) - by 0x........: main (threadname.c:68) + by 0x........: main (threadname.c:76) Address 0x........ is 0 bytes after a block of size 1 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: bad_things (threadname.c:15) - by 0x........: main (threadname.c:68) + by 0x........: main (threadname.c:76) Thread 2: Invalid write of size 1 at 0x........: bad_things (threadname.c:16) - by 0x........: child_fn_0 (threadname.c:53) + by 0x........: child_fn_0 (threadname.c:61) ... Address 0x........ is 0 bytes after a block of size 2 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: bad_things (threadname.c:15) - by 0x........: child_fn_0 (threadname.c:53) + by 0x........: child_fn_0 (threadname.c:61) ... Thread 3 try1: Invalid write of size 1 at 0x........: bad_things (threadname.c:16) - by 0x........: child_fn_1 (threadname.c:38) + by 0x........: child_fn_1 (threadname.c:46) ... Address 0x........ is 0 bytes after a block of size 3 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: bad_things (threadname.c:15) - by 0x........: child_fn_1 (threadname.c:38) + by 0x........: child_fn_1 (threadname.c:46) ... Thread 4 012345678901234: Invalid write of size 1 at 0x........: bad_things (threadname.c:16) - by 0x........: child_fn_2 (threadname.c:26) + by 0x........: child_fn_2 (threadname.c:30) ... Address 0x........ is 0 bytes after a block of size 4 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: bad_things (threadname.c:15) - by 0x........: child_fn_2 (threadname.c:26) + by 0x........: child_fn_2 (threadname.c:30) ... Thread 1: Invalid write of size 1 at 0x........: bad_things (threadname.c:16) - by 0x........: main (threadname.c:76) + by 0x........: main (threadname.c:84) Address 0x........ is 0 bytes after a block of size 5 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: bad_things (threadname.c:15) - by 0x........: main (threadname.c:76) + by 0x........: main (threadname.c:84) diff --git a/memcheck/tests/threadname.vgtest b/memcheck/tests/threadname.vgtest index 22d04f8b3c..2692bd0784 100644 --- a/memcheck/tests/threadname.vgtest +++ b/memcheck/tests/threadname.vgtest @@ -1,3 +1,3 @@ prog: threadname -prereq: test -e ./threadname && ../../tests/os_test linux +prereq: test -e ./threadname vgopts: -q