Back to index

glibc  2.9
tst-tlsmod1.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include <tls.h>
00004 
00005 #include "tls-macros.h"
00006 
00007 
00008 /* One define int variable, two externs.  */
00009 COMMON_INT_DEF(foo);
00010 VAR_INT_DEF(bar);
00011 VAR_INT_DECL(baz);
00012 
00013 extern int in_dso (void);
00014 
00015 int
00016 in_dso (void)
00017 {
00018   int result = 0;
00019   int *ap, *bp, *cp;
00020 
00021   /* Get variables using initial exec model.  */
00022   fputs ("get sum of foo and bar (IE)", stdout);
00023   asm ("" ::: "memory");
00024   ap = TLS_IE (foo);
00025   bp = TLS_IE (bar);
00026   printf (" = %d\n", *ap + *bp);
00027   result |= *ap + *bp != 3;
00028   if (*ap != 1)
00029     {
00030       printf ("foo = %d\n", *ap);
00031       result = 1;
00032     }
00033   if (*bp != 2)
00034     {
00035       printf ("bar = %d\n", *bp);
00036       result = 1;
00037     }
00038 
00039 
00040   /* Get variables using generic dynamic model.  */
00041   fputs ("get sum of foo and bar and baz (GD)", stdout);
00042   ap = TLS_GD (foo);
00043   bp = TLS_GD (bar);
00044   cp = TLS_GD (baz);
00045   printf (" = %d\n", *ap + *bp + *cp);
00046   result |= *ap + *bp + *cp != 6;
00047   if (*ap != 1)
00048     {
00049       printf ("foo = %d\n", *ap);
00050       result = 1;
00051     }
00052   if (*bp != 2)
00053     {
00054       printf ("bar = %d\n", *bp);
00055       result = 1;
00056     }
00057   if (*cp != 3)
00058     {
00059       printf ("baz = %d\n", *cp);
00060       result = 1;
00061     }
00062 
00063   return result;
00064 }