Cast to __intptr_t before casting pointer to int64
[glibc.git] / nptl / tst-oddstacklimit.c
blobbe25948e521013304947a884e4ac2ec290815853
1 /* Test NPTL with stack limit that is not a multiple of the page size.
2 Copyright (C) 2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <errno.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <sys/resource.h>
23 #include <sys/wait.h>
25 /* This sets the stack resource limit to 1023kb, which is not a multiple
26 of the page size since every architecture's page size is > 1k. */
27 #ifndef ODD_STACK_LIMIT
28 # define ODD_STACK_LIMIT (1023 * 1024)
29 #endif
31 static const char *command;
33 static int
34 do_test (void)
36 int ret;
37 struct rlimit rlim;
39 ret = getrlimit (RLIMIT_STACK, &rlim);
40 if (ret != 0)
42 printf ("getrlimit failed: %s\n", strerror (errno));
43 return 1;
45 rlim.rlim_cur = ODD_STACK_LIMIT;
46 ret = setrlimit (RLIMIT_STACK, &rlim);
47 if (ret != 0)
49 printf ("setrlimit failed: %s\n", strerror (errno));
50 return 1;
52 ret = system (command);
53 if (ret == -1)
55 printf ("system failed: %s\n", strerror (errno));
56 return 1;
58 if (WIFEXITED (ret))
59 return WEXITSTATUS (ret);
60 else
61 return 1;
64 #define OPT_COMMAND 10000
65 #define CMDLINE_OPTIONS \
66 { "command", required_argument, NULL, OPT_COMMAND },
67 #define CMDLINE_PROCESS \
68 case OPT_COMMAND: \
69 command = optarg; \
70 break;
71 #define TEST_FUNCTION do_test ()
72 #include "../test-skeleton.c"