]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/tls/tst-tls6.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / tls / tst-tls6.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-tlsmod2.so";
19   int result = 0;
20   int *foop;
21   int *foop2;
22   int (*fp) (int, int *);
23   void *h;
24   int i;
25   int modid = -1;
26
27   for (i = 0; i < 10; ++i)
28     {
29       h = dlopen (modname, RTLD_LAZY);
30       if (h == NULL)
31         {
32           printf ("cannot open '%s': %s\n", modname, dlerror ());
33           exit (1);
34         }
35
36       /* Dirty test code here: we peek into a private data structure.
37          We make sure that the module gets assigned the same ID every
38          time.  The value of the first round is used.  */
39 #ifdef __UCLIBC__
40       if (modid == -1)
41         modid = ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid;
42       else if (((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid
43         != (size_t) modid)
44         {
45           printf ("round %d: modid now %zu, initially %d\n",
46                   i,
47                   ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid,
48                   modid);
49           result = 1;
50         }
51 #else
52       if (modid == -1)
53         modid = ((struct link_map *) h)->l_tls_modid;
54       else if (((struct link_map *) h)->l_tls_modid != modid)
55         {
56           printf ("round %d: modid now %zd, initially %d\n",
57                   i, ((struct link_map *) h)->l_tls_modid, modid);
58           result = 1;
59         }
60 #endif
61
62       foop = dlsym (h, "foo");
63       if (foop == NULL)
64         {
65           printf ("cannot get symbol 'foo': %s\n", dlerror ());
66           exit (1);
67         }
68
69       *foop = 42 + i;
70
71       fp = dlsym (h, "in_dso");
72       if (fp == NULL)
73         {
74           printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
75           exit (1);
76         }
77
78       result |= fp (42 + i, foop);
79
80       foop2 = dlsym (h, "foo");
81       if (foop2 == NULL)
82         {
83           printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
84           exit (1);
85         }
86
87       if (foop != foop2)
88         {
89           puts ("address of 'foo' different the second time");
90           result = 1;
91         }
92       else if (*foop != 16)
93         {
94           puts ("foo != 16");
95           result = 1;
96         }
97
98       dlclose (h);
99     }
100
101   return result;
102 #else
103   return 0;
104 #endif
105 }
106
107
108 #include "../test-skeleton.c"