From 85f718f64d65390f385111e57cfa017abd12879d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 22 Mar 2021 18:21:01 +1300 Subject: sandbox: Support signal handling only when requested At present if sandbox crashes it prints a message and tries to exit. But with the recently introduced signal handler, it often seems to get stuck in a loop until the stack overflows: Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation ... The signal handler is only useful for a few tests, as I understand it. Make it optional. Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'arch/sandbox/cpu/start.c') diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 6bb94473f19..63b086dff80 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -390,6 +390,16 @@ static int sandbox_cmdline_cb_select_unittests(struct sandbox_state *state, } SANDBOX_CMDLINE_OPT_SHORT(select_unittests, 'k', 1, "Select unit tests to run"); +static int sandbox_cmdline_cb_signals(struct sandbox_state *state, + const char *arg) +{ + state->handle_signals = true; + + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(signals, 'S', 0, + "Handle signals (such as SIGSEGV) in sandbox"); + static void setup_ram_buf(struct sandbox_state *state) { /* Zero the RAM buffer if we didn't read it, to keep valgrind happy */ @@ -476,9 +486,11 @@ int main(int argc, char *argv[]) if (ret) goto err; - ret = os_setup_signal_handlers(); - if (ret) - goto err; + if (state->handle_signals) { + ret = os_setup_signal_handlers(); + if (ret) + goto err; + } #if CONFIG_VAL(SYS_MALLOC_F_LEN) gd->malloc_base = CONFIG_MALLOC_F_ADDR; -- cgit v1.2.3 From 3beba4ad34649e053b97c5a61cd7de55bc718866 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 11 May 2021 21:03:16 +0200 Subject: sandbox: ensure that state->ram_buf is in low memory Addresses in state->ram_buf must be in the low 4 GiB of the address space. Otherwise we cannot correctly fill SMBIOS tables. This shows up in warnings like: WARNING: SMBIOS table_address overflow 7f752735e020 Ensure that state->ram_buf is initialized by the first invocation of os_malloc(). Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/start.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'arch/sandbox/cpu/start.c') diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 63b086dff80..ad17e17c59e 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -453,6 +453,14 @@ int main(int argc, char *argv[]) text_base = os_find_text_base(); + /* + * This must be the first invocation of os_malloc() to have + * state->ram_buf in the low 4 GiB. + */ + ret = state_init(); + if (ret) + goto err; + /* * Copy argv[] so that we can pass the arguments in the original * sequence when resetting the sandbox. @@ -467,10 +475,6 @@ int main(int argc, char *argv[]) gd = &data; gd->arch.text_base = text_base; - ret = state_init(); - if (ret) - goto err; - state = state_get_current(); if (os_parse_args(state, argc, argv)) return 1; -- cgit v1.2.3 From 825a9a94e1a5795e545156ead664a85403cda0e1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 12 May 2021 18:38:51 +0200 Subject: sandbox: fix sandbox_reset() state_uninit() and dm_uninit() are mutually exclusive: state_uninit() prints via drivers. So it cannot be executed after dm_uninit(). dm_uninit() requires memory. So it cannot be executed after state_uninit() which releases all memory. Just skip dm_uninit() when resetting the sandbox. We will wake up in a new process and allocate new memory. So this cleanup is not required. We don't do it in sandbox_exit() either. This avoids a segmentation error when efi_reset_system_boottime() is invoked by a UEFI application. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/start.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'arch/sandbox/cpu/start.c') diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index ad17e17c59e..777db4e9522 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -436,9 +436,6 @@ void sandbox_reset(void) if (state_uninit()) os_exit(2); - if (dm_uninit()) - os_exit(2); - /* Restart U-Boot */ os_relaunch(os_argv); } -- cgit v1.2.3