MacOS X.3 introduces a new sigreturn for PowerPC, with a usercontext

versionning argument. For now we only implement the X.2 flavor.
This commit is contained in:
manu 2004-07-04 21:03:55 +00:00
parent aab7e2ab6f
commit 67cf1bc043
7 changed files with 142 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: darwin_machdep.h,v 1.5 2004/07/03 00:14:30 manu Exp $ */
/* $NetBSD: darwin_machdep.h,v 1.6 2004/07/04 21:03:55 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@ -45,6 +45,11 @@
#define DARWIN_USRSTACK 0xbfff0000
#define DARWIN_USRSTACK32 0x00000000bfff000L
/*
* User context versions for newer sigreturn
*/
#define DARWIN_UCVERS_X2 1
void darwin_fork_child_return(void *);
struct darwin_mcontext {

View File

@ -1,4 +1,4 @@
/* $NetBSD: darwin_machdep.c,v 1.14 2004/04/18 23:32:46 matt Exp $ */
/* $NetBSD: darwin_machdep.c,v 1.15 2004/07/04 21:03:55 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: darwin_machdep.c,v 1.14 2004/04/18 23:32:46 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: darwin_machdep.c,v 1.15 2004/07/04 21:03:55 manu Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -182,11 +182,13 @@ darwin_sendsig(ksi, mask)
* The signal trampoline calls this system call
* to get the process state restored like it was
* before the signal delivery.
*
* This is the version for X.2 binaries and older
*/
int
darwin_sys_sigreturn(struct lwp *l, void *v, register_t *retval)
darwin_sys_sigreturn_x2(struct lwp *l, void *v, register_t *retval)
{
struct darwin_sys_sigreturn_args /* {
struct darwin_sys_sigreturn_x2_args /* {
syscallarg(struct darwin_ucontext *) uctx;
} */ *uap = v;
struct proc *p = l->l_proc;
@ -247,6 +249,84 @@ darwin_sys_sigreturn(struct lwp *l, void *v, register_t *retval)
return (EJUSTRETURN);
}
/*
* This is the version used starting with X.3 binaries
*/
int
darwin_sys_sigreturn(struct lwp *l, void *v, register_t *retval)
{
struct darwin_sys_sigreturn_args /* {
syscallarg(struct darwin_ucontext *) uctx;
syscallarg(int) ucvers;
} */ *uap = v;
struct proc *p = l->l_proc;
struct darwin_ucontext uctx;
struct darwin_mcontext mctx;
struct trapframe *tf;
sigset_t mask;
size_t mcsize;
int error;
switch (SCARG(uap, ucvers)) {
case DARWIN_UCVERS_X2:
break;
default:
printf("darwin_sys_sigreturn: ucvers = %d\n",
SCARG(uap, ucvers));
break;
}
/*
* The trampoline hands us the context.
* It is unsafe to keep track of it ourselves, in the event that a
* program jumps out of a signal hander.
*/
if ((error = copyin(SCARG(uap, uctx), &uctx, sizeof(uctx))) != 0)
return (error);
/* Check mcontext size, as it is handed by user code */
mcsize = uctx.uc_mcsize;
if (mcsize > sizeof(mctx))
mcsize = sizeof(mctx);
if ((error = copyin(uctx.uc_mcontext, &mctx, mcsize)) != 0)
return (error);
/* Check for security abuse */
tf = trapframe(l);
if (!PSL_USEROK_P(mctx.ss.srr1)) {
DPRINTF(("uctx.ss.srr1 = 0x%08x, rf->srr1 = 0x%08lx\n",
mctx.ss.srr1, tf->srr1));
return (EINVAL);
}
/* Restore the context */
tf->dar = mctx.es.dar;
tf->dsisr = mctx.es.dsisr;
tf->exc = mctx.es.exception;
tf->srr0 = mctx.ss.srr0;
tf->srr1 = mctx.ss.srr1;
memcpy(&tf->fixreg[0], &mctx.ss.gpreg[0], sizeof(mctx.ss.gpreg));
tf->cr = mctx.ss.cr;
tf->xer = mctx.ss.xer;
tf->lr = mctx.ss.lr;
tf->ctr = mctx.ss.ctr;
/* Restore signal stack */
if (uctx.uc_onstack & SS_ONSTACK)
p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
/* Restore signal mask */
native_sigset13_to_sigset(&uctx.uc_sigmask, &mask);
(void)sigprocmask1(p, SIG_SETMASK, &mask, 0);
return (EJUSTRETURN);
}
/*
* Set the return value for darwin binaries after a fork(). The userland
* libSystem stub expects the child pid to be in retval[0] for the parent

View File

@ -1,10 +1,10 @@
/* $NetBSD: darwin_syscall.h,v 1.37 2003/12/31 02:55:04 manu Exp $ */
/* $NetBSD: darwin_syscall.h,v 1.38 2004/07/04 21:03:55 manu Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.20 2003/12/16 16:13:59 manu Exp
* created from NetBSD: syscalls.master,v 1.21 2003/12/31 02:55:04 manu Exp
*/
/* syscall: "syscall" ret: "int" args: "int" "..." */
@ -250,8 +250,8 @@
/* syscall: "orecv" ret: "int" args: "int" "caddr_t" "int" "int" */
#define DARWIN_SYS_orecv 102
/* syscall: "sigreturn" ret: "int" args: "struct darwin_ucontext *" */
#define DARWIN_SYS_sigreturn 103
/* syscall: "sigreturn_x2" ret: "int" args: "struct darwin_ucontext *" */
#define DARWIN_SYS_sigreturn_x2 103
/* syscall: "setsockopt" ret: "int" args: "int" "int" "int" "const void *" "unsigned int" */
#define DARWIN_SYS_setsockopt 105
@ -390,6 +390,12 @@
/* syscall: "seteuid" ret: "int" args: "uid_t" */
#define DARWIN_SYS_seteuid 183
#ifdef __powerpc__
/* syscall: "sigreturn" ret: "int" args: "struct darwin_ucontext *" "int" */
#define DARWIN_SYS_sigreturn 184
#else
#endif
/* syscall: "stat12" ret: "int" args: "const char *" "struct stat12 *" */
#define DARWIN_SYS_stat12 188

View File

@ -1,10 +1,10 @@
/* $NetBSD: darwin_syscallargs.h,v 1.37 2003/12/31 02:55:04 manu Exp $ */
/* $NetBSD: darwin_syscallargs.h,v 1.38 2004/07/04 21:03:55 manu Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.20 2003/12/16 16:13:59 manu Exp
* created from NetBSD: syscalls.master,v 1.21 2003/12/31 02:55:04 manu Exp
*/
#ifndef _DARWIN_SYS__SYSCALLARGS_H_
@ -173,7 +173,7 @@ struct bsd_compat_12_sys_swapon_args {
syscallarg(const char *) name;
};
struct darwin_sys_sigreturn_args {
struct darwin_sys_sigreturn_x2_args {
syscallarg(struct darwin_ucontext *) uctx;
};
@ -241,6 +241,14 @@ struct darwin_sys_kdebug_trace_args {
syscallarg(int) arg4;
syscallarg(int) arg5;
};
#ifdef __powerpc__
struct darwin_sys_sigreturn_args {
syscallarg(struct darwin_ucontext *) uctx;
syscallarg(int) ucvers;
};
#else
#endif
struct darwin_sys_stat_args {
syscallarg(const char *) path;
@ -515,7 +523,7 @@ int compat_43_sys_send(struct lwp *, void *, register_t *);
int compat_43_sys_recv(struct lwp *, void *, register_t *);
int darwin_sys_sigreturn(struct lwp *, void *, register_t *);
int darwin_sys_sigreturn_x2(struct lwp *, void *, register_t *);
int bsd_sys_bind(struct lwp *, void *, register_t *);
@ -625,6 +633,11 @@ int sys_setegid(struct lwp *, void *, register_t *);
int sys_seteuid(struct lwp *, void *, register_t *);
#ifdef __powerpc__
int darwin_sys_sigreturn(struct lwp *, void *, register_t *);
#else
#endif
int darwin_sys_stat(struct lwp *, void *, register_t *);
int darwin_sys_fstat(struct lwp *, void *, register_t *);

View File

@ -1,14 +1,14 @@
/* $NetBSD: darwin_syscalls.c,v 1.37 2003/12/31 02:55:04 manu Exp $ */
/* $NetBSD: darwin_syscalls.c,v 1.38 2004/07/04 21:03:55 manu Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.20 2003/12/16 16:13:59 manu Exp
* created from NetBSD: syscalls.master,v 1.21 2003/12/31 02:55:04 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.37 2003/12/31 02:55:04 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.38 2004/07/04 21:03:55 manu Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ktrace.h"
@ -148,7 +148,7 @@ const char *const darwin_syscallnames[] = {
"getpriority", /* 100 = getpriority */
"osend", /* 101 = osend */
"orecv", /* 102 = orecv */
"sigreturn", /* 103 = sigreturn */
"sigreturn_x2", /* 103 = sigreturn_x2 */
"bind", /* 104 = bind */
"setsockopt", /* 105 = setsockopt */
"listen", /* 106 = listen */
@ -237,7 +237,11 @@ const char *const darwin_syscallnames[] = {
"setgid", /* 181 = setgid */
"setegid", /* 182 = setegid */
"seteuid", /* 183 = seteuid */
#ifdef __powerpc__
"sigreturn", /* 184 = sigreturn */
#else
"#184 (unimplemented)", /* 184 = unimplemented */
#endif
"#185 (unimplemented)", /* 185 = unimplemented */
"#186 (unimplemented)", /* 186 = unimplemented */
"#187 (unimplemented)", /* 187 = unimplemented */

View File

@ -1,14 +1,14 @@
/* $NetBSD: darwin_sysent.c,v 1.38 2003/12/31 02:55:04 manu Exp $ */
/* $NetBSD: darwin_sysent.c,v 1.39 2004/07/04 21:03:55 manu Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.20 2003/12/16 16:13:59 manu Exp
* created from NetBSD: syscalls.master,v 1.21 2003/12/31 02:55:04 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.38 2003/12/31 02:55:04 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.39 2004/07/04 21:03:55 manu Exp $");
#include "opt_ktrace.h"
#include "opt_nfsserver.h"
@ -254,8 +254,8 @@ struct sysent darwin_sysent[] = {
compat_43_sys_send }, /* 101 = osend */
{ 4, s(struct compat_43_sys_recv_args), 0,
compat_43_sys_recv }, /* 102 = orecv */
{ 1, s(struct darwin_sys_sigreturn_args), 0,
darwin_sys_sigreturn }, /* 103 = sigreturn */
{ 1, s(struct darwin_sys_sigreturn_x2_args), 0,
darwin_sys_sigreturn_x2 }, /* 103 = sigreturn_x2 */
{ 3, s(struct bsd_sys_bind_args), 0,
bsd_sys_bind }, /* 104 = bind */
{ 5, s(struct sys_setsockopt_args), 0,
@ -426,8 +426,13 @@ struct sysent darwin_sysent[] = {
sys_setegid }, /* 182 = setegid */
{ 1, s(struct sys_seteuid_args), 0,
sys_seteuid }, /* 183 = seteuid */
#ifdef __powerpc__
{ 2, s(struct darwin_sys_sigreturn_args), 0,
darwin_sys_sigreturn }, /* 184 = sigreturn */
#else
{ 0, 0, 0,
sys_nosys }, /* 184 = unimplemented */
#endif
{ 0, 0, 0,
sys_nosys }, /* 185 = unimplemented */
{ 0, 0, 0,

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.21 2003/12/31 02:55:04 manu Exp $
$NetBSD: syscalls.master,v 1.22 2004/07/04 21:03:55 manu Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@ -230,7 +230,7 @@
int flags); } osend
102 NOARGS { int compat_43_sys_recv(int s, caddr_t buf, int len, \
int flags); } orecv
103 STD { int darwin_sys_sigreturn(struct \
103 STD { int darwin_sys_sigreturn_x2(struct \
darwin_ucontext *uctx); }
104 NODEF { int bsd_sys_bind(int s, const struct sockaddr *name, \
unsigned int namelen); }
@ -356,7 +356,12 @@
181 NOARGS { int sys_setgid(gid_t gid); }
182 NOARGS { int sys_setegid(gid_t egid); }
183 NOARGS { int sys_seteuid(uid_t euid); }
#ifdef __powerpc__
184 STD { int darwin_sys_sigreturn(struct \
darwin_ucontext *uctx, int ucvers); }
#else
184 UNIMPL
#endif
185 UNIMPL
186 UNIMPL
187 UNIMPL