Back to index

glibc  2.9
tst-dlmopen2.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <gnu/lib-names.h>
00005 #include <ldsodefs.h>
00006 
00007 
00008 static int
00009 do_test (void)
00010 {
00011   int result = 0;
00012 
00013   for (int i = 1; i <= 10; ++i)
00014     {
00015       void *h[DL_NNS - 1];
00016       char used[DL_NNS];
00017 
00018       printf ("round %d\n", i);
00019 
00020       memset (used, '\0', sizeof (used));
00021       used[LM_ID_BASE] = 1;
00022 
00023       for (int j = 0; j < DL_NNS - 1; ++j)
00024        {
00025          h[j] = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so",
00026                        RTLD_LAZY);
00027          if (h[j] == NULL)
00028            {
00029              printf ("round %d, namespace %d: load failed: %s\n",
00030                     i, j, dlerror ());
00031              return 1;
00032            }
00033          Lmid_t ns;
00034          if (dlinfo (h[j], RTLD_DI_LMID, &ns) != 0)
00035            {
00036              printf ("round %d, namespace %d: dlinfo failed: %s\n",
00037                     i, j, dlerror ());
00038              return 1;
00039            }
00040          if (ns < 0 || ns >= DL_NNS)
00041            {
00042              printf ("round %d, namespace %d: invalid namespace %ld",
00043                     i, j, (long int) ns);
00044              result = 1;
00045            }
00046          else if (used[ns] != 0)
00047            {
00048              printf ("\
00049 round %d, namespace %d: duplicate allocate of namespace %ld",
00050                     i, j, (long int) ns);
00051              result = 1;
00052            }
00053          else
00054            used[ns] = 1;
00055        }
00056 
00057       for (int j = 0; j < DL_NNS - 1; ++j)
00058        if (dlclose (h[j]) != 0)
00059          {
00060            printf ("round %d, namespace %d: close failed: %s\n",
00061                   i, j, dlerror ());
00062            return 1;
00063          }
00064     }
00065 
00066   return result;
00067 }
00068 
00069 #define TEST_FUNCTION do_test ()
00070 #include "../test-skeleton.c"