]>
Commit | Line | Data |
---|---|---|
2b7238dd UD |
1 | /* Test for unloading (really unmapping) of objects. By Franz Sirl. |
2 | This test does not have to passed in all dlopen() et.al. implementation | |
3 | since it is not required the unloading actually happens. But we | |
4 | require it for glibc. */ | |
5 | ||
6 | #include <dlfcn.h> | |
9807e540 | 7 | #include <link.h> |
2b7238dd UD |
8 | #include <mcheck.h> |
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | ||
9807e540 | 12 | #define OUT \ |
a334319f | 13 | for (map = _r_debug.r_map; map != NULL; map = map->l_next) \ |
9807e540 | 14 | if (map->l_type == lt_loaded) \ |
a334319f UD |
15 | printf ("name = \"%s\", opencount = %d\n", \ |
16 | map->l_name, (int) map->l_opencount); \ | |
9807e540 UD |
17 | fflush (stdout) |
18 | ||
2b7238dd UD |
19 | typedef struct |
20 | { | |
21 | void *next; | |
22 | } strct; | |
23 | ||
24 | int | |
25 | main (void) | |
26 | { | |
27 | void *sohandle; | |
28 | strct *testdat; | |
29 | int ret; | |
30 | int result = 0; | |
9807e540 | 31 | struct link_map *map; |
2b7238dd UD |
32 | |
33 | mtrace (); | |
34 | ||
9807e540 UD |
35 | puts ("\nBefore"); |
36 | OUT; | |
37 | ||
2b7238dd UD |
38 | sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL); |
39 | if (sohandle == NULL) | |
40 | { | |
9807e540 | 41 | printf ("*** first dlopen failed: %s\n", dlerror ()); |
2b7238dd UD |
42 | exit (1); |
43 | } | |
44 | ||
9807e540 UD |
45 | puts ("\nAfter loading unloadmod.so"); |
46 | OUT; | |
47 | ||
2b7238dd UD |
48 | testdat = dlsym (sohandle, "testdat"); |
49 | testdat->next = (void *) -1; | |
50 | ||
51 | ret = dlclose (sohandle); | |
52 | if (ret != 0) | |
53 | { | |
9807e540 | 54 | puts ("*** first dlclose failed"); |
2b7238dd UD |
55 | result = 1; |
56 | } | |
57 | ||
9807e540 UD |
58 | puts ("\nAfter closing unloadmod.so"); |
59 | OUT; | |
60 | ||
2b7238dd UD |
61 | sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL); |
62 | if (sohandle == NULL) | |
63 | { | |
9807e540 | 64 | printf ("*** second dlopen failed: %s\n", dlerror ()); |
2b7238dd UD |
65 | exit (1); |
66 | } | |
67 | ||
9807e540 UD |
68 | puts ("\nAfter loading unloadmod.so the second time"); |
69 | OUT; | |
70 | ||
2b7238dd UD |
71 | testdat = dlsym (sohandle, "testdat"); |
72 | if (testdat->next == (void *) -1) | |
73 | { | |
9807e540 | 74 | puts ("*** testdat->next == (void *) -1"); |
2b7238dd UD |
75 | result = 1; |
76 | } | |
77 | ||
78 | ret = dlclose (sohandle); | |
79 | if (ret != 0) | |
80 | { | |
9807e540 | 81 | puts ("*** second dlclose failed"); |
2b7238dd UD |
82 | result = 1; |
83 | } | |
84 | ||
9807e540 UD |
85 | puts ("\nAfter closing unloadmod.so again"); |
86 | OUT; | |
87 | ||
2b7238dd UD |
88 | return result; |
89 | } |