Skip to content

Commit 5713533

Browse files
benzearichardweinberger
authored andcommitted
um: Drop NULL check from start_userspace
start_userspace is only called from exactly one location, and the passed pointer for the userspace process stack cannot be NULL. Remove the check, without changing the control flow. Signed-off-by: Benjamin Berg <benjamin@sipsolutions.net> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent a557198 commit 5713533

1 file changed

Lines changed: 24 additions & 29 deletions

File tree

arch/um/os-Linux/skas/process.c

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extern char __syscall_stub_start[];
189189

190190
/**
191191
* userspace_tramp() - userspace trampoline
192-
* @stack: pointer to the new userspace stack page, can be NULL, if? FIXME:
192+
* @stack: pointer to the new userspace stack page
193193
*
194194
* The userspace trampoline is used to setup a new userspace process in start_userspace() after it was clone()'ed.
195195
* This function will run on a temporary stack page.
@@ -204,9 +204,13 @@ extern char __syscall_stub_start[];
204204
*/
205205
static int userspace_tramp(void *stack)
206206
{
207+
struct sigaction sa;
207208
void *addr;
208209
int fd;
209210
unsigned long long offset;
211+
unsigned long segv_handler = STUB_CODE +
212+
(unsigned long) stub_segv_handler -
213+
(unsigned long) __syscall_stub_start;
210214

211215
ptrace(PTRACE_TRACEME, 0, 0, 0);
212216

@@ -222,34 +226,25 @@ static int userspace_tramp(void *stack)
222226
exit(1);
223227
}
224228

225-
if (stack != NULL) {
226-
fd = phys_mapping(uml_to_phys(stack), &offset);
227-
addr = mmap((void *) STUB_DATA,
228-
STUB_DATA_PAGES * UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
229-
MAP_FIXED | MAP_SHARED, fd, offset);
230-
if (addr == MAP_FAILED) {
231-
printk(UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n",
232-
STUB_DATA, errno);
233-
exit(1);
234-
}
229+
fd = phys_mapping(uml_to_phys(stack), &offset);
230+
addr = mmap((void *) STUB_DATA,
231+
STUB_DATA_PAGES * UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
232+
MAP_FIXED | MAP_SHARED, fd, offset);
233+
if (addr == MAP_FAILED) {
234+
printk(UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n",
235+
STUB_DATA, errno);
236+
exit(1);
235237
}
236-
if (stack != NULL) {
237-
struct sigaction sa;
238-
239-
unsigned long v = STUB_CODE +
240-
(unsigned long) stub_segv_handler -
241-
(unsigned long) __syscall_stub_start;
242-
243-
set_sigstack((void *) STUB_DATA, STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);
244-
sigemptyset(&sa.sa_mask);
245-
sa.sa_flags = SA_ONSTACK | SA_NODEFER | SA_SIGINFO;
246-
sa.sa_sigaction = (void *) v;
247-
sa.sa_restorer = NULL;
248-
if (sigaction(SIGSEGV, &sa, NULL) < 0) {
249-
printk(UM_KERN_ERR "%s - setting SIGSEGV handler failed - errno = %d\n",
250-
__func__, errno);
251-
exit(1);
252-
}
238+
239+
set_sigstack((void *) STUB_DATA, STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);
240+
sigemptyset(&sa.sa_mask);
241+
sa.sa_flags = SA_ONSTACK | SA_NODEFER | SA_SIGINFO;
242+
sa.sa_sigaction = (void *) segv_handler;
243+
sa.sa_restorer = NULL;
244+
if (sigaction(SIGSEGV, &sa, NULL) < 0) {
245+
printk(UM_KERN_ERR "%s - setting SIGSEGV handler failed - errno = %d\n",
246+
__func__, errno);
247+
exit(1);
253248
}
254249

255250
kill(os_getpid(), SIGSTOP);
@@ -261,7 +256,7 @@ int kill_userspace_mm[NR_CPUS];
261256

262257
/**
263258
* start_userspace() - prepare a new userspace process
264-
* @stub_stack: pointer to the stub stack. Can be NULL, if? FIXME:
259+
* @stub_stack: pointer to the stub stack.
265260
*
266261
* Setups a new temporary stack page that is used while userspace_tramp() runs
267262
* Clones the kernel process into a new userspace process, with FDs only.

0 commit comments

Comments
 (0)