• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define _XOPEN_SOURCE 600
2 
3 /* Legacy feature macro.  */
4 #define _BSD_SOURCE
5 /* New feature macro, always define to squash warning about _BSD_SOURCE
6    with glibc 2.20+.  */
7 #define _DEFAULT_SOURCE 1
8 
9 #define _GNU_SOURCE
10 
11 #include <stdio.h>
12 
13 #include <sched.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "tests/sys_mman.h"
17 #include <sys/syscall.h>
18 #include <sys/wait.h>
19 #include <unistd.h>
20 
21 #include "valgrind.h"
22 
23 #define STACK_SIZE 8192
24 
25 #ifndef CLONE_THREAD
26 #define CLONE_THREAD	0x00010000	/* Same thread group? */
27 #endif
28 
thread_main(void * arg)29 static int thread_main(void *arg)
30 {
31    char buffer[1024];
32 
33    memset( buffer, 1, sizeof( buffer ) );
34 
35    sleep(2); /* ppc64-linux hack */
36    return memchr( buffer, 1, sizeof( buffer ) ) == NULL;
37 }
38 
main(int argc,char ** argv)39 int main(int argc, char **argv)
40 {
41    void *stack;
42    int stackid __attribute__((unused));
43    pid_t pid;
44 
45    /* "2*" is a ppc64-linux hack */
46    if ( ( stack = mmap( NULL, 2* STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 ) ) == MAP_FAILED )
47    {
48       perror( "mmap" );
49       exit( 1 );
50    }
51 
52    stackid = VALGRIND_STACK_REGISTER( stack, stack + STACK_SIZE );
53 
54    if ( ( pid = clone( thread_main, stack + STACK_SIZE, CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|SIGCHLD, NULL ) ) == -1 )
55    {
56       perror( "clone" );
57       exit( 1 );
58    }
59 
60    sleep( 1 );
61 
62    exit( 0 );
63 }
64