Skip to content

Instantly share code, notes, and snippets.

$ gcc -g3 -Wall -fPIC -shared -o condwait_wrap.so condwait_wrap.c -ldl -lpthread
$ gcc -g3 -Wall -o condwait_test condwait_test.c -lpthread
$ LD_PRELOAD=./condwait_wrap.so ./condwait_test
Calling func condwait with cond: 0x600d80, mutex: 0x600dc0.....got it!
Thread exiting
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <pthread.h>
static int (*condwait_internal)(pthread_cond_t *cond, pthread_mutex_t *mutex);
void __attribute__ ((constructor)) init(void);
$ objdump -t /lib64/libpthread.so.0 | grep pthread_cond_wait
0000000000000000 l df *ABS* 0000000000000000 old_pthread_cond_wait.c
0000003cf900b240 l F .text 00000000000001f7 __pthread_cond_wait
0000003cf900b8f0 l F .text 0000000000000098 __pthread_cond_wait_2_0
0000003cf900b240 g F .text 00000000000001f7 pthread_cond_wait@@GLIBC_2.3.2
0000003cf900b8f0 g F .text 0000000000000098 pthread_cond_wait@GLIBC_2.2.5
$ objdump -t condwait_test | grep pthread_cond_wait
0000000000000000 F *UND* 0000000000000000 pthread_cond_wait@@GLIBC_2.3.2
$ objdump -t /lib64/libpthread.so.0 | grep pthread_cond_wait
0000000000000000 l df *ABS* 0000000000000000 old_pthread_cond_wait.c
0000003cf900b240 l F .text 00000000000001f7 __pthread_cond_wait
0000003cf900b8f0 l F .text 0000000000000098 __pthread_cond_wait_2_0
0000003cf900b240 g F .text 00000000000001f7 pthread_cond_wait@@GLIBC_2.3.2
0000003cf900b8f0 g F .text 0000000000000098 pthread_cond_wait@GLIBC_2.2.5
#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
int
__pthread_cond_wait_2_0 (cond, mutex)
pthread_cond_2_0_t *cond;
pthread_mutex_t *mutex;
{
if (cond->cond == NULL)
{
pthread_cond_t *newcond;
$ gdb condwait_test
<snip LICENSE>
(gdb) set environment LD_PRELOAD ./condwait_wrap.so
(gdb) b condwait_test.c:17
Breakpoint 1 at 0x400864: file condwait_test.c, line 17.
(gdb) r
Starting program: condwait_test
[Thread debugging using libthread_db enabled]
$ gdb condwait_test
<snip LICENSE>
(gdb) b condwait_test.c:17
Breakpoint 1 at 0x400864: file condwait_test.c, line 17.
(gdb) r
Starting program: condwait_test
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff7fd5910 (LWP 32595)]
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <pthread.h>
static int (*condwait_internal)(pthread_cond_t *cond, pthread_mutex_t *mutex);
void __attribute__ ((constructor)) init(void);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
static int okexit = 0;