From: Julian Seward Date: Fri, 26 Apr 2002 03:28:18 +0000 (+0000) Subject: Fix many holes and bugs in an attempt to get my libpthread.so to export X-Git-Tag: svn/VALGRIND_1_0_3~300 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=edf9ed279b74f4821157d1474d62cf831fa1bc24;p=thirdparty%2Fvalgrind.git Fix many holes and bugs in an attempt to get my libpthread.so to export the same set of symbols as the real one, which I now realise is crucial for it to work at all. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@151 --- diff --git a/coregrind/arch/x86-linux/vg_libpthread.c b/coregrind/arch/x86-linux/vg_libpthread.c index 2715953a05..4644a0e610 100644 --- a/coregrind/arch/x86-linux/vg_libpthread.c +++ b/coregrind/arch/x86-linux/vg_libpthread.c @@ -679,6 +679,90 @@ struct __res_state* __res_state ( void ) } +/* --------------------------------------------------- + LIBC-PRIVATE SPECIFIC DATA + ------------------------------------------------ */ + +/* Relies on assumption that initial private data is NULL. This + should be fixed somehow. */ + +/* The allowable keys (indices) (all 2 of them). + From sysdeps/pthread/bits/libc-tsd.h +*/ +enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, + _LIBC_TSD_KEY_DL_ERROR, + _LIBC_TSD_KEY_N }; + +/* Auto-initialising subsystem. libc_specifics_inited is set + after initialisation. libc_specifics_inited_mx guards it. */ +static int libc_specifics_inited = 0; +static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; + +/* These are the keys we must initialise the first time. */ +static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N]; + +/* Initialise the keys, if they are not already initialise. */ +static +void init_libc_tsd_keys ( void ) +{ + int res, i; + pthread_key_t k; + + res = pthread_mutex_lock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: lock"); + + if (libc_specifics_inited == 0) { + /* printf("INIT libc specifics\n"); */ + libc_specifics_inited = 1; + for (i = 0; i < _LIBC_TSD_KEY_N; i++) { + res = pthread_key_create(&k, NULL); + if (res != 0) barf("init_libc_tsd_keys: create"); + libc_specifics_keys[i] = k; + } + } + + res = pthread_mutex_unlock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: unlock"); +} + + +static int +libc_internal_tsd_set ( enum __libc_tsd_key_t key, + const void * pointer ) +{ + int res; + /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_set: invalid key"); + init_libc_tsd_keys(); + res = pthread_setspecific(libc_specifics_keys[key], pointer); + if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); + return 0; +} + +static void * +libc_internal_tsd_get ( enum __libc_tsd_key_t key ) +{ + void* v; + /* printf("GET GET GET key %d\n", key); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_get: invalid key"); + init_libc_tsd_keys(); + v = pthread_getspecific(libc_specifics_keys[key]); + /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ + return v; +} + + + + +int (*__libc_internal_tsd_set)(enum __libc_tsd_key_t key, const void * pointer) + = libc_internal_tsd_set; + +void* (*__libc_internal_tsd_get)(enum __libc_tsd_key_t key) + = libc_internal_tsd_get; + + /* --------------------------------------------------------------------- These are here (I think) because they are deemed cancellation points by POSIX. For the moment we'll simply pass the call along @@ -1214,6 +1298,26 @@ strong_alias(connect, __connect) /*--------------------------------------------------*/ +int +pthread_rwlock_rdlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_rdlock"); + return 0; +} + +strong_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) + + +int +pthread_rwlock_unlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_unlock"); + return 0; +} + +strong_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) + + /* I've no idea what these are, but they get called quite a lot. Anybody know? */ diff --git a/coregrind/arch/x86-linux/vg_libpthread_unimp.c b/coregrind/arch/x86-linux/vg_libpthread_unimp.c index d01dc5bfb0..a2cc926d7e 100644 --- a/coregrind/arch/x86-linux/vg_libpthread_unimp.c +++ b/coregrind/arch/x86-linux/vg_libpthread_unimp.c @@ -101,12 +101,12 @@ void pthread_mutex_timedlock ( void ) { unimp("pthread_mutex_timedlock"); } //void pthread_once ( void ) { unimp("pthread_once"); } void pthread_rwlock_destroy ( void ) { unimp("pthread_rwlock_destroy"); } void pthread_rwlock_init ( void ) { unimp("pthread_rwlock_init"); } -void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } +//void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } void pthread_rwlock_timedrdlock ( void ) { unimp("pthread_rwlock_timedrdlock"); } void pthread_rwlock_timedwrlock ( void ) { unimp("pthread_rwlock_timedwrlock"); } void pthread_rwlock_tryrdlock ( void ) { unimp("pthread_rwlock_tryrdlock"); } void pthread_rwlock_trywrlock ( void ) { unimp("pthread_rwlock_trywrlock"); } -void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } +//void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } void pthread_rwlock_wrlock ( void ) { unimp("pthread_rwlock_wrlock"); } void pthread_rwlockattr_destroy ( void ) { unimp("pthread_rwlockattr_destroy"); } void pthread_rwlockattr_getkind_np ( void ) { unimp("pthread_rwlockattr_getkind_np"); } @@ -153,3 +153,4 @@ void sem_init@GLIBC_2.0 ( void ) { unimp("sem_init@GLIBC_2.0"); } void pthread_attr_init@@GLIBC_2.1 ( void ) { unimp("pthread_attr_init@@GLIBC_2.1"); } void pthread_attr_init@GLIBC_2.0 ( void ) { unimp("pthread_attr_init@GLIBC_2.0"); } #endif + diff --git a/coregrind/valgrind.in b/coregrind/valgrind.in index d16b5d9664..7f18890796 100755 --- a/coregrind/valgrind.in +++ b/coregrind/valgrind.in @@ -166,5 +166,6 @@ export LD_LIBRARY_PATH LD_PRELOAD=valgrind.so:$LD_PRELOAD export LD_PRELOAD #LD_DEBUG=files +#LD_DEBUG=symbols #export LD_DEBUG exec "$@" diff --git a/coregrind/vg_libpthread.c b/coregrind/vg_libpthread.c index 2715953a05..4644a0e610 100644 --- a/coregrind/vg_libpthread.c +++ b/coregrind/vg_libpthread.c @@ -679,6 +679,90 @@ struct __res_state* __res_state ( void ) } +/* --------------------------------------------------- + LIBC-PRIVATE SPECIFIC DATA + ------------------------------------------------ */ + +/* Relies on assumption that initial private data is NULL. This + should be fixed somehow. */ + +/* The allowable keys (indices) (all 2 of them). + From sysdeps/pthread/bits/libc-tsd.h +*/ +enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, + _LIBC_TSD_KEY_DL_ERROR, + _LIBC_TSD_KEY_N }; + +/* Auto-initialising subsystem. libc_specifics_inited is set + after initialisation. libc_specifics_inited_mx guards it. */ +static int libc_specifics_inited = 0; +static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; + +/* These are the keys we must initialise the first time. */ +static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N]; + +/* Initialise the keys, if they are not already initialise. */ +static +void init_libc_tsd_keys ( void ) +{ + int res, i; + pthread_key_t k; + + res = pthread_mutex_lock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: lock"); + + if (libc_specifics_inited == 0) { + /* printf("INIT libc specifics\n"); */ + libc_specifics_inited = 1; + for (i = 0; i < _LIBC_TSD_KEY_N; i++) { + res = pthread_key_create(&k, NULL); + if (res != 0) barf("init_libc_tsd_keys: create"); + libc_specifics_keys[i] = k; + } + } + + res = pthread_mutex_unlock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: unlock"); +} + + +static int +libc_internal_tsd_set ( enum __libc_tsd_key_t key, + const void * pointer ) +{ + int res; + /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_set: invalid key"); + init_libc_tsd_keys(); + res = pthread_setspecific(libc_specifics_keys[key], pointer); + if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); + return 0; +} + +static void * +libc_internal_tsd_get ( enum __libc_tsd_key_t key ) +{ + void* v; + /* printf("GET GET GET key %d\n", key); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_get: invalid key"); + init_libc_tsd_keys(); + v = pthread_getspecific(libc_specifics_keys[key]); + /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ + return v; +} + + + + +int (*__libc_internal_tsd_set)(enum __libc_tsd_key_t key, const void * pointer) + = libc_internal_tsd_set; + +void* (*__libc_internal_tsd_get)(enum __libc_tsd_key_t key) + = libc_internal_tsd_get; + + /* --------------------------------------------------------------------- These are here (I think) because they are deemed cancellation points by POSIX. For the moment we'll simply pass the call along @@ -1214,6 +1298,26 @@ strong_alias(connect, __connect) /*--------------------------------------------------*/ +int +pthread_rwlock_rdlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_rdlock"); + return 0; +} + +strong_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) + + +int +pthread_rwlock_unlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_unlock"); + return 0; +} + +strong_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) + + /* I've no idea what these are, but they get called quite a lot. Anybody know? */ diff --git a/coregrind/vg_libpthread_unimp.c b/coregrind/vg_libpthread_unimp.c index d01dc5bfb0..a2cc926d7e 100644 --- a/coregrind/vg_libpthread_unimp.c +++ b/coregrind/vg_libpthread_unimp.c @@ -101,12 +101,12 @@ void pthread_mutex_timedlock ( void ) { unimp("pthread_mutex_timedlock"); } //void pthread_once ( void ) { unimp("pthread_once"); } void pthread_rwlock_destroy ( void ) { unimp("pthread_rwlock_destroy"); } void pthread_rwlock_init ( void ) { unimp("pthread_rwlock_init"); } -void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } +//void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } void pthread_rwlock_timedrdlock ( void ) { unimp("pthread_rwlock_timedrdlock"); } void pthread_rwlock_timedwrlock ( void ) { unimp("pthread_rwlock_timedwrlock"); } void pthread_rwlock_tryrdlock ( void ) { unimp("pthread_rwlock_tryrdlock"); } void pthread_rwlock_trywrlock ( void ) { unimp("pthread_rwlock_trywrlock"); } -void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } +//void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } void pthread_rwlock_wrlock ( void ) { unimp("pthread_rwlock_wrlock"); } void pthread_rwlockattr_destroy ( void ) { unimp("pthread_rwlockattr_destroy"); } void pthread_rwlockattr_getkind_np ( void ) { unimp("pthread_rwlockattr_getkind_np"); } @@ -153,3 +153,4 @@ void sem_init@GLIBC_2.0 ( void ) { unimp("sem_init@GLIBC_2.0"); } void pthread_attr_init@@GLIBC_2.1 ( void ) { unimp("pthread_attr_init@@GLIBC_2.1"); } void pthread_attr_init@GLIBC_2.0 ( void ) { unimp("pthread_attr_init@GLIBC_2.0"); } #endif + diff --git a/coregrind/vg_to_ucode.c b/coregrind/vg_to_ucode.c index b1b2855647..f06689d956 100644 --- a/coregrind/vg_to_ucode.c +++ b/coregrind/vg_to_ucode.c @@ -3066,7 +3066,10 @@ static Addr disInstr ( UCodeBlock* cb, Addr eip, Bool* isEnd ) } /* Skip a LOCK prefix. */ - if (getUChar(eip) == 0xF0) eip++; + if (getUChar(eip) == 0xF0) { + /* VG_(printf)("LOCK LOCK LOCK LOCK LOCK \n"); */ + eip++; + } /* Crap out if we see a segment override prefix. */ if (getUChar(eip) == 0x65) { diff --git a/valgrind.in b/valgrind.in index d16b5d9664..7f18890796 100755 --- a/valgrind.in +++ b/valgrind.in @@ -166,5 +166,6 @@ export LD_LIBRARY_PATH LD_PRELOAD=valgrind.so:$LD_PRELOAD export LD_PRELOAD #LD_DEBUG=files +#LD_DEBUG=symbols #export LD_DEBUG exec "$@" diff --git a/vg_libpthread.c b/vg_libpthread.c index 2715953a05..4644a0e610 100644 --- a/vg_libpthread.c +++ b/vg_libpthread.c @@ -679,6 +679,90 @@ struct __res_state* __res_state ( void ) } +/* --------------------------------------------------- + LIBC-PRIVATE SPECIFIC DATA + ------------------------------------------------ */ + +/* Relies on assumption that initial private data is NULL. This + should be fixed somehow. */ + +/* The allowable keys (indices) (all 2 of them). + From sysdeps/pthread/bits/libc-tsd.h +*/ +enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0, + _LIBC_TSD_KEY_DL_ERROR, + _LIBC_TSD_KEY_N }; + +/* Auto-initialising subsystem. libc_specifics_inited is set + after initialisation. libc_specifics_inited_mx guards it. */ +static int libc_specifics_inited = 0; +static pthread_mutex_t libc_specifics_inited_mx = PTHREAD_MUTEX_INITIALIZER; + +/* These are the keys we must initialise the first time. */ +static pthread_key_t libc_specifics_keys[_LIBC_TSD_KEY_N]; + +/* Initialise the keys, if they are not already initialise. */ +static +void init_libc_tsd_keys ( void ) +{ + int res, i; + pthread_key_t k; + + res = pthread_mutex_lock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: lock"); + + if (libc_specifics_inited == 0) { + /* printf("INIT libc specifics\n"); */ + libc_specifics_inited = 1; + for (i = 0; i < _LIBC_TSD_KEY_N; i++) { + res = pthread_key_create(&k, NULL); + if (res != 0) barf("init_libc_tsd_keys: create"); + libc_specifics_keys[i] = k; + } + } + + res = pthread_mutex_unlock(&libc_specifics_inited_mx); + if (res != 0) barf("init_libc_tsd_keys: unlock"); +} + + +static int +libc_internal_tsd_set ( enum __libc_tsd_key_t key, + const void * pointer ) +{ + int res; + /* printf("SET SET SET key %d ptr %p\n", key, pointer); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_set: invalid key"); + init_libc_tsd_keys(); + res = pthread_setspecific(libc_specifics_keys[key], pointer); + if (res != 0) barf("libc_internal_tsd_set: setspecific failed"); + return 0; +} + +static void * +libc_internal_tsd_get ( enum __libc_tsd_key_t key ) +{ + void* v; + /* printf("GET GET GET key %d\n", key); */ + if (key < _LIBC_TSD_KEY_MALLOC || key >= _LIBC_TSD_KEY_N) + barf("libc_internal_tsd_get: invalid key"); + init_libc_tsd_keys(); + v = pthread_getspecific(libc_specifics_keys[key]); + /* if (v == NULL) barf("libc_internal_tsd_set: getspecific failed"); */ + return v; +} + + + + +int (*__libc_internal_tsd_set)(enum __libc_tsd_key_t key, const void * pointer) + = libc_internal_tsd_set; + +void* (*__libc_internal_tsd_get)(enum __libc_tsd_key_t key) + = libc_internal_tsd_get; + + /* --------------------------------------------------------------------- These are here (I think) because they are deemed cancellation points by POSIX. For the moment we'll simply pass the call along @@ -1214,6 +1298,26 @@ strong_alias(connect, __connect) /*--------------------------------------------------*/ +int +pthread_rwlock_rdlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_rdlock"); + return 0; +} + +strong_alias(pthread_rwlock_rdlock, __pthread_rwlock_rdlock) + + +int +pthread_rwlock_unlock (void* /* pthread_rwlock_t* */ rwlock) +{ + kludged("pthread_rwlock_unlock"); + return 0; +} + +strong_alias(pthread_rwlock_unlock, __pthread_rwlock_unlock) + + /* I've no idea what these are, but they get called quite a lot. Anybody know? */ diff --git a/vg_libpthread_unimp.c b/vg_libpthread_unimp.c index d01dc5bfb0..a2cc926d7e 100644 --- a/vg_libpthread_unimp.c +++ b/vg_libpthread_unimp.c @@ -101,12 +101,12 @@ void pthread_mutex_timedlock ( void ) { unimp("pthread_mutex_timedlock"); } //void pthread_once ( void ) { unimp("pthread_once"); } void pthread_rwlock_destroy ( void ) { unimp("pthread_rwlock_destroy"); } void pthread_rwlock_init ( void ) { unimp("pthread_rwlock_init"); } -void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } +//void pthread_rwlock_rdlock ( void ) { unimp("pthread_rwlock_rdlock"); } void pthread_rwlock_timedrdlock ( void ) { unimp("pthread_rwlock_timedrdlock"); } void pthread_rwlock_timedwrlock ( void ) { unimp("pthread_rwlock_timedwrlock"); } void pthread_rwlock_tryrdlock ( void ) { unimp("pthread_rwlock_tryrdlock"); } void pthread_rwlock_trywrlock ( void ) { unimp("pthread_rwlock_trywrlock"); } -void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } +//void pthread_rwlock_unlock ( void ) { unimp("pthread_rwlock_unlock"); } void pthread_rwlock_wrlock ( void ) { unimp("pthread_rwlock_wrlock"); } void pthread_rwlockattr_destroy ( void ) { unimp("pthread_rwlockattr_destroy"); } void pthread_rwlockattr_getkind_np ( void ) { unimp("pthread_rwlockattr_getkind_np"); } @@ -153,3 +153,4 @@ void sem_init@GLIBC_2.0 ( void ) { unimp("sem_init@GLIBC_2.0"); } void pthread_attr_init@@GLIBC_2.1 ( void ) { unimp("pthread_attr_init@@GLIBC_2.1"); } void pthread_attr_init@GLIBC_2.0 ( void ) { unimp("pthread_attr_init@GLIBC_2.0"); } #endif + diff --git a/vg_to_ucode.c b/vg_to_ucode.c index b1b2855647..f06689d956 100644 --- a/vg_to_ucode.c +++ b/vg_to_ucode.c @@ -3066,7 +3066,10 @@ static Addr disInstr ( UCodeBlock* cb, Addr eip, Bool* isEnd ) } /* Skip a LOCK prefix. */ - if (getUChar(eip) == 0xF0) eip++; + if (getUChar(eip) == 0xF0) { + /* VG_(printf)("LOCK LOCK LOCK LOCK LOCK \n"); */ + eip++; + } /* Crap out if we see a segment override prefix. */ if (getUChar(eip) == 0x65) {