]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/clone-new-thread-event.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / clone-new-thread-event.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2009-2013 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Test that GDB doesn't lose an event for a thread it didn't know
19 about, until an event is reported for it. */
20
21 #define _GNU_SOURCE
22 #include <sched.h>
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <signal.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <sys/syscall.h>
29
30 #include <features.h>
31 #ifdef __UCLIBC__
32 #if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_HAS_MMU__))
33 #define HAS_NOMMU
34 #endif
35 #endif
36
37 #define STACK_SIZE 0x1000
38
39 static int
40 tkill (int lwpid, int signo)
41 {
42 return syscall (__NR_tkill, lwpid, signo);
43 }
44
45 static pid_t
46 gettid (void)
47 {
48 return syscall (__NR_gettid);
49 }
50
51 static int
52 fn (void *unused)
53 {
54 tkill (gettid (), SIGUSR1);
55 return 0;
56 }
57
58 int
59 main (int argc, char **argv)
60 {
61 unsigned char *stack;
62 int new_pid;
63
64 stack = malloc (STACK_SIZE);
65 assert (stack != NULL);
66
67 new_pid = clone (fn, stack + STACK_SIZE, CLONE_FILES
68 #if defined(__UCLIBC__) && defined(HAS_NOMMU)
69 | CLONE_VM
70 #endif /* defined(__UCLIBC__) && defined(HAS_NOMMU) */
71 , NULL, NULL, NULL, NULL);
72 assert (new_pid > 0);
73
74 return 0;
75 }