Home | History | Annotate | Download | only in output_tests
      1 #ifdef __linux__
      2 #include <stdio.h>
      3 #include <sched.h>
      4 #include <sys/syscall.h>
      5 #include <sys/types.h>
      6 #include <sys/wait.h>
      7 #include <unistd.h>
      8 
      9 int Child(void *arg) {
     10   char x[32] = {0};  // Stack gets poisoned.
     11   printf("Child:  %p\n", x);
     12   _exit(1);  // NoReturn, stack will remain unpoisoned unless we do something.
     13 }
     14 
     15 int main(int argc, char **argv) {
     16   const int kStackSize = 1 << 20;
     17   char child_stack[kStackSize + 1];
     18   char *sp = child_stack + kStackSize;  // Stack grows down.
     19   printf("Parent: %p\n", sp);
     20   pid_t clone_pid = clone(Child, sp, CLONE_FILES | CLONE_VM, NULL, 0, 0, 0);
     21   waitpid(clone_pid, NULL, 0);
     22   for (int i = 0; i < kStackSize; i++)
     23     child_stack[i] = i;
     24   int ret = child_stack[argc - 1];
     25   printf("PASSED\n");
     26   return ret;
     27 }
     28 #else  // not __linux__
     29 #include <stdio.h>
     30 int main() {
     31   printf("PASSED\n");
     32   // Check-Common: PASSED
     33 }
     34 #endif
     35