Back to index

glibc  2.9
tst-tls1.c
Go to the documentation of this file.
00001 /* glibc test for TLS in ld.so.  */
00002 #include <stdio.h>
00003 
00004 #include <tls.h>
00005 
00006 #include "tls-macros.h"
00007 
00008 
00009 /* Two common 'int' variables in TLS.  */
00010 COMMON_INT_DEF(foo);
00011 COMMON_INT_DEF(bar);
00012 
00013 
00014 #define TEST_FUNCTION do_test ()
00015 static int
00016 do_test (void)
00017 {
00018   int result = 0;
00019   int *ap, *bp;
00020 
00021 
00022   /* Set the variable using the local exec model.  */
00023   puts ("set bar to 1 (LE)");
00024   ap = TLS_LE (bar);
00025   *ap = 1;
00026 
00027 
00028   /* Get variables using initial exec model.  */
00029   fputs ("get sum of foo and bar (IE)", stdout);
00030   ap = TLS_IE (foo);
00031   bp = TLS_IE (bar);
00032   printf (" = %d\n", *ap + *bp);
00033   result |= *ap + *bp != 1;
00034   if (*ap != 0)
00035     {
00036       printf ("foo = %d\n", *ap);
00037       result = 1;
00038     }
00039   if (*bp != 1)
00040     {
00041       printf ("bar = %d\n", *bp);
00042       result = 1;
00043     }
00044 
00045 
00046   /* Get variables using local dynamic model.  */
00047   fputs ("get sum of foo and bar (LD)", stdout);
00048   ap = TLS_LD (foo);
00049   bp = TLS_LD (bar);
00050   printf (" = %d\n", *ap + *bp);
00051   result |= *ap + *bp != 1;
00052   if (*ap != 0)
00053     {
00054       printf ("foo = %d\n", *ap);
00055       result = 1;
00056     }
00057   if (*bp != 1)
00058     {
00059       printf ("bar = %d\n", *bp);
00060       result = 1;
00061     }
00062 
00063 
00064   /* Get variables using generic dynamic model.  */
00065   fputs ("get sum of foo and bar (GD)", stdout);
00066   ap = TLS_GD (foo);
00067   bp = TLS_GD (bar);
00068   printf (" = %d\n", *ap + *bp);
00069   result |= *ap + *bp != 1;
00070   if (*ap != 0)
00071     {
00072       printf ("foo = %d\n", *ap);
00073       result = 1;
00074     }
00075   if (*bp != 1)
00076     {
00077       printf ("bar = %d\n", *bp);
00078       result = 1;
00079     }
00080 
00081   return result;
00082 }
00083 
00084 
00085 #include "../test-skeleton.c"