Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178183006
D62271.1796212382.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None
D62271.1796212382.diff
View Options
diff --git a/sys/powerpc/linux/linux_sigframe.h b/sys/powerpc/linux/linux_sigframe.h
--- a/sys/powerpc/linux/linux_sigframe.h
+++ b/sys/powerpc/linux/linux_sigframe.h
@@ -187,14 +187,6 @@
} __attribute__((__aligned__(16)));
-struct l_sigframe {
- struct l_rt_sigframe sf;
- /* frame_record */
- uint64_t fp;
- uint64_t lr;
- ucontext_t f_uc;
-};
-
#define LINUX__SIGNAL_FRAMESIZE 128
void __kernel_start_sigtramp_rt64(int, void*, void*, void*);
diff --git a/sys/powerpc/linux/linux_sysvec.c b/sys/powerpc/linux/linux_sysvec.c
--- a/sys/powerpc/linux/linux_sysvec.c
+++ b/sys/powerpc/linux/linux_sysvec.c
@@ -98,6 +98,7 @@
static vm_offset_t linux_vdso_base;
extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
+extern struct sysentvec elf64_linux_sysvec_v2;
uintptr_t aux_vec;
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
@@ -249,7 +250,7 @@
int
linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
{
- struct l_sigframe *frame;
+ struct l_rt_sigframe *frame;
struct l_sigcontext lsc;
l_sigset_t lsigmask;
mcontext_t mctx;
@@ -258,18 +259,17 @@
int error, i;
tf = td->td_frame;
- frame = (struct l_sigframe *)tf->fixreg[1];
+ frame = (struct l_rt_sigframe *)tf->fixreg[1];
/*
* Restore from the Linux sigcontext the handler could have
- * modified, not the FreeBSD ucontext we happened to stash in
- * frame->f_uc. siglongjmp() and other handlers that mutate
- * their ucontext depend on this round trip actually taking
- * effect on return.
+ * modified. siglongjmp() and other handlers that mutate their
+ * ucontext depend on this round trip actually taking effect on
+ * return.
*/
- if (copyin(&frame->sf.uc.uc_mcontext, &lsc, sizeof(lsc)))
+ if (copyin(&frame->uc.uc_mcontext, &lsc, sizeof(lsc)))
return (EFAULT);
- if (copyin(&frame->sf.uc.uc_sigmask, &lsigmask, sizeof(lsigmask)))
+ if (copyin(&frame->uc.uc_sigmask, &lsigmask, sizeof(lsigmask)))
return (EFAULT);
/*
@@ -343,14 +343,16 @@
struct thread *td;
struct proc *p;
struct trapframe *tf;
- struct l_sigframe *fp, *frame;
- struct l_rt_sigframe *l_frame;
- l_stack_t uc_stack;
- ucontext_t f_uc;
+ struct l_rt_sigframe *fp, *frame;
+ struct l_sigcontext *sc;
struct sigacts *psp;
- uintptr_t uoff;
- int onstack, sig, issiginfo;
+ mcontext_t mctx;
+ l_stack_t uc_stack;
+ uintptr_t sp, uoff;
+ uint64_t entry, toc;
unsigned long newsp;
+ int onstack, sig, issiginfo, i;
+ bool elfv2;
td = curthread;
p = td->td_proc;
@@ -361,40 +363,36 @@
mtx_assert(&psp->ps_mtx, MA_OWNED);
tf = td->td_frame;
- onstack = sigonstack(tf->fixreg[1]);
+ sp = tf->fixreg[1];
+ onstack = sigonstack(sp);
issiginfo = SIGISMEMBER(psp->ps_siginfo, sig);
-
-
- fp = (struct l_sigframe *)td->td_frame->fixreg[1];
-
- /* sizeof(*fp) is a multiple of 16, so this keeps r1 quadword aligned. */
- fp--;
-
- mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(td->td_proc);
- /*
- * f_uc is copied out as part of the frame, so zero the members
- * left untouched below rather than leaking kernel stack.
- */
- bzero(&f_uc, sizeof(f_uc));
- get_mcontext(td, &f_uc.uc_mcontext, 0);
- PROC_LOCK(p);
- mtx_lock(&psp->ps_mtx);
-
- f_uc.uc_sigmask = *mask;
+ elfv2 = (p->p_sysent == &elf64_linux_sysvec_v2);
uc_stack.ss_sp = PTROUT(td->td_sigstk.ss_sp);
uc_stack.ss_size = td->td_sigstk.ss_size;
uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ?
(onstack ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
+ /* Switch to the alternate signal stack if the handler asked for it. */
+ if ((td->td_pflags & TDP_ALTSTACK) != 0 && !onstack &&
+ SIGISMEMBER(psp->ps_sigonstack, sig))
+ sp = (uintptr_t)td->td_sigstk.ss_sp + td->td_sigstk.ss_size;
+
+ /*
+ * The frame ends in an abigap[] member that is never written, so
+ * putting the frame right below the stack pointer keeps the red
+ * zone of the interrupted function intact.
+ */
+ fp = (struct l_rt_sigframe *)((sp - sizeof(*fp)) & ~(uintptr_t)0xf);
+
mtx_unlock(&psp->ps_mtx);
- PROC_UNLOCK(td->td_proc);
+ PROC_UNLOCK(p);
+
+ get_mcontext(td, &mctx, 0);
/* Fill in the frame to copy out */
frame = malloc(sizeof(*frame), M_LINUX, M_WAITOK | M_ZERO);
- memcpy(&frame->f_uc, &f_uc, sizeof(f_uc));
- l_frame = (struct l_rt_sigframe*)frame;
+ sc = &frame->uc.uc_mcontext;
/*
* The frame is built in a staging copy and copied out to fp, so
@@ -403,26 +401,28 @@
*/
uoff = (uintptr_t)fp - (uintptr_t)frame;
- l_frame->pinfo = (l_siginfo_t *)((uintptr_t)&l_frame->info + uoff);
- l_frame->puc = (void *)((uintptr_t)&l_frame->uc + uoff);
+ frame->pinfo = (l_siginfo_t *)((uintptr_t)&frame->info + uoff);
+ frame->puc = (void *)((uintptr_t)&frame->uc + uoff);
/* Create the l_ucontext */
- l_frame->uc.uc_flags = 0;
- memcpy(&l_frame->uc.uc_stack, &uc_stack, sizeof(uc_stack));
- l_frame->uc.uc_link = 0;
+ frame->uc.uc_flags = 0;
+ frame->uc.uc_link = 0;
+ memcpy(&frame->uc.uc_stack, &uc_stack, sizeof(uc_stack));
/* gp_regs[] uses Linux ppc64's slot order, not the trapframe's. */
- l_frame->uc.uc_mcontext.regs = (struct l_user_pt_regs *)
- ((uintptr_t)&l_frame->uc.uc_mcontext.gp_regs + uoff);
- for (int i = 0; i < 32; i++)
- l_frame->uc.uc_mcontext.gp_regs[PT_R0 + i] = tf->fixreg[i];
- l_frame->uc.uc_mcontext.gp_regs[PT_NIP] = tf->srr0;
- l_frame->uc.uc_mcontext.gp_regs[PT_MSR] = tf->srr1;
- l_frame->uc.uc_mcontext.gp_regs[PT_CTR] = tf->ctr;
- l_frame->uc.uc_mcontext.gp_regs[PT_LNK] = tf->lr;
- l_frame->uc.uc_mcontext.gp_regs[PT_XER] = tf->xer;
- l_frame->uc.uc_mcontext.gp_regs[PT_CCR] = tf->cr;
- l_frame->uc.uc_mcontext.gp_regs[PT_SOFTE] = 1;
+ sc->regs = (struct l_user_pt_regs *)((uintptr_t)&sc->gp_regs + uoff);
+ for (i = 0; i < 32; i++)
+ sc->gp_regs[PT_R0 + i] = tf->fixreg[i];
+ sc->gp_regs[PT_NIP] = tf->srr0;
+ sc->gp_regs[PT_MSR] = tf->srr1;
+ sc->gp_regs[PT_CTR] = tf->ctr;
+ sc->gp_regs[PT_LNK] = tf->lr;
+ sc->gp_regs[PT_XER] = tf->xer;
+ sc->gp_regs[PT_CCR] = tf->cr;
+ sc->gp_regs[PT_SOFTE] = 1;
+ sc->gp_regs[PT_TRAP] = tf->exc;
+ sc->gp_regs[PT_DAR] = tf->dar;
+ sc->gp_regs[PT_DSISR] = tf->cpu.aim.dsisr;
/*
* FP registers: fp_regs[0..31] hold the low doubleword of each
@@ -430,11 +430,9 @@
* FPSCR. FreeBSD's mc_fpreg[] uses the same layout, so this
* is a straight copy when the thread has valid FP state.
*/
- if (f_uc.uc_mcontext.mc_flags & _MC_FP_VALID) {
- memcpy(&l_frame->uc.uc_mcontext.fp_regs[0],
- &f_uc.uc_mcontext.mc_fpreg[0],
- sizeof(l_frame->uc.uc_mcontext.fp_regs));
- }
+ if (mctx.mc_flags & _MC_FP_VALID)
+ memcpy(&sc->fp_regs[0], &mctx.mc_fpreg[0],
+ sizeof(sc->fp_regs));
/*
* VMX/VSX save. Linux places the vector state after the
@@ -447,47 +445,59 @@
* after that : VSR[0..31] high doublewords (32 * 8 bytes)
*
* If the thread has no live VMX state, hand userland a NULL
- * v_regs (per Linux's ABI contract).
+ * v_regs (per Linux's ABI contract). The quadword alignment has
+ * to hold for the address userland sees, not for the staging copy.
*/
- if (f_uc.uc_mcontext.mc_flags & _MC_AV_VALID) {
- uintptr_t k_vmx = (uintptr_t)&frame->sf.uc.uc_mcontext.vmx_reserve[0];
- uintptr_t k_vregs = roundup2(k_vmx, 16);
- l_elf_vrreg_t *kv = (l_elf_vrreg_t *)k_vregs;
- int i;
-
- l_frame->uc.uc_mcontext.v_regs =
- (l_elf_vrreg_t *)(k_vregs + uoff);
-
- for (i = 0; i < 32; i++)
- memcpy(&kv[i],
- &f_uc.uc_mcontext.mc_avec[i * 2],
- sizeof(l_elf_vrreg_t));
- memset(&kv[32], 0, sizeof(l_elf_vrreg_t));
- kv[32].u[3] = f_uc.uc_mcontext.mc_vscr;
- memset(&kv[33], 0, sizeof(l_elf_vrreg_t));
- kv[33].u[0] = f_uc.uc_mcontext.mc_vrsave;
-
- if (f_uc.uc_mcontext.mc_flags & _MC_VS_VALID) {
- uint64_t *vsx_dw1 = (uint64_t *)&kv[34];
- for (i = 0; i < 32; i++)
- vsx_dw1[i] = f_uc.uc_mcontext.mc_vsxfpreg[i];
- }
+ if (mctx.mc_flags & _MC_AV_VALID) {
+ uintptr_t u_vregs;
+ char *kv;
+ uint32_t word;
+
+ u_vregs = roundup2((uintptr_t)&sc->vmx_reserve[0] + uoff, 16);
+ kv = (char *)(u_vregs - uoff);
+ sc->v_regs = (l_elf_vrreg_t *)u_vregs;
+
+ memcpy(kv, &mctx.mc_avec[0], 32 * sizeof(l_elf_vrreg_t));
+ word = mctx.mc_vscr;
+ memcpy(kv + 32 * sizeof(l_elf_vrreg_t) + 3 * sizeof(word),
+ &word, sizeof(word));
+ word = mctx.mc_vrsave;
+ memcpy(kv + 33 * sizeof(l_elf_vrreg_t), &word, sizeof(word));
+
+ if (mctx.mc_flags & _MC_VS_VALID)
+ memcpy(kv + LINUX_ELF_NVRREG * sizeof(l_elf_vrreg_t),
+ &mctx.mc_vsxfpreg[0], 32 * sizeof(uint64_t));
} else {
- l_frame->uc.uc_mcontext.v_regs = NULL;
+ sc->v_regs = NULL;
}
sig = bsd_to_linux_signal(sig);
- l_frame->uc.uc_mcontext.signal = sig;
- l_frame->uc.uc_mcontext.handler = (unsigned long)catcher;
+ sc->signal = sig;
+ sc->handler = (unsigned long)catcher;
+
+ bsd_to_linux_sigset(mask, &frame->uc.uc_sigmask);
- bsd_to_linux_sigset(mask, &l_frame->uc.uc_sigmask);
+ siginfo_to_lsiginfo(&ksi->ksi_info, &frame->info, sig);
- siginfo_to_lsiginfo(&ksi->ksi_info, &l_frame->info, sig);
+ /* Allocate a dummy caller frame for the signal handler. */
+ newsp = (unsigned long)fp - LINUX__SIGNAL_FRAMESIZE;
- /* Might need to make sure signal handler doesn't get spurious FP exceptions? */
+ entry = (uint64_t)catcher;
+ toc = 0;
- /* Copy the sigframe out to the user's stack. */
- if (copyout(frame, fp, sizeof(*fp)) != 0) {
+ /*
+ * Copy the sigframe out to the user's stack, leaving the red zone
+ * alone, and store the back chain of the dummy frame. An ELFv1
+ * handler is a pointer to a function descriptor holding the entry
+ * point and the TOC of the routine.
+ */
+ if (copyout(frame, fp, offsetof(struct l_rt_sigframe, abigap)) != 0 ||
+ suword((void *)newsp, tf->fixreg[1]) != 0 ||
+ (!elfv2 &&
+ (copyin(&((struct l_func_desc *)catcher)->addr, &entry,
+ sizeof(entry)) != 0 ||
+ copyin(&((struct l_func_desc *)catcher)->toc, &toc,
+ sizeof(toc)) != 0))) {
/* Process has trashed its stack. Kill it. */
free(frame, M_LINUX);
CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
@@ -496,31 +506,27 @@
}
free(frame, M_LINUX);
- /* Set up to return from userspace. */
+ /*
+ * Enter the handler through the vDSO trampoline, which calls it
+ * with bctrl and issues rt_sigreturn() once it returns. ELFv2
+ * expects the entry point in r12 to derive its TOC pointer.
+ */
tf->srr0 = (register_t)linux_vdso_sigcode;
-
- /* Allocate a dummy caller frame for the signal handler. */
- newsp = (unsigned long)fp - LINUX__SIGNAL_FRAMESIZE;
-
- /* For ELFv1 */
- /* Handler is *really* a pointer to the function descriptor for
- * the signal routine. The first entry in the function
- * descriptor is the entry address of signal and the second
- * entry is the TOC value we need to use.
- */
- struct l_func_desc *ptr = (struct l_func_desc*)catcher;
- tf->ctr = (register_t)ptr->addr;
- tf->fixreg[2] = (register_t)ptr->toc;
+ tf->ctr = (register_t)entry;
+ if (elfv2)
+ tf->fixreg[12] = (register_t)entry;
+ else
+ tf->fixreg[2] = (register_t)toc;
tf->fixreg[1] = (register_t)newsp;
tf->fixreg[3] = (register_t)sig;
if (issiginfo) {
- tf->fixreg[4] = (register_t)&fp->sf.info;
- tf->fixreg[5] = (register_t)&fp->sf.uc;
- tf->fixreg[6] = (register_t)&fp->sf;
+ tf->fixreg[4] = (register_t)&fp->info;
+ tf->fixreg[5] = (register_t)&fp->uc;
+ tf->fixreg[6] = (register_t)fp;
} else {
- tf->fixreg[4] = (register_t)&fp->sf.uc.uc_mcontext;
+ tf->fixreg[4] = (register_t)&fp->uc.uc_mcontext;
}
PROC_LOCK(p);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 2, 11:53 AM (19 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42141167
Default Alt Text
D62271.1796212382.diff (11 KB)
Attached To
Mode
D62271: linuxulator/powerpc: fix signal delivery
Attached
Detach File
Event Timeline