]> 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 dyn_elf *) h)->dyn->l_tls_modid;
40       else if (((struct dyn_elf *)h)->dyn->l_tls_modid != (size_t) modid)
41         {
42           printf ("round %d: modid now %zu, initially %d\n",
43                   i,
44                   ((struct dyn_elf *)h)->dyn->l_tls_modid,
45                   modid);
46           result = 1;
47         }
48 #else
49       if (modid == -1)
50         modid = ((struct link_map *) h)->l_tls_modid;
51       else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
52         {
53           printf ("round %d: modid now %zu, initially %d\n",
54                   i, ((struct link_map *) h)->l_tls_modid, modid);
55           result = 1;
56         }
57 #endif
58
59       fp = dlsym (h, "in_dso2");
60       if (fp == NULL)
61         {
62           printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
63           exit (1);
64         }
65
66       result |= fp ();
67
68       dlclose (h);
69     }
70
71   return result;
72 #else
73   return 0;
74 #endif
75 }
76
77
78 #include "../test-skeleton.c"