From: Julian Seward Date: Fri, 30 Nov 2007 08:30:29 +0000 (+0000) Subject: Remove pthread_object_size.h and associated hardwired constants. X-Git-Tag: svn/VALGRIND_3_3_0~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec903846a6ca7f2d748318e2d0d5005d5ac2f1aa;p=thirdparty%2Fvalgrind.git Remove pthread_object_size.h and associated hardwired constants. (Bart Van Assche) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7252 --- diff --git a/exp-drd/TODO.txt b/exp-drd/TODO.txt index 02a135c3fc..cbe891f33d 100644 --- a/exp-drd/TODO.txt +++ b/exp-drd/TODO.txt @@ -19,7 +19,6 @@ Data-race detection algorithm AMD64). - Change s_threadinfo[] from an array into an OSet or VgHashTable, in order to make ThreadId <> DrdThreadId <> pthread_t conversions faster. -- Write a configure test that figures out sizeof(pthread_mutex_t) etc. - [AMD64] Find out why removing 'write(1, "", 0)' in drd_preloaded.c triggers a crash on AMD64. Is this a drd or a VEX bug ? - Reintroduce the const keyword in the function declarations of the OSet diff --git a/exp-drd/drd_clientreq.c b/exp-drd/drd_clientreq.c index 194d31f241..d77c741dee 100644 --- a/exp-drd/drd_clientreq.c +++ b/exp-drd/drd_clientreq.c @@ -4,7 +4,7 @@ #include "drd_suppression.h" // drd_start_suppression() #include "drd_thread.h" #include "drd_track.h" -#include "pthread_object_size.h" +#include "priv_drd_clientreq.h" #include "pub_core_tooliface.h" // VG_TRACK() #include "pub_tool_basics.h" // Bool #include "pub_tool_libcassert.h" @@ -20,24 +20,26 @@ static void drd_spin_init_or_unlock(const Addr spinlock, const SizeT size) struct mutex_info* mutex_p = mutex_get(spinlock); if (mutex_p) { - mutex_unlock(spinlock); + mutex_unlock(spinlock, mutex_type_spinlock); } else { - mutex_init(spinlock, size); + mutex_init(spinlock, size, mutex_type_spinlock); } } -static void drd_pre_cond_wait(const Addr cond, const Addr mutex) +static void drd_pre_cond_wait(const Addr cond, const SizeT cond_size, + const Addr mutex) { - mutex_unlock(mutex); - cond_pre_wait(cond, mutex); + mutex_unlock(mutex, mutex_type_mutex); + cond_pre_wait(cond, cond_size, mutex); } -static void drd_post_cond_wait(const Addr cond, const Addr mutex) +static void drd_post_cond_wait(const Addr cond, const Addr mutex, + const SizeT size) { cond_post_wait(cond); - mutex_lock(mutex, PTHREAD_MUTEX_SIZE); + mutex_lock(mutex, size, mutex_type_mutex); } static void drd_pre_cond_signal(const Addr cond) @@ -105,7 +107,7 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret) break; case VG_USERREQ__PRE_MUTEX_INIT: - drd_pre_mutex_init(arg[1], arg[2]); + drd_pre_mutex_init(arg[1], arg[2], arg[3]); break; case VG_USERREQ__POST_MUTEX_DESTROY: @@ -113,15 +115,15 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret) break; case VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK: - drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2]); + drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]); break; case VG_USERREQ__POST_PTHREAD_MUTEX_LOCK: - drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2]); + drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]); break; case VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK: - drd_pre_mutex_unlock(thread_get_running_tid(), arg[1]); + drd_pre_mutex_unlock(thread_get_running_tid(), arg[1], arg[3]); break; case VG_USERREQ__SPIN_INIT_OR_UNLOCK: @@ -133,15 +135,16 @@ static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret) break; case VG_USERREQ__PRE_PTHREAD_COND_DESTROY: - drd_pre_cond_destroy(arg[1], arg[2]); + drd_pre_cond_destroy(arg[1]); break; case VG_USERREQ__PRE_PTHREAD_COND_WAIT: - drd_pre_cond_wait(arg[1], arg[2]); + drd_pre_cond_wait(arg[1]/*cond*/, arg[2]/*cond_size*/, arg[3]/*mutex*/); break; case VG_USERREQ__POST_PTHREAD_COND_WAIT: - drd_post_cond_wait(arg[1], arg[2]); + drd_post_cond_wait(arg[1]/*cond*/, arg[3]/*mutex*/, + arg[4]/*mutex_size*/); break; case VG_USERREQ__PRE_PTHREAD_COND_SIGNAL: diff --git a/exp-drd/drd_clientreq.h b/exp-drd/drd_clientreq.h index 57baee0918..e07f008488 100644 --- a/exp-drd/drd_clientreq.h +++ b/exp-drd/drd_clientreq.h @@ -54,16 +54,16 @@ enum { /* To notify the core of a pthread_mutex_init call */ VG_USERREQ__PRE_MUTEX_INIT, - /* args: Addr, SizeT */ + /* args: Addr, MutexT */ /* To notify the core of a pthread_mutex_destroy call */ VG_USERREQ__POST_MUTEX_DESTROY, - /* args: Addr, SizeT */ + /* args: Addr, SizeT, MutexT */ /* To notify the core of pthread_mutex_lock calls */ VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, - /* args: Addr, SizeT */ + /* args: Addr, SizeT, MutexT */ /* To notify the core of pthread_mutex_lock calls */ VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, - /* args: Addr, SizeT */ + /* args: Addr, SizeT, MutexT */ /* To notify the core of pthread_mutex_unlock calls */ VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK, /* args: Addr */ @@ -73,14 +73,14 @@ enum { /* To notify the core of a pthread_cond_init call */ VG_USERREQ__POST_PTHREAD_COND_INIT, - /* args: Addr, SizeT */ + /* args: Addr */ /* To notify the core of a pthread_cond_destroy call */ VG_USERREQ__PRE_PTHREAD_COND_DESTROY, - /* args: Addr, SizeT */ + /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */ VG_USERREQ__PRE_PTHREAD_COND_WAIT, - /* args: Addr cond, Addr mutex */ + /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */ VG_USERREQ__POST_PTHREAD_COND_WAIT, - /* args: Addr cond, Addr mutex */ + /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */ VG_USERREQ__PRE_PTHREAD_COND_SIGNAL, /* args: Addr cond */ VG_USERREQ__PRE_PTHREAD_COND_BROADCAST, @@ -88,7 +88,11 @@ enum { }; -void drd_clientreq_init(void); +typedef enum +{ + mutex_type_mutex = 1, + mutex_type_spinlock = 2, +} MutexT; #endif // __DRD_CLIENTREQ_H diff --git a/exp-drd/drd_cond.c b/exp-drd/drd_cond.c index 0323fa0c4d..83db465b63 100644 --- a/exp-drd/drd_cond.c +++ b/exp-drd/drd_cond.c @@ -27,7 +27,6 @@ #include "drd_error.h" #include "drd_mutex.h" #include "drd_suppression.h" -#include "pthread_object_size.h" #include "pub_tool_errormgr.h" // VG_(maybe_record_error)() #include "pub_tool_libcassert.h" // tl_assert() #include "pub_tool_libcprint.h" // VG_(printf)() @@ -46,29 +45,37 @@ void cond_set_trace(const Bool trace_cond) } static -void cond_initialize(struct cond_info* const p, const Addr cond) +void cond_initialize(struct cond_info* const p, const Addr cond, + const SizeT size) { tl_assert(cond != 0); p->cond = cond; + p->size = size; p->waiter_count = 0; p->mutex = 0; } -static struct cond_info* cond_get_or_allocate(const Addr cond) +static struct cond_info* +cond_get_or_allocate(const Addr cond, const SizeT size) { int i; for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++) + { if (s_cond[i].cond == cond) + { + tl_assert(s_cond[i].size == size); return &s_cond[i]; + } + } for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++) { if (s_cond[i].cond == 0) { - cond_initialize(&s_cond[i], cond); + cond_initialize(&s_cond[i], cond, size); /* TO DO: replace the constant below by a symbolic constant referring */ /* to sizeof(pthread_cond_t). */ - drd_start_suppression(cond, cond + PTHREAD_COND_SIZE, "cond"); + drd_start_suppression(cond, cond + size, "cond"); return &s_cond[i]; } } @@ -76,7 +83,7 @@ static struct cond_info* cond_get_or_allocate(const Addr cond) return 0; } -void cond_init(const Addr cond) +void cond_init(const Addr cond, const SizeT size) { if (s_trace_cond) { @@ -85,7 +92,8 @@ void cond_init(const Addr cond) VG_(clo_backtrace_size)); } tl_assert(cond_get(cond) == 0); - cond_get_or_allocate(cond); + tl_assert(size > 0); + cond_get_or_allocate(cond, size); } void cond_destroy(struct cond_info* const p) @@ -100,7 +108,7 @@ void cond_destroy(struct cond_info* const p) // TO DO: print a proper error message if waiter_count != 0. tl_assert(p->waiter_count == 0); - drd_finish_suppression(p->cond, p->cond + PTHREAD_COND_SIZE); + drd_finish_suppression(p->cond, p->cond + p->size); p->cond = 0; p->waiter_count = 0; @@ -116,11 +124,11 @@ struct cond_info* cond_get(const Addr cond) return 0; } -int cond_pre_wait(const Addr cond, const Addr mutex) +int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex) { struct cond_info* p; - p = cond_get_or_allocate(cond); + p = cond_get_or_allocate(cond, cond_size); if (p->waiter_count == 0) { p->mutex = mutex; @@ -194,7 +202,7 @@ void cond_stop_using_mem(const Addr a1, const Addr a2) { if (a1 <= s_cond[i].cond && s_cond[i].cond < a2) { - tl_assert(s_cond[i].cond + PTHREAD_COND_SIZE <= a2); + tl_assert(s_cond[i].cond + s_cond[i].size <= a2); cond_destroy(&s_cond[i]); } } diff --git a/exp-drd/drd_cond.h b/exp-drd/drd_cond.h index 2a3b94570b..9912c83c31 100644 --- a/exp-drd/drd_cond.h +++ b/exp-drd/drd_cond.h @@ -38,17 +38,18 @@ struct cond_info { - Addr cond; // Pointer to client condition variable. - int waiter_count; - Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null + Addr cond; // Pointer to client condition variable. + SizeT size; // sizeof(pthread_cond_t) + int waiter_count; + Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null // if no client threads are currently waiting on this cond.var. }; void cond_set_trace(const Bool trace_cond); -void cond_init(const Addr cond); +void cond_init(const Addr cond, const SizeT size); void cond_destroy(struct cond_info* const p); struct cond_info* cond_get(Addr const mutex); -int cond_pre_wait(const Addr cond, const Addr mutex); +int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex); int cond_post_wait(const Addr cond); void cond_pre_signal(Addr const cond); void cond_pre_broadcast(Addr const cond); diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c index 7ddb900c8c..900b08369e 100644 --- a/exp-drd/drd_main.c +++ b/exp-drd/drd_main.c @@ -34,7 +34,7 @@ #include "drd_thread.h" #include "drd_track.h" #include "drd_vc.h" -#include "pthread_object_size.h" +#include "priv_drd_clientreq.h" #include "pub_core_mallocfree.h" #include "pub_core_options.h" #include "pub_tool_vki.h" @@ -469,12 +469,12 @@ static void drd_thread_finished(ThreadId tid) thread_finished(drd_tid); } -void drd_pre_mutex_init(Addr mutex, SizeT size) +void drd_pre_mutex_init(Addr mutex, SizeT size, MutexT mutex_type) { - mutex_init(mutex, size); + mutex_init(mutex, size, mutex_type); } -void drd_post_mutex_destroy(Addr mutex, SizeT size) +void drd_post_mutex_destroy(Addr mutex, MutexT mutex_type) { struct mutex_info* p; @@ -490,29 +490,32 @@ void drd_post_mutex_destroy(Addr mutex, SizeT size) void drd_pre_mutex_lock(const DrdThreadId drd_tid, const Addr mutex, - const SizeT size) + const SizeT size, + const MutexT mutex_type) { if (mutex_get(mutex) == 0) { - mutex_init(mutex, size); + mutex_init(mutex, size, mutex_type); } } void drd_post_mutex_lock(const DrdThreadId drd_tid, const Addr mutex, - const SizeT size) + const SizeT size, + const MutexT mutex_type) { - mutex_lock(mutex, size); + mutex_lock(mutex, size, mutex_type); } -void drd_pre_mutex_unlock(const DrdThreadId drd_tid, Addr mutex) +void drd_pre_mutex_unlock(const DrdThreadId drd_tid, + const Addr mutex, + const MutexT mutex_type) { - mutex_unlock(mutex); + mutex_unlock(mutex, mutex_type); } void drd_post_cond_init(Addr cond, SizeT s) { - tl_assert(s == PTHREAD_COND_SIZE); if (cond_get(cond)) { CondErrInfo cei = { .cond = cond }; @@ -522,14 +525,13 @@ void drd_post_cond_init(Addr cond, SizeT s) "initialized twice", &cei); } - cond_init(cond); + cond_init(cond, s); } -void drd_pre_cond_destroy(Addr cond, SizeT s) +void drd_pre_cond_destroy(Addr cond) { struct cond_info* cond_p; - tl_assert(s == PTHREAD_COND_SIZE); cond_p = cond_get(cond); if (cond_p) { diff --git a/exp-drd/drd_mutex.c b/exp-drd/drd_mutex.c index 25b4ef13b5..304f36531a 100644 --- a/exp-drd/drd_mutex.c +++ b/exp-drd/drd_mutex.c @@ -26,7 +26,7 @@ #include "drd_error.h" #include "drd_mutex.h" #include "drd_suppression.h" -#include "pthread_object_size.h" +#include "priv_drd_clientreq.h" #include "pub_tool_errormgr.h" // VG_(maybe_record_error)() #include "pub_tool_libcassert.h" // tl_assert() #include "pub_tool_libcprint.h" // VG_(printf)() @@ -40,6 +40,7 @@ struct mutex_info { Addr mutex; // Pointer to client mutex. SizeT size; // Size in bytes of client-side object. + MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t. int recursion_count; // 0 if free, >= 1 if locked. DrdThreadId owner; // owner if locked, last owner if free. VectorClock vc; // vector clock associated with last unlock. @@ -64,30 +65,47 @@ void mutex_set_trace(const Bool trace_mutex) static void mutex_initialize(struct mutex_info* const p, const Addr mutex, - const SizeT size) + const SizeT size, + const MutexT mutex_type) { tl_assert(mutex != 0); tl_assert(size > 0); + tl_assert(mutex_type == mutex_type_mutex + || mutex_type == mutex_type_spinlock); p->mutex = mutex; p->size = size; + p->mutex_type = mutex_type; p->recursion_count = 0; p->owner = DRD_INVALID_THREADID; vc_init(&p->vc, 0, 0); } static -struct mutex_info* mutex_get_or_allocate(const Addr mutex, const SizeT size) +struct mutex_info* +mutex_get_or_allocate(const Addr mutex, + const SizeT size, + const MutexT mutex_type) { int i; + + tl_assert(mutex_type == mutex_type_mutex + || mutex_type == mutex_type_spinlock); + for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++) + { if (s_mutex[i].mutex == mutex) + { + tl_assert(s_mutex[i].mutex_type == mutex_type); + tl_assert(s_mutex[i].size == size); return &s_mutex[i]; + } + } for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++) { if (s_mutex[i].mutex == 0) { - mutex_initialize(&s_mutex[i], mutex, size); + mutex_initialize(&s_mutex[i], mutex, size, mutex_type); drd_start_suppression(mutex, mutex + size, mutex_get_typename(&s_mutex[i])); return &s_mutex[i]; @@ -97,12 +115,15 @@ struct mutex_info* mutex_get_or_allocate(const Addr mutex, const SizeT size) return 0; } -struct mutex_info* mutex_init(const Addr mutex, const SizeT size) +struct mutex_info* +mutex_init(const Addr mutex, const SizeT size, const MutexT mutex_type) { struct mutex_info* mutex_p; tl_assert(mutex_get(mutex) == 0); - mutex_p = mutex_get_or_allocate(mutex, size); + tl_assert(mutex_type == mutex_type_mutex + || mutex_type == mutex_type_spinlock); + mutex_p = mutex_get_or_allocate(mutex, size, mutex_type); if (s_trace_mutex) { @@ -151,10 +172,10 @@ struct mutex_info* mutex_get(const Addr mutex) * Note: this function must be called after pthread_mutex_lock() has been * called, or a race condition is triggered ! */ -int mutex_lock(const Addr mutex, const SizeT size) +int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type) { const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)()); - struct mutex_info* const p = mutex_get_or_allocate(mutex, size); + struct mutex_info* const p = mutex_get_or_allocate(mutex, size, mutex_type); const DrdThreadId last_owner = p->owner; if (s_trace_mutex) @@ -170,7 +191,12 @@ int mutex_lock(const Addr mutex, const SizeT size) p ? p->owner : VG_INVALID_THREADID); } - if (p->recursion_count >= 1 && p->size == PTHREAD_SPINLOCK_SIZE) + tl_assert(mutex_type == mutex_type_mutex + || mutex_type == mutex_type_spinlock); + tl_assert(p->mutex_type == mutex_type); + tl_assert(p->size == size); + + if (p->recursion_count >= 1 && mutex_type == mutex_type_spinlock) { // TO DO: tell the user in a more friendly way that it is not allowed to // lock spinlocks recursively. @@ -211,7 +237,7 @@ int mutex_lock(const Addr mutex, const SizeT size) * @param tid ThreadId of the thread calling pthread_mutex_unlock(). * @param vc Pointer to the current vector clock of thread tid. */ -int mutex_unlock(const Addr mutex) +int mutex_unlock(const Addr mutex, const MutexT mutex_type) { const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)()); const ThreadId vg_tid = DrdThreadIdToVgThreadId(drd_tid); @@ -230,7 +256,11 @@ int mutex_unlock(const Addr mutex) } tl_assert(p); + tl_assert(p->mutex_type == mutex_type); tl_assert(p->owner != DRD_INVALID_THREADID); + tl_assert(mutex_type == mutex_type_mutex + || mutex_type == mutex_type_spinlock); + if (p->owner != drd_tid) { MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner }; @@ -257,11 +287,12 @@ int mutex_unlock(const Addr mutex) const char* mutex_get_typename(struct mutex_info* const p) { tl_assert(p); - switch (p->size) + + switch (p->mutex_type) { - case PTHREAD_MUTEX_SIZE: + case mutex_type_mutex: return "mutex"; - case PTHREAD_SPINLOCK_SIZE: + case mutex_type_spinlock: return "spinlock"; default: tl_assert(0); diff --git a/exp-drd/drd_mutex.h b/exp-drd/drd_mutex.h index 03d2994b03..180c7e1744 100644 --- a/exp-drd/drd_mutex.h +++ b/exp-drd/drd_mutex.h @@ -30,20 +30,22 @@ #define __MUTEX_H -#include "pub_tool_basics.h" // Addr, SizeT -#include "drd_vc.h" +#include "drd_clientreq.h" // MutexT #include "drd_thread.h" // DrdThreadId +#include "drd_vc.h" +#include "pub_tool_basics.h" // Addr, SizeT struct mutex_info; void mutex_set_trace(const Bool trace_mutex); -struct mutex_info* mutex_init(const Addr mutex, const SizeT size); +struct mutex_info* mutex_init(const Addr mutex, const SizeT size, + const MutexT mutex_type); void mutex_destroy(struct mutex_info* const p); struct mutex_info* mutex_get(const Addr mutex); -int mutex_lock(const Addr mutex, const SizeT size); -int mutex_unlock(const Addr mutex); +int mutex_lock(const Addr mutex, const SizeT size, const MutexT mutex_type); +int mutex_unlock(const Addr mutex, const MutexT mutex_type); const char* mutex_get_typename(struct mutex_info* const p); Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid); const VectorClock* mutex_get_last_vc(const Addr mutex); diff --git a/exp-drd/drd_preloaded.c b/exp-drd/drd_preloaded.c index 8c9028845c..0a0b30035b 100644 --- a/exp-drd/drd_preloaded.c +++ b/exp-drd/drd_preloaded.c @@ -56,7 +56,6 @@ #include "pub_core_debuginfo.h" // Needed for pub_core_redir.h #include "pub_core_redir.h" // For VG_NOTIFY_ON_LOAD #include "pub_tool_threadstate.h"// VG_N_THREADS -#include "pthread_object_size.h" // PTHREAD_MUTEX_SIZE etc. // Defines. @@ -165,10 +164,6 @@ static void vg_set_main_thread_state(void) VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK, 0, 0, 0, 0, 0); - // Sanity checks. - assert(sizeof(pthread_mutex_t) == PTHREAD_MUTEX_SIZE); - assert(sizeof(pthread_spinlock_t) == PTHREAD_SPINLOCK_SIZE); - // Make sure that DRD knows about the main thread's POSIX thread ID. VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID, pthread_self(), 0, 0, 0, 0); @@ -281,7 +276,7 @@ PTH_FUNC(int, pthreadZumutexZuinit, OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, sizeof(*mutex), mutex_type_mutex, 0, 0); CALL_FN_W_WW(ret, fn, mutex, attr); return ret; } @@ -296,7 +291,7 @@ PTH_FUNC(int, pthreadZumutexZudestroy, VALGRIND_GET_ORIG_FN(fn); CALL_FN_W_W(ret, fn, mutex); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, mutex_type_mutex, 0, 0, 0); return ret; } @@ -309,7 +304,7 @@ PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, sizeof(*mutex), mutex_type_mutex, 0, 0); #if 1 // The only purpose of the system call below is to make drd work on AMD64 // systems. Without this system call, clients crash (SIGSEGV) in @@ -319,7 +314,7 @@ PTH_FUNC(int, pthreadZumutexZulock, // pthread_mutex_lock CALL_FN_W_W(ret, fn, mutex); if (ret == 0) VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, sizeof(*mutex), mutex_type_mutex, 0, 0); return ret; } @@ -335,7 +330,7 @@ PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock if (ret == 0) { VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, sizeof(*mutex), mutex_type_mutex, 0, 0); } return ret; } @@ -350,7 +345,7 @@ PTH_FUNC(int, pthreadZumutexZuunlock, // pthread_mutex_unlock VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK, - mutex, sizeof(*mutex), 0, 0, 0); + mutex, sizeof(*mutex), mutex_type_mutex, 0, 0); CALL_FN_W_W(ret, fn, mutex); return ret; } @@ -379,7 +374,7 @@ PTH_FUNC(int, pthreadZucondZudestroyZAZa, // pthread_cond_destroy@* OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_DESTROY, - cond, sizeof(*cond), 0, 0, 0); + cond, 0, 0, 0, 0); CALL_FN_W_W(ret, fn, cond); return ret; } @@ -394,10 +389,10 @@ PTH_FUNC(int, pthreadZucondZuwaitZAZa, // pthread_cond_wait@* OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, - cond, mutex, 0, 0, 0); + cond, sizeof(*cond), mutex, sizeof(*mutex), 0); CALL_FN_W_WW(ret, fn, cond, mutex); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, - cond, mutex, 0, 0, 0); + cond, sizeof(*cond), mutex, sizeof(*mutex), 0); return ret; } @@ -412,10 +407,10 @@ PTH_FUNC(int, pthreadZucondZutimedwaitZAZa, // pthread_cond_timedwait@* OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT, - cond, mutex, 0, 0, 0); + cond, sizeof(*cond), mutex, sizeof(*mutex), 0); CALL_FN_W_WWW(ret, fn, cond, mutex, abstime); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT, - cond, mutex, 0, 0, 0); + cond, sizeof(*cond), mutex, sizeof(*mutex), 0); return ret; } @@ -458,7 +453,8 @@ PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, - spinlock, sizeof(*spinlock), 0, 0, 0); + spinlock, sizeof(*spinlock), + mutex_type_spinlock, 0, 0); CALL_FN_W_WW(ret, fn, spinlock, pshared); return ret; } @@ -473,7 +469,7 @@ PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy VALGRIND_GET_ORIG_FN(fn); CALL_FN_W_W(ret, fn, spinlock); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, - spinlock, sizeof(*spinlock), 0, 0, 0); + spinlock, mutex_type_spinlock, 0, 0, 0); return ret; } @@ -489,7 +485,8 @@ PTH_FUNC(int, pthreadZuspinZulock, // pthread_spin_lock if (ret == 0) { VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, - spinlock, sizeof(*spinlock), 0, 0, 0); + spinlock, sizeof(*spinlock), + mutex_type_spinlock, 0, 0); } return ret; } @@ -506,7 +503,8 @@ PTH_FUNC(int, pthreadZuspinZutrylock, // pthread_spin_trylock if (ret == 0) { VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK, - spinlock, sizeof(*spinlock), 0, 0, 0); + spinlock, sizeof(*spinlock), + mutex_type_spinlock, 0, 0); } return ret; } @@ -520,7 +518,8 @@ PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, - spinlock, sizeof(*spinlock), 0, 0, 0); + spinlock, sizeof(*spinlock), + mutex_type_spinlock, 0, 0); CALL_FN_W_W(ret, fn, spinlock); return ret; } diff --git a/exp-drd/drd_thread.c b/exp-drd/drd_thread.c index 72a92dc02b..38121a2575 100644 --- a/exp-drd/drd_thread.c +++ b/exp-drd/drd_thread.c @@ -27,7 +27,6 @@ #include "drd_segment.h" #include "drd_suppression.h" #include "drd_thread.h" -#include "pthread_object_size.h" #include "pub_core_options.h" // VG_(clo_backtrace_size) #include "pub_tool_basics.h" // Addr, SizeT #include "pub_tool_errormgr.h" // VG_(unique_error)() diff --git a/exp-drd/drd_track.h b/exp-drd/drd_track.h index 8d56222c54..4a8e564f69 100644 --- a/exp-drd/drd_track.h +++ b/exp-drd/drd_track.h @@ -1,8 +1,11 @@ void drd_post_thread_join(DrdThreadId joiner, DrdThreadId joinee); -void drd_pre_mutex_init(Addr mutex, SizeT size); -void drd_post_mutex_destroy(Addr mutex, SizeT size); -void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size); -void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size); -void drd_pre_mutex_unlock(DrdThreadId tid, Addr mutex); +void drd_pre_mutex_init(Addr mutex, SizeT size, const MutexT mutex_type); +void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type); +void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size, + const MutexT mutex_type); +void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size, + const MutexT mutex_type); +void drd_pre_mutex_unlock(const DrdThreadId tid, const Addr mutex, + const MutexT mutex_type); void drd_post_cond_init(Addr cond, SizeT s); -void drd_pre_cond_destroy(Addr cond, SizeT s); +void drd_pre_cond_destroy(Addr cond); diff --git a/exp-drd/priv_drd_clientreq.h b/exp-drd/priv_drd_clientreq.h new file mode 100644 index 0000000000..0e63b0ea9e --- /dev/null +++ b/exp-drd/priv_drd_clientreq.h @@ -0,0 +1,30 @@ +/* + This file is part of drd, a data race detector. + + Copyright (C) 2006-2007 Bart Van Assche + bart.vanassche@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __PRIV_DRD_CLIENTREQ_H +#define __PRIV_DRD_CLIENTREQ_H + +void drd_clientreq_init(void); + +#endif /* __PRIV_DRD_CLIENTREQ_H */ diff --git a/exp-drd/pthread_object_size.h b/exp-drd/pthread_object_size.h deleted file mode 100644 index 75b1baa17b..0000000000 --- a/exp-drd/pthread_object_size.h +++ /dev/null @@ -1,15 +0,0 @@ -// TO DO: replace the constants below by macro's #define'd during the configure -// phase. - -#if defined(VGP_x86_linux) -# define PTHREAD_MUTEX_SIZE 24 -# define PTHREAD_COND_SIZE 48 -#elif defined(VGP_amd64_linux) -# define PTHREAD_MUTEX_SIZE 40 -# define PTHREAD_COND_SIZE 48 -#else - /* FIXME: fill these fields in correctly. 32 is arbitrary. */ -# define PTHREAD_MUTEX_SIZE 32 -# define PTHREAD_COND_SIZE 32 -#endif -#define PTHREAD_SPINLOCK_SIZE 4 diff --git a/exp-drd/tests/Makefile.am b/exp-drd/tests/Makefile.am index 2959c5665f..bc01d0daca 100644 --- a/exp-drd/tests/Makefile.am +++ b/exp-drd/tests/Makefile.am @@ -57,4 +57,4 @@ pth_detached_SOURCES = pth_detached.c pth_detached_LDADD = -lpthread sigalrm_SOURCES = sigalrm.c -sigalrm_LDADD = -lpthread -lrt +sigalrm_LDADD = -lpthread