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