]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/tls/tst-tls7.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / tls / tst-tls7.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <tls.h>
6 #include <link.h>
7 #ifdef __UCLIBC__
8 #include "dl-elf.h"
9 #include "dl-hash.h"
10 #endif
11
12
13 #define TEST_FUNCTION do_test ()
14 static int
15 do_test (void)
16 {
17 #ifdef USE_TLS
18   static const char modname[] = "tst-tlsmod3.so";
19   int result = 0;
20   int (*fp) (void);
21   void *h;
22   int i;
23   int modid = -1;
24
25   for (i = 0; i < 10; ++i)
26     {
27       h = dlopen (modname, RTLD_LAZY);
28       if (h == NULL)
29         {
30           printf ("cannot open '%s': %s\n", modname, dlerror ());
31           exit (1);
32         }
33
34       /* Dirty test code here: we peek into a private data structure.
35          We make sure that the module gets assigned the same ID every
36          time.  The value of the first round is used.  */
37 #ifdef __UCLIBC__
38       if (modid == -1)
39         modid = ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid;
40       else if (((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid
41         != (size_t) modid)
42         {
43           printf ("round %d: modid now %zu, initially %d\n",
44                   i,
45                   ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid,
46                   modid);
47           result = 1;
48         }
49 #else
50       if (modid == -1)
51         modid = ((struct link_map *) h)->l_tls_modid;
52       else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
53         {
54           printf ("round %d: modid now %zu, initially %d\n",
55                   i, ((struct link_map *) h)->l_tls_modid, modid);
56           result = 1;
57         }
58 #endif
59
60       fp = dlsym (h, "in_dso2");
61       if (fp == NULL)
62         {
63           printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
64           exit (1);
65         }
66
67       result |= fp ();
68
69       dlclose (h);
70     }
71
72   return result;
73 #else
74   return 0;
75 #endif
76 }
77
78
79 #include "../test-skeleton.c"