int NaClAppThreadSpawn(struct NaClApp *nap, uintptr_t usr_entry, uintptr_t usr_stack_ptr, uint32_t user_tls1, uint32_t user_tls2) { struct NaClAppThread *natp = NaClAppThreadMake(nap, usr_entry, usr_stack_ptr, user_tls1, user_tls2); if (natp == NULL) { return 0; } /* * We set host_thread_is_defined assuming, for now, that * NaClThreadCtor() will succeed. */ natp->host_thread_is_defined = 1; if (!NaClThreadCtor(&natp->host_thread, NaClAppThreadLauncher, (void *) natp, NACL_KERN_STACK_SIZE)) { /* * No other thread saw the NaClAppThread, so it is OK that * host_thread was not initialized despite host_thread_is_defined * being set. */ natp->host_thread_is_defined = 0; NaClAppThreadDelete(natp); return 0; } return 1; }
int main(int argc, char **argv) { struct NaClApp app; struct NaClApp *nap = &app; struct NaClSyscallTableEntry syscall_table[NACL_MAX_SYSCALLS] = {{0}}; int index; int use_separate_thread = 0; for (index = 0; index < NACL_MAX_SYSCALLS; index++) { syscall_table[index].handler = NotImplementedDecoder; } syscall_table[TEST_SYSCALL_INVOKE].handler = MySyscallInvoke; syscall_table[TEST_SYSCALL_EXIT].handler = MySyscallExit; NaClAllModulesInit(); CHECK(NaClAppWithSyscallTableCtor(&app, syscall_table)); CHECK(NaClAppLoadFileFromFilename(&app, argv[1]) == LOAD_OK); struct NaClAppThread *natp; uintptr_t stack_ptr = NaClGetInitialStackTop(nap); /* Ensure the stack pointer is suitably aligned. */ stack_ptr &= ~NACL_STACK_ALIGN_MASK; stack_ptr -= NACL_STACK_PAD_BELOW_ALIGN; /* TODO(mseaborn): Make this interface more straightforward to use. */ stack_ptr = NaClSysToUserStackAddr(nap, NaClUserToSys(nap, stack_ptr)); natp = NaClAppThreadMake(nap, nap->initial_entry_pt, stack_ptr, 0, 0); CHECK(natp != NULL); NaClAppThreadLauncher(natp); printf("game over\n"); return 1; }