00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <dlfcn.h>
00032
00033 extern "C" void *GC_start_routine(void * arg);
00034
00035 typedef void *pthread_create_type(void *a, void *b, void *c, void *d);
00036
00037 extern "C" void *GC_pthread_create(void *, void *, void *, void *);
00038
00039 void *pthread_lib = NULL;
00040 pthread_create_type *orig = NULL;
00041
00042 extern "C" void *pthread_create(void *a, void *b, void *c, void *d)
00043 {
00044 if (c != (void*)GC_start_routine)
00045 return GC_pthread_create(a, b, c, d);
00046 else {
00047 if (pthread_lib == NULL) {
00048 pthread_lib = dlopen("libpthread.so.0", RTLD_LAZY);
00049 if (pthread_lib == NULL) {
00050 printf("cannot dynamically open pthreads %s.\n", dlerror());
00051 exit(1);
00052 }
00053 orig = (pthread_create_type*)dlsym(pthread_lib, "pthread_create");
00054 if (orig == NULL) {
00055 printf("cannot find symbol pthread_create %s.\n", dlerror());
00056 exit(1);
00057 }
00058 }
00059 return (*orig)(a, b, c, d);
00060 }
00061 }
00062
00063