Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 2002-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <limits.h>
20#include <pthread.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/param.h>
24#include <unistd.h>
25
26
27static void *stack;
28static size_t size;
29
30
31static void *
32tf (void *a)
33{
34 int result = 0;
35
36 puts ("child start");
37
38 pthread_attr_t attr;
39 if (pthread_getattr_np (pthread_self (), &attr) != 0)
40 {
41 puts ("getattr_np failed");
42 exit (1);
43 }
44
45 size_t test_size;
46 void *test_stack;
47 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
48 {
49 puts ("attr_getstack failed");
50 exit (1);
51 }
52
53 if (test_size != size)
54 {
55 printf ("child: reported size differs: is %zu, expected %zu\n",
56 test_size, size);
57 result = 1;
58 }
59
60 if (test_stack != stack)
61 {
62 printf ("child: reported stack address differs: is %p, expected %p\n",
63 test_stack, stack);
64 result = 1;
65 }
66
67 puts ("child OK");
68
69 return result ? (void *) 1l : NULL;
70}
71
72
73int
74do_test (void)
75{
76 int result = 0;
77
78 size = MAX (4 * getpagesize (), PTHREAD_STACK_MIN);
79 if (posix_memalign (&stack, getpagesize (), size) != 0)
80 {
81 puts ("out of memory while allocating the stack memory");
82 exit (1);
83 }
84
85 pthread_attr_t attr;
86 if (pthread_attr_init (&attr) != 0)
87 {
88 puts ("attr_init failed");
89 exit (1);
90 }
91
92 puts ("attr_setstack");
93 if (pthread_attr_setstack (&attr, stack, size) != 0)
94 {
95 puts ("attr_setstack failed");
96 exit (1);
97 }
98
99 size_t test_size;
100 void *test_stack;
101 puts ("attr_getstack");
102 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
103 {
104 puts ("attr_getstack failed");
105 exit (1);
106 }
107
108 if (test_size != size)
109 {
110 printf ("reported size differs: is %zu, expected %zu\n",
111 test_size, size);
112 result = 1;
113 }
114
115 if (test_stack != stack)
116 {
117 printf ("reported stack address differs: is %p, expected %p\n",
118 test_stack, stack);
119 result = 1;
120 }
121
122 puts ("create");
123
124 pthread_t th;
125 if (pthread_create (&th, &attr, tf, NULL) != 0)
126 {
127 puts ("failed to create thread");
128 exit (1);
129 }
130
131 void *status;
132 if (pthread_join (th, &status) != 0)
133 {
134 puts ("join failed");
135 exit (1);
136 }
137
138 result |= status != NULL;
139
140 return result;
141}
142
143
144#define TEST_FUNCTION do_test ()
145#include "../test-skeleton.c"
146

Warning: That file was not part of the compilation database. It may have many parsing errors.