#define _XOPEN_SOURCE 600 #define _BSD_SOURCE #include #include #include #include #include #include #include #include #include "valgrind.h" #define STACK_SIZE 8192 static int thread_main(void *arg) { char buffer[1024]; memset( buffer, 1, sizeof( buffer ) ); return memchr( buffer, 1, sizeof( buffer ) ) == NULL; } int main(int argc, char **argv) { void *stack; int stackid; pid_t pid; if ( ( stack = mmap( NULL, STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 ) ) == MAP_FAILED ) { perror( "mmap" ); exit( 1 ); } stackid = VALGRIND_STACK_REGISTER( stack, stack + STACK_SIZE ); if ( ( pid = clone( thread_main, stack + STACK_SIZE, CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|SIGCHLD, NULL ) ) == -1 ) { perror( "clone" ); exit( 1 ); } sleep( 1 ); exit( 0 ); }