void program_main(const argdata_t *ad) { // Extract executable file descriptor and argument data from sequence. argdata_seq_iterator_t it; argdata_seq_iterate(ad, &it); const argdata_t *fdv, *argv; int fd; if (!argdata_seq_next(&it, &fdv) || argdata_get_fd(fdv, &fd) != 0 || !argdata_seq_next(&it, &argv)) _Exit(127); // Serialize argument data that needs to be passed to the executable. size_t buflen, fdslen; argdata_get_buffer_length(argv, &buflen, &fdslen); int *fds = malloc(fdslen * sizeof(fds[0]) + buflen); if (fds == NULL) _Exit(127); void *buf = &fds[fdslen]; fdslen = argdata_get_buffer(argv, buf, fds); // Register file descriptors. struct fd_table ft; fd_table_init(&ft); for (size_t i = 0; i < fdslen; ++i) if (!fd_table_insert_existing(&ft, i, fds[i])) _Exit(127); // Start emulation. emulate(fd, buf, buflen, &posix_syscalls); _Exit(127); }
/** * * Kernel entrypoint * @param multiboot pointer to multiboot header * @param magic magic value from multiboot bootloader * **/ void kmain(multiboot_t* multiboot, uint32_t magic) { /* Check magic */ if(magic != 0x2BADB002) { printf("Multiboot magic is incorrect.\n"); _Exit(EXIT_FAILURE); } /* Check if there are modules */ if(multiboot->mods_count == 0) { printf("No modules available. Can't boot.\n"); _Exit(EXIT_FAILURE); } /* Get module and info about it */ multiboot_module_t* module = (multiboot_module_t*) multiboot->mods_addr; uintptr_t start = module->mod_start; uintptr_t end = module->mod_end; /* Install heap after module */ heap_install(end); /* Run VM */ run_vm((void*) start); }
pid_t background_and_capture(char *cmd, int user_sh, FILE **out, FILE **err) { pid_t pid; int out_pipe[2]; int error_pipe[2]; if(pipe(out_pipe) != 0) { show_error_msg("File pipe error", "Error creating pipe"); return (pid_t)-1; } if(pipe(error_pipe) != 0) { show_error_msg("File pipe error", "Error creating pipe"); close(out_pipe[0]); close(out_pipe[1]); return (pid_t)-1; } if((pid = fork()) == -1) { close(out_pipe[0]); close(out_pipe[1]); close(error_pipe[0]); close(error_pipe[1]); return (pid_t)-1; } if(pid == 0) { char *sh; close(out_pipe[0]); close(error_pipe[0]); if(dup2(out_pipe[1], STDOUT_FILENO) == -1) { _Exit(EXIT_FAILURE); } if(dup2(error_pipe[1], STDERR_FILENO) == -1) { _Exit(EXIT_FAILURE); } sh = user_sh ? get_execv_path(cfg.shell) : "/bin/sh"; execvp(sh, make_execv_array(sh, cmd)); _Exit(127); } close(out_pipe[1]); close(error_pipe[1]); *out = fdopen(out_pipe[0], "r"); *err = fdopen(error_pipe[0], "r"); return pid; }
/** * @brief Execute command (fork, exec, wait) * * @param [in] argc number of cmd args * @param [in] argv cmd args * * @return Operation status * @retval 0 on success * @retval -1 on error */ static int execute_cmd(int argc, char **argv) { int i = 0; if (0 >= argc || NULL == argv) return -1; if (g_cfg.verbose) { printf("Trying to execute "); for (i = 0; i < argc; i++) printf("%s ", argv[i]); printf("\n"); } pid_t pid = fork(); if (-1 == pid) { fprintf(stderr, "%s,%s:%d Failed to execute %s !" " fork failed\n", __FILE__, __func__, __LINE__, argv[0]); return -1; } else if (0 < pid) { int status = EXIT_FAILURE; /* Wait for child */ waitpid(pid, &status, 0); if (EXIT_SUCCESS != status) return -1; } else { /* set cpu affinity */ if (0 != set_affinity(0)) { fprintf(stderr, "%s,%s:%d Failed to set core " "affinity!\n", __FILE__, __func__, __LINE__); _Exit(EXIT_FAILURE); } /* drop elevated root privileges */ if (0 == g_cfg.sudo_keep && 0 != sudo_drop()) _Exit(EXIT_FAILURE); errno = 0; /* execute command */ execvp(argv[0], argv); fprintf(stderr, "%s,%s:%d Failed to execute %s, %s (%i) !\n", __FILE__, __func__, __LINE__, argv[0], strerror(errno), errno); _Exit(EXIT_FAILURE); } return 0; }
void sh_quit(void) { sh_reset_termios(); set_winstruct(NULL, 1); tputs(tgetstr("ei", NULL), 0, tputchar); _Exit(0); }
void testApp::release( sem_t* mutex_) { if(sem_post(mutex) < 0) { perror("main thread: error on post semaphore"); _Exit(EXIT_FAILURE); } }
void exit( _In_ int Status) { __cxa_exithandlers(Status, 0, 1, 1); _Exit(Status); }
static void handler(int sig) { unw_context_t context; unw_getcontext(&context); unw_cursor_t cursor; unw_init_local(&cursor, &context); SkDebugf("\nSignal %d:\n", sig); while (unw_step(&cursor) > 0) { static const size_t kMax = 256; char mangled[kMax], demangled[kMax]; unw_word_t offset; unw_get_proc_name(&cursor, mangled, kMax, &offset); int ok; size_t len = kMax; abi::__cxa_demangle(mangled, demangled, &len, &ok); SkDebugf("%s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t)offset); } SkDebugf("\n"); // Exit NOW. Don't notify other threads, don't call anything registered with atexit(). _Exit(sig); }
void ERR04_1() { int a = 0; int b = 1; if (a == b) { _Exit(EXIT_FAILURE); } }
// Tries detecting a memory leak on the particular input that we have just // executed before calling this function. void Fuzzer::TryDetectingAMemoryLeak(uint8_t *Data, size_t Size) { if (!HasMoreMallocsThanFrees) return; // mallocs==frees, a leak is unlikely. if (!Options.DetectLeaks) return; if (!&__lsan_enable || !&__lsan_disable || !__lsan_do_recoverable_leak_check) return; // No lsan. // Run the target once again, but with lsan disabled so that if there is // a real leak we do not report it twice. __lsan_disable(); RunOneAndUpdateCorpus(Data, Size); __lsan_enable(); if (!HasMoreMallocsThanFrees) return; // a leak is unlikely. if (NumberOfLeakDetectionAttempts++ > 1000) { Options.DetectLeaks = false; Printf("INFO: libFuzzer disabled leak detection after every mutation.\n" " Most likely the target function accumulates allocated\n" " memory in a global state w/o actually leaking it.\n" " If LeakSanitizer is enabled in this process it will still\n" " run on the process shutdown.\n"); return; } // Now perform the actual lsan pass. This is expensive and we must ensure // we don't call it too often. if (__lsan_do_recoverable_leak_check()) { // Leak is found, report it. CurrentUnitData = Data; CurrentUnitSize = Size; DumpCurrentUnit("leak-"); PrintFinalStats(); _Exit(Options.ErrorExitCode); // not exit() to disable lsan further on. } }
void Server::wait( sem_t* mutex_) { if(sem_wait(mutex_) < 0){ perror("server: error on wait semaphore"); _Exit(EXIT_FAILURE); } }
void _entryPoint() { /****************************> Get Handles <****************************/ //Get a handle to coreinit.rpl unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); unsigned int nsyshid_handle; OSDynLoad_Acquire("nsyshid.rpl", &nsyshid_handle); /****************************> External Prototypes <****************************/ //OS functions void(*_Exit)(); int(*HIDAddClient)(HIDClient *p_client, HIDAttachCallback attach_callback); int(*HIDDelClient)(HIDClient *p_client); /****************************> Exports <****************************/ //OS functions OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); OSDynLoad_FindExport(nsyshid_handle, 0, "HIDAddClient", &HIDAddClient); OSDynLoad_FindExport(nsyshid_handle, 0, "HIDDelClient", &HIDDelClient); HIDClient fd; HIDAddClient(&fd, my_attach_cb); while(1) ; HIDDelClient(&fd); //WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE. int ii=0; for(ii;ii<2;ii++) { fillScreen(0,0,0,0); flipBuffers(); } _Exit(); }
static void MTA (int n) { if (n < 0) _Exit (81); Charlie (n - 1); }
/** Catches thrown signals. Performs necessary cleanup to ensure database is * in a consistent state. * @param signum the thrown signal */ static void soft_interrupt_handler(int signum) { #ifdef __MSYS__ struct termios term; #endif if(signum == SIGINT) { const char msg[] = "\nInterrupt signal received\n"; xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1); } else { const char msg[] = "\nHangup signal received\n"; xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1); } if(alpm_trans_interrupt(config->handle) == 0) { /* a transaction is being interrupted, don't exit pacman yet. */ return; } alpm_unlock(config->handle); #ifdef __MSYS__ /* restore input printing possibly disabled by core update */ if(tcgetattr(STDIN_FILENO, &term) == 0) { term.c_lflag |= ECHO; tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); } #endif /* output a newline to be sure we clear any line we may be on */ xwrite(STDOUT_FILENO, "\n", 1); _Exit(128 + signum); }
void Server::release( sem_t* mutex_) { if(sem_post(mutex) < 0) { perror("server: error on post semaphore"); _Exit(EXIT_FAILURE); } }
static void segv_handler(int signum) { const char msg[] = "\nerror: segmentation fault\n" "Please submit a full bug report with --debug if appropriate.\n"; xwrite(STDERR_FILENO, msg, sizeof(msg) - 1); _Exit(signum); }
_Noreturn void quick_exit(int code) { static int lock; while (a_swap(&lock, 1)) __syscall(SYS_pause); __funcs_on_quick_exit(); _Exit(code); }
static void trapILL(int sig RECARG) { static const char *emsg[] = { /* FPE_NOOP 0*/ "SIGILL", /* ILL_ILLOPC 1*/ "illegal opcode", /* ILL_ILLTRP 2*/ "illegal trap", /* ILL_PRVOPC 3*/ "privileged opcode", /* ILL_ILLOPN 4*/ "illegal operand", /* 5 */ "illegal addressing mode", /* 6 */ "privileged register", /* 7 */ "coprocessor error", /* 8 */ "internal stack error"}; CTX ctx = knh_getCurrentContext(); record_signal(ctx, sig RECDATA); if(ctx != NULL) { #if defined(K_USING_MINGW_) int si_code = 0; #else int si_code = (si->si_code < 9) ? si->si_code : 0; #endif /* defined(K_USING_MINGW_) */ WCTX(ctx)->signal = sig; THROW_Halt(ctx, NULL, emsg[si_code]); } _Exit(EX_SOFTWARE); }
void test_join_restricted_process() { pfq_t * x = pfq_open_group(Q_CLASS_DEFAULT, Q_POLICY_GROUP_RESTRICTED, 64, 1024, 1024); pfq_t * z = pfq_open_group(Q_CLASS_DEFAULT, Q_POLICY_GROUP_SHARED, 64, 1024, 1024); assert(x); assert(z); int p = fork(); if (p == 0) { pfq_t * y = pfq_open_group(Q_CLASS_DEFAULT, Q_POLICY_GROUP_UNDEFINED, 64, 1024, 1024); int gid = pfq_group_id(z); assert( pfq_join_group(y, gid, Q_CLASS_DEFAULT, Q_POLICY_GROUP_SHARED) == gid); assert( pfq_join_group(y, pfq_group_id(x), Q_CLASS_DEFAULT, Q_POLICY_GROUP_SHARED) == -1); pfq_close(y); _Exit(1); } wait(NULL); pfq_close(x); pfq_close(z); }
void string_invert(std::string IN){ std::cerr << "\tREVERSED: "; std::string OUT = std::string(""); int SIZE = IN.size(); int index = SIZE-1; pid_t pid; int status; // fork for ( int j = 0; j < SIZE; j++) { // create SIZE number of forks if ((pid = fork()) == 0) { // child, break out break; } else { // parent keep making children wait(NULL); index--; } } std::cerr << IN[index]; if(index == 0) std::cout << std::endl << std::endl; _Exit(0); }
void quick_exit(int exit_code) { std::lock_guard<std::mutex> lock(quick_exit_mutex); for (auto it = quick_exit_handlers.rbegin(); it != quick_exit_handlers.rend(); ++it) { (*it)(); } _Exit(exit_code); }
void printName(int id) { switch(id) { case TOM: printf("Tom"); break; case JERRY: printf("Jerry"); break; case MARK: printf("Mark"); break; case AVIL: printf("Avil"); break; case BILL: printf("Bill"); break; case CATE: printf("Cate"); break; case DAVID: printf("David"); break; case EVAN: printf("Evan"); break; default: _Exit(-1); } }
void _cplb_miss_without_replacement(void) { interrupt_info iinfo[1]; get_interrupt_info(ik_exception, iinfo); _ex_report_event(iinfo); _Exit(); /* NOTREACHED */ }
void quick_exit( int status ) { while ( _PDCLIB_quickexitptr < NUMBER_OF_SLOTS ) { _PDCLIB_quickexitstack[ _PDCLIB_quickexitptr++ ](); } _Exit( status ); }
void ExecutionTracker::thrilleAssert(thrID myself, void * ret_addr, bool cond) { if (!cond) { log->programAssertFail(myself, ret_addr); destructorHelper(); _Exit(UNRECOVERABLE_ERROR); } }
void Fuzzer::RssLimitCallback() { InOOMState = true; SignalToMainThread(); SleepSeconds(5); Printf("Signal to main thread failed (non-linux?). Exiting.\n"); _Exit(Options.ErrorExitCode); return; }
int main(){ atexit(fa);//只注册fa(),只有在exit()时才调用; printf("begin\n"); exit(0);//参数是退出码,可以用来记录退出情况; _Exit(0);//立即结束,不掉用fa; printf("end\n"); return 0; }
int main(void) { printf("Enter main()\n"); atexit(f1); atexit(f2); fflush(stdout); /* _Exit does not flush unwritten buffered data */ _Exit(0); }
intptr_t diag_run_agent(char **argv) { assert(argv); pid_t pid = fork(); if (pid < 0) { perror(argv[0]); _Exit(EXIT_FAILURE); } if (pid == 0) { if (execvp(argv[0], argv) == -1) { perror(argv[0]); _Exit(EXIT_FAILURE); } } return (intptr_t)pid; }
void exit( _In_ int Status) { StdioCleanup(); __CppFinit(); _Exit(Status); }