i386: ulp update for SSE2 --disable-multi-arch configurations
[glibc.git] / sysdeps / unix / sysv / linux / tst-clone.c
blob2bc71249837fbb660c49cdf1c66914632845ff82
1 /* Test for proper error/errno handling in clone.
2 Copyright (C) 2006-2024 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 <https://www.gnu.org/licenses/>. */
19 /* BZ #2386, BZ #31402 */
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <sched.h>
25 #include <stackinfo.h> /* For _STACK_GROWS_{UP,DOWN}. */
26 #include <support/check.h>
28 volatile unsigned v = 0xdeadbeef;
30 int child_fn(void *arg)
32 puts ("FAIL: in child_fn(); should not be here");
33 exit(1);
36 static int
37 __attribute__((noinline))
38 do_clone (int (*fn)(void *), void *stack)
40 int result;
41 unsigned int a = v;
42 unsigned int b = v;
43 unsigned int c = v;
44 unsigned int d = v;
45 unsigned int e = v;
46 unsigned int f = v;
47 unsigned int g = v;
48 unsigned int h = v;
49 unsigned int i = v;
50 unsigned int j = v;
51 unsigned int k = v;
52 unsigned int l = v;
53 unsigned int m = v;
54 unsigned int n = v;
55 unsigned int o = v;
57 result = clone (fn, stack, 0, NULL);
59 /* Check that clone does not clobber call-saved registers. */
60 TEST_VERIFY (a == v && b == v && c == v && d == v && e == v && f == v
61 && g == v && h == v && i == v && j == v && k == v && l == v
62 && m == v && n == v && o == v);
64 return result;
67 static void
68 __attribute__((noinline))
69 do_test_single (int (*fn)(void *), void *stack)
71 printf ("%s (fn=%p, stack=%p)\n", __FUNCTION__, fn, stack);
72 errno = 0;
74 int result = do_clone (fn, stack);
76 TEST_COMPARE (errno, EINVAL);
77 TEST_COMPARE (result, -1);
80 static int
81 do_test (void)
83 char st[128 * 1024] __attribute__ ((aligned));
84 void *stack = NULL;
85 #if _STACK_GROWS_DOWN
86 stack = st + sizeof (st);
87 #elif _STACK_GROWS_UP
88 stack = st;
89 #else
90 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
91 #endif
93 do_test_single (child_fn, NULL);
94 do_test_single (NULL, stack);
95 do_test_single (NULL, NULL);
97 return 0;
100 #include <support/test-driver.c>