void reset_cpu(ulong ignored) { if (state_uninit()) os_exit(2); if (dm_uninit()) os_exit(2); /* This is considered normal termination for now */ os_exit(0); }
void sandbox_exit(void) { /* Do this here while it still has an effect */ os_fd_restore(); if (state_uninit()) os_exit(2); if (dm_uninit()) os_exit(2); /* This is considered normal termination for now */ os_exit(0); }
int sandbox_early_getopt_check(void) { struct sandbox_state *state = state_get_current(); struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start; size_t num_options = __u_boot_sandbox_option_count(); size_t i; int max_arg_len, max_noarg_len; /* parse_err will be a string of the faulting option */ if (!state->parse_err) return 0; if (strcmp(state->parse_err, "help")) { printf("u-boot: error: failed while parsing option: %s\n" "\ttry running with --help for more information.\n", state->parse_err); os_exit(1); } printf( "u-boot, a command line test interface to U-Boot\n\n" "Usage: u-boot [options]\n" "Options:\n"); max_arg_len = 0; for (i = 0; i < num_options; ++i) max_arg_len = max((int)strlen(sb_opt[i]->flag), max_arg_len); max_noarg_len = max_arg_len + 7; for (i = 0; i < num_options; ++i) { struct sandbox_cmdline_option *opt = sb_opt[i]; /* first output the short flag if it has one */ if (opt->flag_short >= 0x100) printf(" "); else printf(" -%c, ", opt->flag_short); /* then the long flag */ if (opt->has_arg) printf("--%-*s <arg> ", max_arg_len, opt->flag); else printf("--%-*s", max_noarg_len, opt->flag); /* finally the help text */ printf(" %s\n", opt->help); } os_exit(0); }
void __start(void) { int argc; char *ro_args, *args, **argv; /* Clear BSS */ memset(edata, 0, end - edata); /* Define heap. */ setheap(end, (void *)(HIMEM - 0x1000)); ro_args = os_get_env(NULL, NULL); args = alloc(strlen(ro_args)+10); /* some spare extra */ strcpy(args, ro_args); argc = splitargs(args, 0, NULL); argv = alloc(argc * sizeof(*argv)); if (argv == NULL) panic("alloc of argv failed"); argc = splitargs(args, 1, argv); /* start real main() */ os_exit(NULL, main(argc, argv)); }
int sandbox_main_loop_init(void) { struct sandbox_state *state = state_get_current(); /* Execute command if required */ if (state->cmd) { run_command_list(state->cmd, -1, 0); os_exit(state->exit_type); } return 0; }
off_t os_lseek(int fd, off_t offset, int whence) { if (whence == OS_SEEK_SET) whence = SEEK_SET; else if (whence == OS_SEEK_CUR) whence = SEEK_CUR; else if (whence == OS_SEEK_END) whence = SEEK_END; else os_exit(1); return lseek(fd, offset, whence); }
int os_jump_to_image(const void *dest, int size) { struct sandbox_state *state = state_get_current(); char fname[30], mem_fname[30]; int fd, err; const char *extra_args[5]; char **argv = state->argv; #ifdef DEBUG int argc, i; #endif err = make_exec(fname, dest, size); if (err) return err; strcpy(mem_fname, "/tmp/u-boot.mem.XXXXXX"); fd = mkstemp(mem_fname); if (fd < 0) return -ENOENT; close(fd); err = os_write_ram_buf(mem_fname); if (err) return err; os_fd_restore(); extra_args[0] = "-j"; extra_args[1] = fname; extra_args[2] = "-m"; extra_args[3] = mem_fname; extra_args[4] = "--rm_memory"; err = add_args(&argv, extra_args, sizeof(extra_args) / sizeof(extra_args[0])); if (err) return err; #ifdef DEBUG for (i = 0; argv[i]; i++) printf("%d %s\n", i, argv[i]); #endif if (state_uninit()) os_exit(2); err = execv(fname, argv); free(argv); if (err) return err; return unlink(fname); }
int main(int argc, char *argv[]) { int status; OS_ASSERT(argc == 2); status = atoi(argv[1]); os_exit(status); /* Should never go there */ OS_ASSERT(false); /* Prevent a warning */ return 0; }
int sandbox_main_loop_init(void) { struct sandbox_state *state = state_get_current(); /* Execute command if required */ if (state->cmd || state->run_distro_boot) { int retval = 0; cli_init(); #ifdef CONFIG_CMDLINE if (state->cmd) retval = run_command_list(state->cmd, -1, 0); if (state->run_distro_boot) retval = cli_simple_run_command("run distro_bootcmd", 0); #endif if (!state->interactive) os_exit(retval); } return 0; }
static void unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc) { uword fatal = 0; /* These come in handy when looking at core files from optimized images */ last_signum = signum; last_faulting_address = (uword) si->si_addr; syslog_msg = format (syslog_msg, "received signal %U, PC %U", format_signal, signum, format_ucontext_pc, uc); if (signum == SIGSEGV) syslog_msg = format (syslog_msg, ", faulting address %p", si->si_addr); switch (signum) { /* these (caught) signals cause the application to exit */ case SIGTERM: /* * Ignore SIGTERM if it's sent before we're ready. */ if (unix_main.vlib_main && unix_main.vlib_main->main_loop_exit_set) { syslog (LOG_ERR | LOG_DAEMON, "received SIGTERM, exiting..."); unix_main.vlib_main->main_loop_exit_now = 1; } else syslog (LOG_ERR | LOG_DAEMON, "IGNORE early SIGTERM..."); break; /* fall through */ case SIGQUIT: case SIGINT: case SIGILL: case SIGBUS: case SIGSEGV: case SIGHUP: case SIGFPE: case SIGABRT: fatal = 1; break; /* by default, print a message and continue */ default: fatal = 0; break; } #ifdef CLIB_GCOV /* * Test framework sends SIGTERM, so we need to flush the * code coverage stats here. */ { void __gcov_flush (void); __gcov_flush (); } #endif /* Null terminate. */ vec_add1 (syslog_msg, 0); if (fatal) { syslog (LOG_ERR | LOG_DAEMON, "%s", syslog_msg); /* Address of callers: outer first, inner last. */ uword callers[15]; uword n_callers = clib_backtrace (callers, ARRAY_LEN (callers), 0); int i; for (i = 0; i < n_callers; i++) { vec_reset_length (syslog_msg); syslog_msg = format (syslog_msg, "#%-2d 0x%016lx %U%c", i, callers[i], format_clib_elf_symbol_with_address, callers[i], 0); syslog (LOG_ERR | LOG_DAEMON, "%s", syslog_msg); } /* have to remove SIGABRT to avoid recusive - os_exit calling abort() */ unsetup_signal_handlers (SIGABRT); os_exit (1); } else clib_warning ("%s", syslog_msg); }
void _rtt(void) { os_exit(NULL, 0); }