10 #ifndef TEST_CLONE_FLAGS
11 #define TEST_CLONE_FLAGS 0
21 sival
.sival_int
= getpid ();
22 printf ("pid = %d\n", sival
.sival_int
);
23 if (sigqueue (getppid (), sig
, sival
) != 0)
32 int mypid
= getpid ();
38 if (sigprocmask (SIG_BLOCK
, &ss
, NULL
) != 0)
40 printf ("sigprocmask failed: %m\n");
45 extern int __clone2 (int (*__fn
) (void *__arg
), void *__child_stack_base
,
46 size_t __child_stack_size
, int __flags
,
48 char st
[256 * 1024] __attribute__ ((aligned
));
49 pid_t p
= __clone2 (f
, st
, sizeof (st
), TEST_CLONE_FLAGS
, 0);
51 char st
[128 * 1024] __attribute__ ((aligned
));
52 # if _STACK_GROWS_DOWN
53 pid_t p
= clone (f
, st
+ sizeof (st
), TEST_CLONE_FLAGS
, 0);
54 # elif _STACK_GROWS_UP
55 pid_t p
= clone (f
, st
, TEST_CLONE_FLAGS
, 0);
57 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
62 printf("clone failed: %m\n");
65 printf ("new thread: %d\n", (int) p
);
69 if (sigwaitinfo (&ss
, &si
) < 0)
71 printf("sigwaitinfo failed: %m\n");
75 while (si
.si_signo
!= sig
|| si
.si_code
!= SI_QUEUE
);
78 if (waitpid (p
, &e
, __WCLONE
) != p
)
80 puts ("waitpid failed");
87 printf ("died from signal %s\n", strsignal (WTERMSIG (e
)));
89 puts ("did not terminate correctly");
92 if (WEXITSTATUS (e
) != 0)
94 printf ("exit code %d\n", WEXITSTATUS (e
));
98 if (si
.si_int
!= (int) p
)
100 printf ("expected PID %d, got si_int %d\n", (int) p
, si
.si_int
);
107 printf ("expected PID %d, got si_pid %d\n", (int) p
, (int) si
.si_pid
);
112 if (getpid () != mypid
)
114 puts ("my PID changed");
121 #define TEST_FUNCTION do_test ()
122 #include "../test-skeleton.c"