|
Packit |
6c4009 |
/* Check if clone (CLONE_THREAD) does not call exit_group (BZ #21512)
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <sched.h>
|
|
Packit |
6c4009 |
#include <signal.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <sys/syscall.h>
|
|
Packit |
6c4009 |
#include <sys/wait.h>
|
|
Packit |
6c4009 |
#include <sys/types.h>
|
|
Packit |
6c4009 |
#include <linux/futex.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stackinfo.h> /* For _STACK_GROWS_{UP,DOWN}. */
|
|
Packit |
6c4009 |
#include <support/check.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Test if clone call with CLONE_THREAD does not call exit_group. The 'f'
|
|
Packit |
6c4009 |
function returns '1', which will be used by clone thread to call the
|
|
Packit |
6c4009 |
'exit' syscall directly. If _exit is used instead, exit_group will be
|
|
Packit |
6c4009 |
used and thus the thread group will finish with return value of '1'
|
|
Packit |
6c4009 |
(where '2' from main thread is expected. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
f (void *a)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Futex wait for TID argument, similar to pthread_join internal
|
|
Packit |
6c4009 |
implementation. */
|
|
Packit Service |
93dc7a |
#define wait_tid(tid) \
|
|
Packit Service |
93dc7a |
do { \
|
|
Packit Service |
93dc7a |
__typeof (tid) __tid; \
|
|
Packit Service |
93dc7a |
while ((__tid = (tid)) != 0) \
|
|
Packit Service |
93dc7a |
futex_wait (&(tid), __tid); \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static inline int
|
|
Packit |
6c4009 |
futex_wait (int *futexp, int val)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char st[1024] __attribute__ ((aligned));
|
|
Packit |
6c4009 |
int clone_flags = CLONE_THREAD;
|
|
Packit |
6c4009 |
/* Minimum required flags to used along with CLONE_THREAD. */
|
|
Packit |
6c4009 |
clone_flags |= CLONE_VM | CLONE_SIGHAND;
|
|
Packit |
6c4009 |
/* We will used ctid to call on futex to wait for thread exit. */
|
|
Packit |
6c4009 |
clone_flags |= CLONE_CHILD_CLEARTID;
|
|
Packit Service |
93dc7a |
pid_t ctid, tid;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __ia64__
|
|
Packit |
6c4009 |
extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
|
|
Packit |
6c4009 |
size_t __child_stack_size, int __flags,
|
|
Packit |
6c4009 |
void *__arg, ...);
|
|
Packit |
6c4009 |
tid = __clone2 (f, st, sizeof (st), clone_flags, NULL, /* ptid */ NULL,
|
|
Packit |
6c4009 |
/* tls */ NULL, &ctid);
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
#if _STACK_GROWS_DOWN
|
|
Packit |
6c4009 |
tid = clone (f, st + sizeof (st), clone_flags, NULL, /* ptid */ NULL,
|
|
Packit |
6c4009 |
/* tls */ NULL, &ctid);
|
|
Packit |
6c4009 |
#elif _STACK_GROWS_UP
|
|
Packit |
6c4009 |
tid = clone (f, st, clone_flags, NULL, /* ptid */ NULL, /* tls */ NULL,
|
|
Packit |
6c4009 |
&ctid);
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
#error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
if (tid == -1)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("clone failed: %m");
|
|
Packit |
6c4009 |
|
|
Packit Service |
93dc7a |
ctid = tid;
|
|
Packit Service |
93dc7a |
wait_tid (ctid);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return 2;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define EXPECTED_STATUS 2
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|