Author: sewardj
Date: Sun Oct 12 14:47:30 2014
New Revision: 14622
Log:
Fix the thread-name facility and associated test on Darwin.
Patch from Rhys Kidd (rhy...@gm...). Fixes #339442.
Modified:
trunk/coregrind/m_syswrap/syswrap-darwin.c
trunk/memcheck/tests/threadname.c
trunk/memcheck/tests/threadname.stderr.exp
trunk/memcheck/tests/threadname.vgtest
Modified: trunk/coregrind/m_syswrap/syswrap-darwin.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-darwin.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-darwin.c Sun Oct 12 14:47:30 2014
@@ -3915,9 +3915,41 @@
{
#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
}
Modified: trunk/memcheck/tests/threadname.c
==============================================================================
--- trunk/memcheck/tests/threadname.c (original)
+++ trunk/memcheck/tests/threadname.c Sun Oct 12 14:47:30 2014
@@ -21,7 +21,11 @@
{
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 @@
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);
Modified: trunk/memcheck/tests/threadname.stderr.exp
==============================================================================
--- trunk/memcheck/tests/threadname.stderr.exp (original)
+++ trunk/memcheck/tests/threadname.stderr.exp Sun Oct 12 14:47:30 2014
@@ -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)
Modified: trunk/memcheck/tests/threadname.vgtest
==============================================================================
--- trunk/memcheck/tests/threadname.vgtest (original)
+++ trunk/memcheck/tests/threadname.vgtest Sun Oct 12 14:47:30 2014
@@ -1,3 +1,3 @@
prog: threadname
-prereq: test -e ./threadname && ../../tests/os_test linux
+prereq: test -e ./threadname
vgopts: -q
|