summaryrefslogtreecommitdiffstats
path: root/sys/ia64
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-05-23 18:32:02 +0000
committerkib <kib@FreeBSD.org>2010-05-23 18:32:02 +0000
commit4208ccbe79fd8e0ec189a25823cc3bdbe848155d (patch)
tree56fad7d2ceb7c32121f981b707c967936cda94bf /sys/ia64
parent2b2103d8ae2c5f46d069ef8b5d67cc0061230612 (diff)
downloadFreeBSD-src-4208ccbe79fd8e0ec189a25823cc3bdbe848155d.zip
FreeBSD-src-4208ccbe79fd8e0ec189a25823cc3bdbe848155d.tar.gz
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements: sv_fetch_syscall_args - the method to fetch syscall arguments from usermode into struct syscall_args. The structure is machine-depended (this might be reconsidered after all architectures are converted). sv_set_syscall_retval - the method to set a return value for usermode from the syscall. It is a generalization of cpu_set_syscall_retval(9) to allow ABIs to override the way to set a return value. sv_syscallnames - the table of syscall names. Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding the call to cpu_set_syscall_retval(). The new functions syscallenter(9) and syscallret(9) are provided that use sv_*syscall* pointers and contain the common repeated code from the syscall() implementations for the architecture-specific syscall trap handlers. Syscallenter() fetches arguments, calls syscall implementation from ABI sysent table, and set up return frame. The end of syscall bookkeeping is done by syscallret(). Take advantage of single place for MI syscall handling code and implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the thread is stopped at syscall entry or return point respectively. The EXEC flag augments SCX and notifies debugger that the process address space was changed by one of exec(2)-family syscalls. The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are changed to use syscallenter()/syscallret(). MIPS and arm are not converted and use the mostly unchanged syscall() implementation. Reviewed by: jhb, marcel, marius, nwhitehorn, stas Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc), stas (mips) MFC after: 1 month
Diffstat (limited to 'sys/ia64')
-rw-r--r--sys/ia64/ia32/ia32_trap.c182
-rw-r--r--sys/ia64/ia64/elf_machdep.c5
-rw-r--r--sys/ia64/ia64/trap.c135
-rw-r--r--sys/ia64/include/proc.h10
4 files changed, 131 insertions, 201 deletions
diff --git a/sys/ia64/ia32/ia32_trap.c b/sys/ia64/ia32/ia32_trap.c
index ba2bceb..9c7f08d 100644
--- a/sys/ia64/ia32/ia32_trap.c
+++ b/sys/ia64/ia32/ia32_trap.c
@@ -48,86 +48,15 @@ __FBSDID("$FreeBSD$");
#include <security/audit/audit.h>
-extern char *syscallnames[];
+#include <compat/ia32/ia32_util.h>
-static void
-ia32_syscall(struct trapframe *tf)
+void
+ia32_set_syscall_retval(struct thread *td, int error)
{
- uint64_t args64[8];
- uint32_t args[8];
- struct thread *td;
struct proc *p;
- struct sysent *callp;
- caddr_t params;
- register_t eflags;
- u_int code;
- int error, i, narg;
- ksiginfo_t ksi;
-
- PCPU_INC(cnt.v_syscall);
-
- td = curthread;
- params = (caddr_t)(tf->tf_special.sp & ((1L<<32)-1)) +
- sizeof(uint32_t);
- code = tf->tf_scratch.gr8; /* eax */
- eflags = ia64_get_eflag();
- p = td->td_proc;
-
- if (p->p_sysent->sv_prepsyscall == NULL) {
- if (code == SYS_syscall) {
- /* Code is first argument, followed by actual args. */
- code = fuword32(params);
- params += sizeof(int);
- } else if (code == SYS___syscall) {
- /*
- * Like syscall, but code is a quad, so as to maintain
- * quad alignment for the rest of the arguments. We
- * use a 32-bit fetch in case params is not aligned.
- */
- code = fuword32(params);
- params += sizeof(quad_t);
- }
- } else
- (*p->p_sysent->sv_prepsyscall)(tf, args, &code, &params);
-
- if (p->p_sysent->sv_mask)
- code &= p->p_sysent->sv_mask;
-
- if (code >= p->p_sysent->sv_size)
- callp = &p->p_sysent->sv_table[0];
- else
- callp = &p->p_sysent->sv_table[code];
+ struct trapframe *tf;
- narg = callp->sy_narg;
-
- /* copyin and the ktrsyscall()/ktrsysret() code is MP-aware */
- if (params != NULL && narg != 0)
- error = copyin(params, (caddr_t)args, narg * sizeof(int));
- else
- error = 0;
-
- for (i = 0; i < narg; i++)
- args64[i] = args[i];
-
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSCALL))
- ktrsyscall(code, narg, args64);
-#endif
- CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
- td->td_proc->p_pid, td->td_proc->p_comm, code);
-
- if (error == 0) {
- td->td_retval[0] = 0;
- td->td_retval[1] = tf->tf_scratch.gr10; /* edx */
-
- STOPEVENT(p, S_SCE, narg);
-
- PTRACESTOP_SC(p, td, S_PT_SCE);
-
- AUDIT_SYSCALL_ENTER(code, td);
- error = (*callp->sy_call)(td, args64);
- AUDIT_SYSCALL_EXIT(error, td);
- }
+ tf = td->td_frame;
switch (error) {
case 0:
@@ -148,6 +77,7 @@ ia32_syscall(struct trapframe *tf)
break;
default:
+ p = td->td_proc;
if (p->p_sysent->sv_errsize) {
if (error >= p->p_sysent->sv_errsize)
error = -1; /* XXX */
@@ -158,6 +88,74 @@ ia32_syscall(struct trapframe *tf)
ia64_set_eflag(ia64_get_eflag() | PSL_C);
break;
}
+}
+
+int
+ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
+{
+ struct trapframe *tf;
+ struct proc *p;
+ uint32_t args[8];
+ caddr_t params;
+ int error, i;
+
+ tf = td->td_frame;
+ p = td->td_proc;
+
+ params = (caddr_t)(tf->tf_special.sp & ((1L<<32)-1)) +
+ sizeof(uint32_t);
+ sa->code = tf->tf_scratch.gr8; /* eax */
+
+ if (sa->code == SYS_syscall) {
+ /* Code is first argument, followed by actual args. */
+ sa->code = fuword32(params);
+ params += sizeof(int);
+ } else if (sa->code == SYS___syscall) {
+ /*
+ * Like syscall, but code is a quad, so as to maintain
+ * quad alignment for the rest of the arguments. We
+ * use a 32-bit fetch in case params is not aligned.
+ */
+ sa->code = fuword32(params);
+ params += sizeof(quad_t);
+ }
+
+ if (p->p_sysent->sv_mask)
+ sa->code &= p->p_sysent->sv_mask;
+ if (sa->code >= p->p_sysent->sv_size)
+ sa->callp = &p->p_sysent->sv_table[0];
+ else
+ sa->callp = &p->p_sysent->sv_table[sa->code];
+ sa->narg = sa->callp->sy_narg;
+
+ if (params != NULL && sa->narg != 0)
+ error = copyin(params, (caddr_t)args, sa->narg * sizeof(int));
+ else
+ error = 0;
+
+ if (error == 0) {
+ for (i = 0; i < sa->narg; i++)
+ sa->args[i] = args[i];
+ td->td_retval[0] = 0;
+ td->td_retval[1] = tf->tf_scratch.gr10; /* edx */
+ }
+
+ return (error);
+}
+
+static void
+ia32_syscall(struct trapframe *tf)
+{
+ struct thread *td;
+ struct syscall_args sa;
+ register_t eflags;
+ int error;
+ ksiginfo_t ksi;
+
+ td = curthread;
+ eflags = ia64_get_eflag();
+
+ error = syscallenter(td, &sa);
/*
* Traced syscall.
@@ -171,37 +169,7 @@ ia32_syscall(struct trapframe *tf)
trapsignal(td, &ksi);
}
- /*
- * Check for misbehavior.
- */
- WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???");
- KASSERT(td->td_critnest == 0,
- ("System call %s returning in a critical section",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"));
- KASSERT(td->td_locks == 0,
- ("System call %s returning with %d locks held",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???",
- td->td_locks));
-
- /*
- * End of syscall tracing.
- */
- CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
- td->td_proc->p_pid, td->td_proc->p_comm, code);
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSRET))
- ktrsysret(code, error, td->td_retval[0]);
-#endif
-
- /*
- * This works because errno is findable through the
- * register set. If we ever support an emulation where this
- * is not the case, this code will need to be revisited.
- */
- STOPEVENT(p, S_SCX, code);
-
- PTRACESTOP_SC(p, td, S_PT_SCX);
+ syscallret(td, error, &sa);
}
/*
diff --git a/sys/ia64/ia64/elf_machdep.c b/sys/ia64/ia64/elf_machdep.c
index 8360165..87fcd4f 100644
--- a/sys/ia64/ia64/elf_machdep.c
+++ b/sys/ia64/ia64/elf_machdep.c
@@ -81,7 +81,10 @@ struct sysentvec elf64_freebsd_sysvec = {
.sv_setregs = exec_setregs,
.sv_fixlimit = NULL,
.sv_maxssiz = NULL,
- .sv_flags = SV_ABI_FREEBSD | SV_LP64
+ .sv_flags = SV_ABI_FREEBSD | SV_LP64,
+ .sv_set_syscall_retval = cpu_set_syscall_retval,
+ .sv_fetch_syscall_args = cpu_fetch_syscall_args,
+ .sv_syscallnames = syscallnames,
};
static Elf64_Brandinfo freebsd_brand_info = {
diff --git a/sys/ia64/ia64/trap.c b/sys/ia64/ia64/trap.c
index f539097..6ce56b7 100644
--- a/sys/ia64/ia64/trap.c
+++ b/sys/ia64/ia64/trap.c
@@ -87,8 +87,6 @@ static void break_syscall(struct trapframe *tf);
*/
extern struct fpswa_iface *fpswa_iface;
-extern char *syscallnames[];
-
static const char *ia64_vector_names[] = {
"VHPT Translation", /* 0 */
"Instruction TLB", /* 1 */
@@ -899,117 +897,68 @@ break_syscall(struct trapframe *tf)
do_ast(tf);
}
-/*
- * Process a system call.
- *
- * See syscall.s for details as to how we get here. In order to support
- * the ERESTART case, we return the error to our caller. They deal with
- * the hairy details.
- */
int
-syscall(struct trapframe *tf)
+cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
{
- struct sysent *callp;
struct proc *p;
- struct thread *td;
- uint64_t *args;
- int code, error;
-
- ia64_set_fpsr(IA64_FPSR_DEFAULT);
-
- code = tf->tf_scratch.gr15;
- args = &tf->tf_scratch.gr16;
-
- PCPU_INC(cnt.v_syscall);
+ struct trapframe *tf;
+ register_t *args;
- td = curthread;
- td->td_frame = tf;
p = td->td_proc;
+ tf = td->td_frame;
- td->td_pticks = 0;
- if (td->td_ucred != p->p_ucred)
- cred_update_thread(td);
+ sa->code = tf->tf_scratch.gr15;
+ args = &tf->tf_scratch.gr16;
- if (p->p_sysent->sv_prepsyscall) {
- /* (*p->p_sysent->sv_prepsyscall)(tf, args, &code, &params); */
- panic("prepsyscall");
- } else {
+ /*
+ * syscall() and __syscall() are handled the same on
+ * the ia64, as everything is 64-bit aligned, anyway.
+ */
+ if (sa->code == SYS_syscall || sa->code == SYS___syscall) {
/*
- * syscall() and __syscall() are handled the same on
- * the ia64, as everything is 64-bit aligned, anyway.
+ * Code is first argument, followed by actual args.
*/
- if (code == SYS_syscall || code == SYS___syscall) {
- /*
- * Code is first argument, followed by actual args.
- */
- code = args[0];
- args++;
- }
+ sa->code = args[0];
+ args++;
}
if (p->p_sysent->sv_mask)
- code &= p->p_sysent->sv_mask;
-
- if (code >= p->p_sysent->sv_size)
- callp = &p->p_sysent->sv_table[0];
- else
- callp = &p->p_sysent->sv_table[code];
-
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSCALL))
- ktrsyscall(code, callp->sy_narg, args);
-#endif
- CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
- td->td_proc->p_pid, td->td_name, code);
+ sa->code &= p->p_sysent->sv_mask;
+ if (sa->code >= p->p_sysent->sv_size)
+ sa->callp = &p->p_sysent->sv_table[0];
+ else
+ sa->callp = &p->p_sysent->sv_table[sa->code];
+ sa->narg = sa->callp->sy_narg;
+ bcopy(args, sa->args, sa->narg * sizeof(sa->args[0]));
td->td_retval[0] = 0;
td->td_retval[1] = 0;
- tf->tf_scratch.gr10 = EJUSTRETURN;
- STOPEVENT(p, S_SCE, callp->sy_narg);
-
- PTRACESTOP_SC(p, td, S_PT_SCE);
-
- AUDIT_SYSCALL_ENTER(code, td);
- error = (*callp->sy_call)(td, args);
- AUDIT_SYSCALL_EXIT(error, td);
-
- cpu_set_syscall_retval(td, error);
- td->td_syscalls++;
-
- /*
- * Check for misbehavior.
- */
- WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???");
- KASSERT(td->td_critnest == 0,
- ("System call %s returning in a critical section",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"));
- KASSERT(td->td_locks == 0,
- ("System call %s returning with %d locks held",
- (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???",
- td->td_locks));
+ return (0);
+}
- /*
- * Handle reschedule and other end-of-syscall issues
- */
- userret(td, tf);
+/*
+ * Process a system call.
+ *
+ * See syscall.s for details as to how we get here. In order to support
+ * the ERESTART case, we return the error to our caller. They deal with
+ * the hairy details.
+ */
+int
+syscall(struct trapframe *tf)
+{
+ struct syscall_args sa;
+ struct thread *td;
+ int error;
- CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
- td->td_proc->p_pid, td->td_name, code);
-#ifdef KTRACE
- if (KTRPOINT(td, KTR_SYSRET))
- ktrsysret(code, error, td->td_retval[0]);
-#endif
+ td = curthread;
+ td->td_frame = tf;
- /*
- * This works because errno is findable through the
- * register set. If we ever support an emulation where this
- * is not the case, this code will need to be revisited.
- */
- STOPEVENT(p, S_SCX, code);
+ ia64_set_fpsr(IA64_FPSR_DEFAULT);
+ tf->tf_scratch.gr10 = EJUSTRETURN;
- PTRACESTOP_SC(p, td, S_PT_SCX);
+ error = syscallenter(td, &sa);
+ syscallret(td, error, &sa);
return (error);
}
diff --git a/sys/ia64/include/proc.h b/sys/ia64/include/proc.h
index e9f337c..574be36 100644
--- a/sys/ia64/include/proc.h
+++ b/sys/ia64/include/proc.h
@@ -41,4 +41,14 @@ struct mdproc {
#define KINFO_PROC_SIZE 1088
#define KINFO_PROC32_SIZE 768
+#ifdef _KERNEL
+struct syscall_args {
+ u_int code;
+ struct sysent *callp;
+ register_t args[8];
+ int narg;
+};
+#define HAVE_SYSCALL_ARGS_DEF 1
+#endif
+
#endif /* !_MACHINE_PROC_H_ */
OpenPOWER on IntegriCloud