| [2036] | 1 | /* Copyright (C) 2003 Free Software Foundation, Inc.
|
|---|
| 2 | This file is part of the GNU C Library.
|
|---|
| 3 | Contributed by Jakub Jelinek <[email protected]>, 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 <sys/param.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "tst-tls1.h"
|
|---|
| 28 |
|
|---|
| 29 | #ifdef TLS_REGISTER
|
|---|
| 30 |
|
|---|
| 31 | struct tls_obj tls_registry[64];
|
|---|
| 32 |
|
|---|
| 33 | static int
|
|---|
| 34 | tls_addr_cmp (const void *a, const void *b)
|
|---|
| 35 | {
|
|---|
| 36 | if (((struct tls_obj *)a)->addr < ((struct tls_obj *)b)->addr)
|
|---|
| 37 | return -1;
|
|---|
| 38 | if (((struct tls_obj *)a)->addr > ((struct tls_obj *)b)->addr)
|
|---|
| 39 | return 1;
|
|---|
| 40 | return 0;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | static int
|
|---|
| 44 | do_test (void)
|
|---|
| 45 | {
|
|---|
| 46 | size_t cnt, i;
|
|---|
| 47 | int res = 0;
|
|---|
| 48 | uintptr_t min_addr = ~(uintptr_t) 0, max_addr = 0;
|
|---|
| 49 |
|
|---|
| 50 | for (cnt = 0; tls_registry[cnt].name; ++cnt);
|
|---|
| 51 |
|
|---|
| 52 | qsort (tls_registry, cnt, sizeof (struct tls_obj), tls_addr_cmp);
|
|---|
| 53 |
|
|---|
| 54 | for (i = 0; i < cnt; ++i)
|
|---|
| 55 | {
|
|---|
| 56 | printf ("%s = %p, size %zd, align %zd",
|
|---|
| 57 | tls_registry[i].name, (void *) tls_registry[i].addr,
|
|---|
| 58 | tls_registry[i].size, tls_registry[i].align);
|
|---|
| 59 | if (tls_registry[i].addr & (tls_registry[i].align - 1))
|
|---|
| 60 | {
|
|---|
| 61 | fputs (", WRONG ALIGNMENT", stdout);
|
|---|
| 62 | res = 1;
|
|---|
| 63 | }
|
|---|
| 64 | if (i > 0
|
|---|
| 65 | && (tls_registry[i - 1].addr + tls_registry[i - 1].size
|
|---|
| 66 | > tls_registry[i].addr))
|
|---|
| 67 | {
|
|---|
| 68 | fputs (", ADDRESS OVERLAP", stdout);
|
|---|
| 69 | res = 1;
|
|---|
| 70 | }
|
|---|
| 71 | puts ("");
|
|---|
| 72 | min_addr = MIN (tls_registry[i].addr, min_addr);
|
|---|
| 73 | max_addr = MAX (tls_registry[i].addr + tls_registry[i].size,
|
|---|
| 74 | max_addr);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | if (cnt > 1)
|
|---|
| 78 | printf ("Initial TLS used block size %zd\n",
|
|---|
| 79 | (size_t) (max_addr - min_addr));
|
|---|
| 80 | return res;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | #define TEST_FUNCTION do_test ()
|
|---|
| 84 |
|
|---|
| 85 | #else
|
|---|
| 86 |
|
|---|
| 87 | #define TEST_FUNCTION 0
|
|---|
| 88 |
|
|---|
| 89 | #endif
|
|---|
| 90 |
|
|---|
| 91 | #include "../test-skeleton.c"
|
|---|