chunksize(x) => x->size
[glibc.git] / elf / unload.c
blob4fd82b7e3a220931a6e8442c2e6988eec74cb894
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. */
6 #include <dlfcn.h>
7 #include <link.h>
8 #include <mcheck.h>
9 #include <stdio.h>
10 #include <stdlib.h>
12 #define OUT \
13 for (map = _r_debug.r_map; map != NULL; map = map->l_next) \
14 if (map->l_type == lt_loaded) \
15 printf ("name = \"%s\", opencount = %d\n", \
16 map->l_name, (int) map->l_opencount); \
17 fflush (stdout)
19 typedef struct
21 void *next;
22 } strct;
24 int
25 main (void)
27 void *sohandle;
28 strct *testdat;
29 int ret;
30 int result = 0;
31 struct link_map *map;
33 mtrace ();
35 puts ("\nBefore");
36 OUT;
38 sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL);
39 if (sohandle == NULL)
41 printf ("*** first dlopen failed: %s\n", dlerror ());
42 exit (1);
45 puts ("\nAfter loading unloadmod.so");
46 OUT;
48 testdat = dlsym (sohandle, "testdat");
49 testdat->next = (void *) -1;
51 ret = dlclose (sohandle);
52 if (ret != 0)
54 puts ("*** first dlclose failed");
55 result = 1;
58 puts ("\nAfter closing unloadmod.so");
59 OUT;
61 sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL);
62 if (sohandle == NULL)
64 printf ("*** second dlopen failed: %s\n", dlerror ());
65 exit (1);
68 puts ("\nAfter loading unloadmod.so the second time");
69 OUT;
71 testdat = dlsym (sohandle, "testdat");
72 if (testdat->next == (void *) -1)
74 puts ("*** testdat->next == (void *) -1");
75 result = 1;
78 ret = dlclose (sohandle);
79 if (ret != 0)
81 puts ("*** second dlclose failed");
82 result = 1;
85 puts ("\nAfter closing unloadmod.so again");
86 OUT;
88 return result;