-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unload.c
56 lines (41 loc) · 1.12 KB
/
test_unload.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
extern void * __libc_dlopen_mode(char *name, int flags);
extern void * __libc_dlsym(void *handle, char *name);
extern void __libc_dlclose(void *handle);
int stopping = 0;
int stopped = 0;
void * threadfunc (void * arg)
{
printf ("in threadfunc\n");
void * handle = __libc_dlopen_mode ("./test_unload.so", RTLD_LAZY | 0x80000000);
printf ("dlopen ok handle: %p\n", handle);
void (*pfn_shared_method)(void) = __libc_dlsym(handle, "shared_method");
printf ("before func\n");
pfn_shared_method ();
printf ("after func\n");
printf ("about to dlclose handle: %p\n", handle);
__libc_dlclose (handle);
printf ("done dlclose\n");
while (!stopping)
sleep (1);
printf ("leaving threadfunc\n");
stopped = 1;
}
int main (int argc, char **argv)
{
printf ("started\n");
pthread_t thread;
pthread_create (&thread, NULL, threadfunc, NULL);
printf ("letting thread run...\n");
sleep (5);
printf ("stopping thread...\n");
stopping = 1;
while(!stopped)
sleep(1);
return 0;
}