Back to index

glibc  2.9
tst-dlmopen1.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <gnu/lib-names.h>
00004 
00005 
00006 static int
00007 do_test (void)
00008 {
00009   void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
00010   if (h == NULL)
00011     {
00012       printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
00013       return 1;
00014     }
00015 
00016   Lmid_t ns = -10;
00017   if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
00018     {
00019       printf ("dlinfo for %s in %s failed: %s\n",
00020              LIBC_SO, __func__, dlerror ());
00021       return 1;
00022     }
00023 
00024   if (ns != LM_ID_BASE)
00025     {
00026       printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
00027       return 1;
00028     }
00029 
00030   if (dlclose (h) != 0)
00031     {
00032       printf ("dlclose for %s in %s failed: %s\n",
00033              LIBC_SO, __func__, dlerror ());
00034       return 1;
00035     }
00036 
00037   h = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so", RTLD_LAZY);
00038   if (h == NULL)
00039     {
00040       printf ("cannot get handle for %s: %s\n",
00041              "tst-dlmopen1mod.so", dlerror ());
00042       return 1;
00043     }
00044 
00045   ns = -10;
00046   if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
00047     {
00048       printf ("dlinfo for %s in %s failed: %s\n",
00049              "tst-dlmopen1mod.so", __func__, dlerror ());
00050       return 1;
00051     }
00052 
00053   if (ns == LM_ID_BASE)
00054     {
00055       printf ("namespace for %s is LM_ID_BASE\n", LIBC_SO);
00056       return 1;
00057     }
00058 
00059   int (*fct) (Lmid_t) = dlsym (h, "foo");
00060   if (fct == NULL)
00061     {
00062       printf ("could not find %s: %s\n", "foo", dlerror ());
00063       return 1;
00064     }
00065 
00066   if (fct (ns) != 0)
00067     return 1;
00068 
00069   if (dlclose (h) != 0)
00070     {
00071       printf ("dlclose for %s in %s failed: %s\n",
00072              LIBC_SO, __func__, dlerror ());
00073       return 1;
00074     }
00075 
00076   return 0;
00077 }
00078 
00079 #define TEST_FUNCTION do_test ()
00080 #include "../test-skeleton.c"