|
Packit Service |
82fcde |
/* Test for unloading (really unmapping) of objects. By Franz Sirl.
|
|
Packit Service |
82fcde |
This test does not have to passed in all dlopen() et.al. implementation
|
|
Packit Service |
82fcde |
since it is not required the unloading actually happens. But we
|
|
Packit Service |
82fcde |
require it for glibc. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <dlfcn.h>
|
|
Packit Service |
82fcde |
#include <link.h>
|
|
Packit Service |
82fcde |
#include <mcheck.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <stdlib.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define MAPS ((struct link_map *) _r_debug.r_map)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define OUT \
|
|
Packit Service |
82fcde |
for (map = MAPS; map != NULL; map = map->l_next) \
|
|
Packit Service |
82fcde |
if (map->l_type == lt_loaded) \
|
|
Packit Service |
82fcde |
printf ("name = \"%s\", direct_opencount = %d\n", \
|
|
Packit Service |
82fcde |
map->l_name, (int) map->l_direct_opencount); \
|
|
Packit Service |
82fcde |
fflush (stdout)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef struct
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *next;
|
|
Packit Service |
82fcde |
} strct;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
main (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *sohandle;
|
|
Packit Service |
82fcde |
strct *testdat;
|
|
Packit Service |
82fcde |
int ret;
|
|
Packit Service |
82fcde |
int result = 0;
|
|
Packit Service |
82fcde |
struct link_map *map;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
mtrace ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
puts ("\nBefore");
|
|
Packit Service |
82fcde |
OUT;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL);
|
|
Packit Service |
82fcde |
if (sohandle == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("*** first dlopen failed: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
puts ("\nAfter loading unloadmod.so");
|
|
Packit Service |
82fcde |
OUT;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
testdat = dlsym (sohandle, "testdat");
|
|
Packit Service |
82fcde |
testdat->next = (void *) -1;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ret = dlclose (sohandle);
|
|
Packit Service |
82fcde |
if (ret != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("*** first dlclose failed");
|
|
Packit Service |
82fcde |
result = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
puts ("\nAfter closing unloadmod.so");
|
|
Packit Service |
82fcde |
OUT;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
sohandle = dlopen ("unloadmod.so", RTLD_NOW | RTLD_GLOBAL);
|
|
Packit Service |
82fcde |
if (sohandle == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("*** second dlopen failed: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
puts ("\nAfter loading unloadmod.so the second time");
|
|
Packit Service |
82fcde |
OUT;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
testdat = dlsym (sohandle, "testdat");
|
|
Packit Service |
82fcde |
if (testdat->next == (void *) -1)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("*** testdat->next == (void *) -1");
|
|
Packit Service |
82fcde |
result = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ret = dlclose (sohandle);
|
|
Packit Service |
82fcde |
if (ret != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("*** second dlclose failed");
|
|
Packit Service |
82fcde |
result = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
puts ("\nAfter closing unloadmod.so again");
|
|
Packit Service |
82fcde |
OUT;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return result;
|
|
Packit Service |
82fcde |
}
|