This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <dlfcn.h> | |
static void *(*malloc_internal)(size_t size); | |
void __attribute__ ((constructor)) init(void); | |
/* Library constructor */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ LD_PRELOAD=./malloc_wrap.so /bin/uname | |
Malloc request for 34 bytes got memory: 0x1103010 | |
Malloc request for 10 bytes got memory: 0x1103040 | |
Linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc -Wall -shared -fPIC -o malloc_wrap.so malloc_wrap.c -ldl | |
$ LD_PRELOAD=./malloc_wrap.so /bin/uname | |
Malloc request for 34 bytes got memory: 0x1103010 | |
Malloc request for 10 bytes got memory: 0x1103040 | |
Linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./condwait_test | |
Thread exiting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc -g3 -Wall -fPIC -shared -o condwait_wrap.so condwait_wrap.c -ldl -lpthread | |
$ gcc -g3 -Wall -o condwait_test condwait_test.c -lpthread | |
$ ./condwait_test | |
Thread exiting | |
$ LD_PRELOAD=./condwait_wrap.so ./condwait_test | |
Calling func condwait with cond: 0x600d80, mutex: 0x600dc0...^C | |
Exit 130 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |