Skip to content

Commit

Permalink
x86, 64-bit: Use user_mode() to determine new stack pointer in copy_t…
Browse files Browse the repository at this point in the history
…hread()

Use user_mode() instead of a magic value for sp to determine when returning
to kernel mode.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
LKML-Reference: <1260380084-3707-3-git-send-email-brgerst@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
  • Loading branch information
Brian Gerst authored and H. Peter Anvin committed Dec 10, 2009
1 parent 3bd95df commit fa4b8f8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions arch/x86/kernel/process_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
regs.flags = X86_EFLAGS_IF;

/* Ok, create the new process.. */
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, ~0UL, &regs, 0, NULL, NULL);
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
EXPORT_SYMBOL(kernel_thread);

Expand Down Expand Up @@ -312,8 +312,9 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
*childregs = *regs;

childregs->ax = 0;
childregs->sp = sp;
if (sp == ~0UL)
if (user_mode(regs))
childregs->sp = sp;
else
childregs->sp = (unsigned long)childregs;

p->thread.sp = (unsigned long) childregs;
Expand Down

0 comments on commit fa4b8f8

Please sign in to comment.