Back to index

glibc  2.9
tst-tls6.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-tlsmod2.so";
00014   int result = 0;
00015   int *foop;
00016   int *foop2;
00017   int (*fp) (int, int *);
00018   void *h;
00019   int i;
00020   int modid = -1;
00021 
00022   for (i = 0; i < 10; ++i)
00023     {
00024       h = dlopen (modname, RTLD_LAZY);
00025       if (h == NULL)
00026        {
00027          printf ("cannot open '%s': %s\n", modname, dlerror ());
00028          exit (1);
00029        }
00030 
00031       /* Dirty test code here: we peek into a private data structure.
00032         We make sure that the module gets assigned the same ID every
00033         time.  The value of the first round is used.  */
00034       if (modid == -1)
00035        modid = ((struct link_map *) h)->l_tls_modid;
00036       else if (((struct link_map *) h)->l_tls_modid != modid)
00037        {
00038          printf ("round %d: modid now %zd, initially %d\n",
00039                 i, ((struct link_map *) h)->l_tls_modid, modid);
00040          result = 1;
00041        }
00042 
00043       foop = dlsym (h, "foo");
00044       if (foop == NULL)
00045        {
00046          printf ("cannot get symbol 'foo': %s\n", dlerror ());
00047          exit (1);
00048        }
00049 
00050       *foop = 42 + i;
00051 
00052       fp = dlsym (h, "in_dso");
00053       if (fp == NULL)
00054        {
00055          printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
00056          exit (1);
00057        }
00058 
00059       result |= fp (42 + i, foop);
00060 
00061       foop2 = dlsym (h, "foo");
00062       if (foop2 == NULL)
00063        {
00064          printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
00065          exit (1);
00066        }
00067 
00068       if (foop != foop2)
00069        {
00070          puts ("address of 'foo' different the second time");
00071          result = 1;
00072        }
00073       else if (*foop != 16)
00074        {
00075          puts ("foo != 16");
00076          result = 1;
00077        }
00078 
00079       dlclose (h);
00080     }
00081 
00082   return result;
00083 }
00084 
00085 
00086 #include "../test-skeleton.c"