Back to index

glibc  2.9
tst-tls7.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 #include <link.h>
00006 #include <tls.h>
00007 
00008 
00009 #define TEST_FUNCTION do_test ()
00010 static int
00011 do_test (void)
00012 {
00013   static const char modname[] = "tst-tlsmod3.so";
00014   int result = 0;
00015   int (*fp) (void);
00016   void *h;
00017   int i;
00018   int modid = -1;
00019 
00020   for (i = 0; i < 10; ++i)
00021     {
00022       h = dlopen (modname, RTLD_LAZY);
00023       if (h == NULL)
00024        {
00025          printf ("cannot open '%s': %s\n", modname, dlerror ());
00026          exit (1);
00027        }
00028 
00029       /* Dirty test code here: we peek into a private data structure.
00030         We make sure that the module gets assigned the same ID every
00031         time.  The value of the first round is used.  */
00032       if (modid == -1)
00033        modid = ((struct link_map *) h)->l_tls_modid;
00034       else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
00035        {
00036          printf ("round %d: modid now %zu, initially %d\n",
00037                 i, ((struct link_map *) h)->l_tls_modid, modid);
00038          result = 1;
00039        }
00040 
00041       fp = dlsym (h, "in_dso2");
00042       if (fp == NULL)
00043        {
00044          printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
00045          exit (1);
00046        }
00047 
00048       result |= fp ();
00049 
00050       dlclose (h);
00051     }
00052 
00053   return result;
00054 }
00055 
00056 
00057 #include "../test-skeleton.c"