linux: Extend internal clone3 documentation
[glibc.git] / sysdeps / unix / sysv / linux / tst-misalign-clone-internal.c
blob8b94a74819bde8941b3b8bcf4e024ab3b437d373
1 /* Verify that __clone_internal properly aligns the child stack.
2 Copyright (C) 2021-2023 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 #include <sched.h>
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <sys/wait.h>
25 #include <unistd.h>
26 #include <libc-pointer-arith.h>
27 #include <tst-stack-align.h>
28 #include <clone_internal.h>
29 #include <support/xunistd.h>
30 #include <support/check.h>
32 static int
33 check_stack_alignment (void *arg)
35 puts ("in f");
37 return TEST_STACK_ALIGN () ? 1 : 0;
40 static int
41 do_test (void)
43 puts ("in do_test");
45 if (TEST_STACK_ALIGN ())
46 FAIL_EXIT1 ("stack isn't aligned\n");
48 #ifdef __ia64__
49 # define STACK_SIZE (256 * 1024)
50 #else
51 # define STACK_SIZE (128 * 1024)
52 #endif
53 char st[STACK_SIZE + 1];
54 /* NB: Align child stack to 1 byte. */
55 char *stack = PTR_ALIGN_UP (&st[0], 2) + 1;
56 struct clone_args clone_args =
58 .stack = (uintptr_t) stack,
59 .stack_size = STACK_SIZE,
61 pid_t p = __clone_internal (&clone_args, check_stack_alignment, 0);
63 /* Clone must not fail. */
64 TEST_VERIFY_EXIT (p != -1);
66 int e;
67 xwaitpid (p, &e, __WCLONE);
68 TEST_VERIFY (WIFEXITED (e));
69 TEST_COMPARE (WEXITSTATUS (e), 0);
71 return 0;
74 #include <support/test-driver.c>