Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
- index e9dafbd8fe3..5f7dc9adfe0 100644
- --- a/sys/amd64/amd64/trap.c
- +++ b/sys/amd64/amd64/trap.c
- @@ -963,48 +963,67 @@ cpu_fetch_syscall_args(struct thread *td)
- register_t *argp;
- struct syscall_args *sa;
- caddr_t params;
- - int reg, regcnt, error;
- + int regoff, regcnt, error;
- + u_int abi;
- p = td->td_proc;
- - frame = td->td_frame;
- - sa = &td->td_sa;
- - reg = 0;
- - regcnt = 6;
- + abi = SV_PROC_ABI(p);
- +
- + KASSERT(abi == SV_ABI_FREEBSD ||
- + abi == SV_ABI_LINUX ||
- + abi == SV_ABI_CLOUDABI,
- + ("Unknown ABI. cpu_fetch_syscall_args is unimplemented."));
- - sa->code = frame->tf_rax;
- - if (sa->code == SYS_syscall || sa->code == SYS___syscall) {
- - sa->code = frame->tf_rdi;
- - reg++;
- - regcnt--;
- + frame = td->td_frame;
- + regoff = 0;
- + if (__predict_true(abi == SV_ABI_FREEBSD)) {
- + regoff = frame->tf_rax == SYS_syscall ||
- + frame->tf_rax == SYS___syscall;
- }
- - 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 = &td->td_sa;
- + regcnt = 6 - regoff;
- +
- + sa->code = regoff ? frame->tf_rdi : frame->tf_rax;
- + if (__predict_false(sa->code >= p->p_sysent->sv_size)) {
- + switch (abi) {
- + case SV_ABI_CLOUDABI:
- + return (ENOSYS);
- + case SV_ABI_LINUX:
- + sa->code = p->p_sysent->sv_size - 1;
- + break;
- + case SV_ABI_FREEBSD:
- + sa->code = 0;
- + break;
- + }
- + }
- + sa->callp = &p->p_sysent->sv_table[sa->code];
- + if (p->p_sysent->sv_mask)
- + sa->code &= p->p_sysent->sv_mask;
- sa->narg = sa->callp->sy_narg;
- KASSERT(sa->narg <= sizeof(sa->args) / sizeof(sa->args[0]),
- ("Too many syscall arguments!"));
- error = 0;
- argp = &frame->tf_rdi;
- - argp += reg;
- + argp += regoff;
- memcpy(sa->args, argp, sizeof(sa->args[0]) * 6);
- + /* Other ABIs than FreeBSD has maximum 6 arguments per syscall. */
- if (sa->narg > regcnt) {
- params = (caddr_t)frame->tf_rsp + sizeof(register_t);
- error = copyin(params, &sa->args[regcnt],
- (sa->narg - regcnt) * sizeof(sa->args[0]));
- }
- - if (error == 0) {
- - td->td_retval[0] = 0;
- + if (error != 0)
- + return (error);
- +
- + td->td_retval[0] = 0;
- + if (SV_PROC_ABI(p) != SV_ABI_LINUX)
- td->td_retval[1] = frame->tf_rdx;
- - }
- - return (error);
- + return (0);
- }
- #include "../../kern/subr_syscall.c"
- diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
- index dca9f568463..50af59cf790 100644
- --- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c
- +++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
- @@ -86,36 +86,6 @@ cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp,
- (void)cpu_set_user_tls(td, TO_PTR(stack));
- }
- -static int
- -cloudabi64_fetch_syscall_args(struct thread *td)
- -{
- - struct trapframe *frame;
- - struct syscall_args *sa;
- -
- - frame = td->td_frame;
- - sa = &td->td_sa;
- -
- - /* Obtain system call number. */
- - sa->code = frame->tf_rax;
- - if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL)
- - return (ENOSYS);
- - sa->callp = &cloudabi64_sysent[sa->code];
- - sa->narg = sa->callp->sy_narg;
- -
- - /* Fetch system call arguments. */
- - sa->args[0] = frame->tf_rdi;
- - sa->args[1] = frame->tf_rsi;
- - sa->args[2] = frame->tf_rdx;
- - sa->args[3] = frame->tf_rcx; /* Actually %r10. */
- - sa->args[4] = frame->tf_r8;
- - sa->args[5] = frame->tf_r9;
- -
- - /* Default system call return values. */
- - td->td_retval[0] = 0;
- - td->td_retval[1] = frame->tf_rdx;
- - return (0);
- -}
- -
- static void
- cloudabi64_set_syscall_retval(struct thread *td, int error)
- {
- @@ -206,7 +176,7 @@ static struct sysentvec cloudabi64_elf_sysvec = {
- .sv_setregs = cloudabi64_proc_setregs,
- .sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_LP64,
- .sv_set_syscall_retval = cloudabi64_set_syscall_retval,
- - .sv_fetch_syscall_args = cloudabi64_fetch_syscall_args,
- + .sv_fetch_syscall_args = cpu_fetch_syscall_args,
- .sv_syscallnames = cloudabi64_syscallnames,
- .sv_schedtail = cloudabi64_schedtail,
- };
- diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
- index afa06bb415c..8e3882767a5 100644
- --- a/sys/amd64/linux/linux_sysvec.c
- +++ b/sys/amd64/linux/linux_sysvec.c
- @@ -118,7 +118,6 @@ static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
- static void linux_vdso_install(void *param);
- static void linux_vdso_deinstall(void *param);
- static void linux_set_syscall_retval(struct thread *td, int error);
- -static int linux_fetch_syscall_args(struct thread *td);
- static void linux_exec_setregs(struct thread *td, struct image_params *imgp,
- u_long stack);
- static int linux_vsyscall(struct thread *td);
- @@ -188,36 +187,6 @@ linux_translate_traps(int signal, int trap_code)
- }
- }
- -static int
- -linux_fetch_syscall_args(struct thread *td)
- -{
- - struct proc *p;
- - struct trapframe *frame;
- - struct syscall_args *sa;
- -
- - p = td->td_proc;
- - frame = td->td_frame;
- - sa = &td->td_sa;
- -
- - sa->args[0] = frame->tf_rdi;
- - sa->args[1] = frame->tf_rsi;
- - sa->args[2] = frame->tf_rdx;
- - sa->args[3] = frame->tf_rcx;
- - sa->args[4] = frame->tf_r8;
- - sa->args[5] = frame->tf_r9;
- - sa->code = frame->tf_rax;
- -
- - if (sa->code >= p->p_sysent->sv_size)
- - /* nosys */
- - sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
- - else
- - sa->callp = &p->p_sysent->sv_table[sa->code];
- - sa->narg = sa->callp->sy_narg;
- -
- - td->td_retval[0] = 0;
- - return (0);
- -}
- -
- static void
- linux_set_syscall_retval(struct thread *td, int error)
- {
- @@ -735,7 +704,7 @@ struct sysentvec elf_linux_sysvec = {
- .sv_maxssiz = NULL,
- .sv_flags = SV_ABI_LINUX | SV_LP64 | SV_SHP,
- .sv_set_syscall_retval = linux_set_syscall_retval,
- - .sv_fetch_syscall_args = linux_fetch_syscall_args,
- + .sv_fetch_syscall_args = cpu_fetch_syscall_args,
- .sv_syscallnames = NULL,
- .sv_shared_page_base = SHAREDPAGE,
- .sv_shared_page_len = PAGE_SIZE,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement