Back to index

glibc  2.9
tst-audit2.c
Go to the documentation of this file.
00001 /* Test case for early TLS initialization in dynamic linker.  */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 #if HAVE___THREAD
00008 # define MAGIC1 0xabcdef72
00009 # define MAGIC2 0xd8675309
00010 static __thread unsigned int magic[] = { MAGIC1, MAGIC2 };
00011 #endif
00012 
00013 #undef calloc
00014 
00015 /* This calloc definition will be called by the dynamic linker itself.
00016    We test that it has initialized our TLS block by the time it does so.  */
00017 
00018 void *
00019 calloc (size_t n, size_t m)
00020 {
00021 #if HAVE___THREAD
00022   if (magic[0] != MAGIC1 || magic[1] != MAGIC2)
00023     {
00024       printf ("{%x, %x} != {%x, %x}\n", magic[0], magic[1], MAGIC1, MAGIC2);
00025       abort ();
00026     }
00027   magic[0] = MAGIC2;
00028   magic[1] = MAGIC1;
00029 #endif
00030 
00031   n *= m;
00032   void *ptr = malloc (n);
00033   if (ptr != NULL)
00034     memset (ptr, '\0', n);
00035   return ptr;
00036 }
00037 
00038 int
00039 main (void)
00040 {
00041 #if HAVE___THREAD
00042   if (magic[1] != MAGIC1 || magic[0] != MAGIC2)
00043     {
00044       printf ("{%x, %x} != {%x, %x}\n", magic[0], magic[1], MAGIC2, MAGIC1);
00045       return 1;
00046     }
00047 #endif
00048 
00049   return 0;
00050 }