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
This commit is contained in:
Julian Seward 2014-10-12 13:47:30 +00:00
parent bf28744a5f
commit 77791188fc
4 changed files with 51 additions and 11 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -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)

View File

@ -1,3 +1,3 @@
prog: threadname
prereq: test -e ./threadname && ../../tests/os_test linux
prereq: test -e ./threadname
vgopts: -q