Commit 9e16fb93 authored by Benjamin Berg's avatar Benjamin Berg Committed by Richard Weinberger

um: Make errors to stop ptraced child fatal during startup

For the detection code to check whether SYSEMU_SINGLESTEP works
correctly we needed some error cases while stopping to be non-fatal.
However, at this point stop_ptraced_child must always succeed, and we
can therefore simplify it slightly to exit immediately on error.
Signed-off-by: default avatarBenjamin Berg <benjamin@sipsolutions.net>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 57135337
...@@ -112,35 +112,20 @@ static int start_ptraced_child(void) ...@@ -112,35 +112,20 @@ static int start_ptraced_child(void)
return pid; return pid;
} }
/* When testing for SYSEMU support, if it is one of the broken versions, we static void stop_ptraced_child(int pid, int exitcode)
* must just avoid using sysemu, not panic, but only if SYSEMU features are
* broken.
* So only for SYSEMU features we test mustpanic, while normal host features
* must work anyway!
*/
static int stop_ptraced_child(int pid, int exitcode, int mustexit)
{ {
int status, n, ret = 0; int status, n;
if (ptrace(PTRACE_CONT, pid, 0, 0) < 0)
fatal_perror("stop_ptraced_child : ptrace failed");
if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) {
perror("stop_ptraced_child : ptrace failed");
return -1;
}
CATCH_EINTR(n = waitpid(pid, &status, 0)); CATCH_EINTR(n = waitpid(pid, &status, 0));
if (!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { if (!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
int exit_with = WEXITSTATUS(status); int exit_with = WEXITSTATUS(status);
if (exit_with == 2) fatal("stop_ptraced_child : child exited with exitcode %d, "
non_fatal("check_ptrace : child exited with status 2. " "while expecting %d; status 0x%x\n", exit_with,
"\nDisabling SYSEMU support.\n");
non_fatal("check_ptrace : child exited with exitcode %d, while "
"expecting %d; status 0x%x\n", exit_with,
exitcode, status); exitcode, status);
if (mustexit)
exit(1);
ret = -1;
} }
return ret;
} }
static void __init check_sysemu(void) static void __init check_sysemu(void)
...@@ -185,16 +170,14 @@ static void __init check_sysemu(void) ...@@ -185,16 +170,14 @@ static void __init check_sysemu(void)
goto fail; goto fail;
} }
} }
if (stop_ptraced_child(pid, 0, 0) < 0) stop_ptraced_child(pid, 0);
goto fail_stopped;
os_info("OK\n"); os_info("OK\n");
return; return;
fail: fail:
stop_ptraced_child(pid, 1, 0); stop_ptraced_child(pid, 1);
fail_stopped:
fatal("missing\n"); fatal("missing\n");
} }
...@@ -233,7 +216,7 @@ static void __init check_ptrace(void) ...@@ -233,7 +216,7 @@ static void __init check_ptrace(void)
break; break;
} }
} }
stop_ptraced_child(pid, 0, 1); stop_ptraced_child(pid, 0);
os_info("OK\n"); os_info("OK\n");
check_sysemu(); check_sysemu();
} }
...@@ -312,7 +295,7 @@ void __init os_early_checks(void) ...@@ -312,7 +295,7 @@ void __init os_early_checks(void)
pid = start_ptraced_child(); pid = start_ptraced_child();
if (init_pid_registers(pid)) if (init_pid_registers(pid))
fatal("Failed to initialize default registers"); fatal("Failed to initialize default registers");
stop_ptraced_child(pid, 1, 1); stop_ptraced_child(pid, 1);
} }
int __init parse_iomem(char *str, int *add) int __init parse_iomem(char *str, int *add)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment