Skip to content

Commit 9e16fb9

Browse files
benzearichardweinberger
authored andcommitted
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: Benjamin Berg <benjamin@sipsolutions.net> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 5713533 commit 9e16fb9

1 file changed

Lines changed: 12 additions & 29 deletions

File tree

arch/um/os-Linux/start_up.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,35 +112,20 @@ static int start_ptraced_child(void)
112112
return pid;
113113
}
114114

115-
/* When testing for SYSEMU support, if it is one of the broken versions, we
116-
* must just avoid using sysemu, not panic, but only if SYSEMU features are
117-
* broken.
118-
* So only for SYSEMU features we test mustpanic, while normal host features
119-
* must work anyway!
120-
*/
121-
static int stop_ptraced_child(int pid, int exitcode, int mustexit)
115+
static void stop_ptraced_child(int pid, int exitcode)
122116
{
123-
int status, n, ret = 0;
117+
int status, n;
118+
119+
if (ptrace(PTRACE_CONT, pid, 0, 0) < 0)
120+
fatal_perror("stop_ptraced_child : ptrace failed");
124121

125-
if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) {
126-
perror("stop_ptraced_child : ptrace failed");
127-
return -1;
128-
}
129122
CATCH_EINTR(n = waitpid(pid, &status, 0));
130123
if (!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
131124
int exit_with = WEXITSTATUS(status);
132-
if (exit_with == 2)
133-
non_fatal("check_ptrace : child exited with status 2. "
134-
"\nDisabling SYSEMU support.\n");
135-
non_fatal("check_ptrace : child exited with exitcode %d, while "
136-
"expecting %d; status 0x%x\n", exit_with,
137-
exitcode, status);
138-
if (mustexit)
139-
exit(1);
140-
ret = -1;
125+
fatal("stop_ptraced_child : child exited with exitcode %d, "
126+
"while expecting %d; status 0x%x\n", exit_with,
127+
exitcode, status);
141128
}
142-
143-
return ret;
144129
}
145130

146131
static void __init check_sysemu(void)
@@ -185,16 +170,14 @@ static void __init check_sysemu(void)
185170
goto fail;
186171
}
187172
}
188-
if (stop_ptraced_child(pid, 0, 0) < 0)
189-
goto fail_stopped;
173+
stop_ptraced_child(pid, 0);
190174

191175
os_info("OK\n");
192176

193177
return;
194178

195179
fail:
196-
stop_ptraced_child(pid, 1, 0);
197-
fail_stopped:
180+
stop_ptraced_child(pid, 1);
198181
fatal("missing\n");
199182
}
200183

@@ -233,7 +216,7 @@ static void __init check_ptrace(void)
233216
break;
234217
}
235218
}
236-
stop_ptraced_child(pid, 0, 1);
219+
stop_ptraced_child(pid, 0);
237220
os_info("OK\n");
238221
check_sysemu();
239222
}
@@ -312,7 +295,7 @@ void __init os_early_checks(void)
312295
pid = start_ptraced_child();
313296
if (init_pid_registers(pid))
314297
fatal("Failed to initialize default registers");
315-
stop_ptraced_child(pid, 1, 1);
298+
stop_ptraced_child(pid, 1);
316299
}
317300

318301
int __init parse_iomem(char *str, int *add)

0 commit comments

Comments
 (0)