/* Procedure executed by sideline threads. * XXX i#500: Cannot use libc routines (printf) in the child process. */ int run(void *arg) { int threadnum = (int)(long) arg; int i = 0; /* for CLONE_CHILD_CLEARTID for signaling parent. if we used raw * clone system call we could get kernel to do this for us. */ child[threadnum] = dynamorio_syscall(SYS_gettid, 0); dynamorio_syscall(SYS_set_tid_address, 1, &child[threadnum]); child_started[threadnum] = true; nolibc_print("Sideline thread started\n"); while (true) { /* do nothing for now */ i++; if (i % 25000000 == 0) break; } while (!child_exit[threadnum]) nolibc_nanosleep(&sleeptime); nolibc_print("Sideline thread finished, exiting whole group\n"); /* We deliberately bring down the whole group. Note that this is * the default on x64 on returning for some reason which seems * like a bug in _clone() (xref i#94). */ dynamorio_syscall(SYS_exit_group, 0); return 0; }
/* Procedure executed by sideline threads * XXX i#500: Cannot use libc routines (printf) in the child process. */ int run(void *arg) { int i = 0; nolibc_print("Sideline thread started\n"); while (true) { /* do nothing for now */ i++; if (i % 2500000 == 0) { nolibc_print("i = "); nolibc_print_int(i); nolibc_print("\n"); } if (i % 25000000 == 0) break; } while (!child_exit) nolibc_nanosleep(&sleeptime); nolibc_print("Sideline thread finished\n"); child_done = true; return 0; }
/* Procedure executed by sideline threads * XXX i#500: Cannot use libc routines (printf) in the child process. */ int run(void *arg) { int threadnum = (int)(long) arg; int i = 0; /* for CLONE_CHILD_CLEARTID for signaling parent. if we used raw * clone system call we could get kernel to do this for us. */ child[threadnum] = nolibc_syscall(SYS_gettid, 0); nolibc_syscall(SYS_set_tid_address, 1, &child[threadnum]); if (threadnum == 0) { /* first child creates rest of group */ int j; for (j = 1; j < NUM_THREADS; j++) { child[j] = create_thread(run, (void *)(long)j, &stack[j], true); if (child[j] < 0) nolibc_print("failed to create child thread\n"); } } child_started[threadnum] = true; nolibc_print("Sideline thread started\n"); while (true) { /* do nothing for now */ i++; if (i % 25000000 == 0) break; } while (!child_exit[threadnum]) nolibc_nanosleep(&sleeptime); nolibc_print("Sideline thread finished, exiting whole group\n"); child_done[threadnum] = true; /* We deliberately bring down the whole group. Note that this is * the default on x64 on returning for some reason which seems * like a bug in _clone() (xref i#94). */ nolibc_syscall(SYS_exit_group, 0); return 0; }