source: vendor/glibc-tests/2005-06-14/nptl/tst-tls5.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20/* Check alignment, overlapping and layout of TLS variables. */
21#include <stdint.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <pthread.h>
25#include <pthreadP.h>
26#include <sys/param.h>
27
28#include "tst-tls5.h"
29
30#ifdef TLS_REGISTER
31
32struct tls_obj tls_registry[64];
33
34static int
35tls_addr_cmp (const void *a, const void *b)
36{
37 if (((struct tls_obj *)a)->addr < ((struct tls_obj *)b)->addr)
38 return -1;
39 if (((struct tls_obj *)a)->addr > ((struct tls_obj *)b)->addr)
40 return 1;
41 return 0;
42}
43
44static int
45do_test (void)
46{
47 size_t cnt, i;
48 int res = 0;
49 uintptr_t min_addr = ~(uintptr_t) 0, max_addr = 0;
50
51 for (cnt = 0; tls_registry[cnt].name; ++cnt);
52 tls_registry[cnt].name = NULL;
53 tls_registry[cnt].addr = (uintptr_t) pthread_self ();
54 tls_registry[cnt].size = sizeof (struct pthread);
55 tls_registry[cnt++].align = __alignof__ (struct pthread);
56
57 qsort (tls_registry, cnt, sizeof (struct tls_obj), tls_addr_cmp);
58
59 for (i = 0; i < cnt; ++i)
60 {
61 printf ("%s%s = %p, size %zd, align %zd",
62 tls_registry[i].name ? "&" : "",
63 tls_registry[i].name ?: "pthread_self ()",
64 (void *) tls_registry[i].addr,
65 tls_registry[i].size, tls_registry[i].align);
66 if (tls_registry[i].addr & (tls_registry[i].align - 1))
67 {
68 fputs (", WRONG ALIGNMENT", stdout);
69 res = 1;
70 }
71 if (i > 0
72 && (tls_registry[i - 1].addr + tls_registry[i - 1].size
73 > tls_registry[i].addr))
74 {
75 fputs (", ADDRESS OVERLAP", stdout);
76 res = 1;
77 }
78 puts ("");
79 if (tls_registry[i].name)
80 {
81 min_addr = MIN (tls_registry[i].addr, min_addr);
82 max_addr = MAX (tls_registry[i].addr + tls_registry[i].size,
83 max_addr);
84 }
85 }
86
87 if (cnt > 1)
88 {
89#if TLS_TCB_AT_TP
90 if (tls_registry[cnt - 1].name)
91 {
92 puts ("pthread_self () not larger than all TLS addresses");
93 res = 1;
94 }
95 else
96 max_addr = MAX (tls_registry[cnt - 1].addr, max_addr);
97#elif TLS_DTV_AT_TP
98 if (tls_registry[0].name)
99 {
100 puts ("pthread_self () not smaller than all TLS addresses");
101 res = 1;
102 }
103#else
104 abort ();
105#endif
106 printf ("Initial TLS used block size %zd\n",
107 (size_t) (max_addr - min_addr));
108 }
109 return res;
110}
111
112#define TEST_FUNCTION do_test ()
113
114#else
115
116#define TEST_FUNCTION 0
117
118#endif
119
120#include "../test-skeleton.c"
Note: See TracBrowser for help on using the repository browser.