Skip to content

Commit

Permalink
test w/ sigframe
Browse files Browse the repository at this point in the history
  • Loading branch information
thehajime committed Dec 12, 2024
1 parent 0344dad commit ae5dab8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions arch/x86/um/nommu/entry_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ ENTRY(__kernel_vsyscall)
POP_REGS

addq $8, %rsp /* skip orig_ax */
addq $8, %rsp /* skip ip */
popq %rcx /* pt_regs->ip */
addq $8, %rsp /* skip cs */
addq $8, %rsp /* skip flags */
popq %rsp

ret
//popq %rcx
jmp %rcx

END(__kernel_vsyscall)

// void userspace(struct uml_pt_regs *regs)
ENTRY(userspace)
/* fixup stack for vfork syscall*/
call arch_fixup_stack
//call arch_fixup_stack

/* align the stack for x86_64 ABI */
and $-0x10, %rsp
Expand Down
9 changes: 5 additions & 4 deletions arch/x86/um/nommu/os-Linux/mcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

static void userspace_sigreturn(void)
{
__asm__ volatile("movq $15, %rax");
__asm__ volatile("call *%0" : : "r"(__kernel_vsyscall) :);
/* XXX: dummy syscall */
//__asm__ volatile("movq $15, %rax");
__asm__ volatile("call *%0" : : "r"(__kernel_vsyscall), "a"(39) :);
}

void mc_set_regs_ip_relay(mcontext_t *mc)
Expand All @@ -19,8 +20,8 @@ void mc_set_regs_ip_relay(mcontext_t *mc)

void mc_set_sigsys_hook(mcontext_t *mc)
{
mc->gregs[REG_RSP] -= sizeof(unsigned long);
*((unsigned long *) (mc->gregs[REG_RSP])) = mc->gregs[REG_RIP];
//mc->gregs[REG_RSP] -= sizeof(unsigned long);
//*((unsigned long *) (mc->gregs[REG_RSP])) = mc->gregs[REG_RIP];
mc->gregs[REG_RCX] = mc->gregs[REG_RIP];
mc->gregs[REG_RIP] = (unsigned long) __kernel_vsyscall;
}
7 changes: 7 additions & 0 deletions arch/x86/um/nommu/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

#include <sysdep/signal.h>

/* XXX: this makes pthread_cancel, cancel_handler loops endlessly....
if this skips, cancel works
*/
/* XXX: without this doesn't work with SIGSEGV */
int arch_setup_signal_stack_si(struct rt_sigframe __user **frame,
struct ksignal *ksig)
{
int err = 0;
return 0;
if (ksig->sig != SIGSEGV)
return 0;

/*
* we need to push handler address at top of stack, as
Expand Down
7 changes: 2 additions & 5 deletions arch/x86/um/nommu/zpoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,8 @@ static int __init setup_zpoline_trampoline(void)
* pretending to be syscall instruction by putting return
* address in %rcx.
*/
/* 48 8b 0c 24 mov (%rsp),%rcx */
__zpoline_start[ptr++] = 0x48;
__zpoline_start[ptr++] = 0x8b;
__zpoline_start[ptr++] = 0x0c;
__zpoline_start[ptr++] = 0x24;
/* 59 pop %rcx */
__zpoline_start[ptr++] = 0x59;

/* 41 ff e3 jmp *%r11 */
__zpoline_start[ptr++] = 0x41;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/um/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ int setup_signal_stack_si(unsigned long stack_top, struct ksignal *ksig,
return err;

/* fixup rt_sigframe for nommu */
err |= arch_setup_signal_stack_si(&frame, ksig);
//err |= arch_setup_signal_stack_si(&frame, ksig);
if (err)
return err;

Expand Down Expand Up @@ -457,7 +457,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
sigset_t set;

/* fixup rt_sigframe for nommu */
frame = arch_setup_rt_sigreturn(frame);
//frame = arch_setup_rt_sigreturn(frame);
uc = &frame->uc;

if (copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
Expand Down

0 comments on commit ae5dab8

Please sign in to comment.