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 */
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");
37 __attribute__((noinline
))
38 do_clone (int (*fn
)(void *), void *stack
)
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
);
68 __attribute__((noinline
))
69 do_test_single (int (*fn
)(void *), void *stack
)
71 printf ("%s (fn=%p, stack=%p)\n", __FUNCTION__
, fn
, stack
);
74 int result
= do_clone (fn
, stack
);
76 TEST_COMPARE (errno
, EINVAL
);
77 TEST_COMPARE (result
, -1);
83 char st
[128 * 1024] __attribute__ ((aligned
));
86 stack
= st
+ sizeof (st
);
90 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
93 do_test_single (child_fn
, NULL
);
94 do_test_single (NULL
, stack
);
95 do_test_single (NULL
, NULL
);
100 #include <support/test-driver.c>