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