From 791b4b11220da33b615f8f806a4061700e6564dd Mon Sep 17 00:00:00 2001 From: dchagin Date: Sun, 22 May 2016 12:46:34 +0000 Subject: [PATCH] Add macro to convert errno and use it when appropriate. MFC after: 1 week --- sys/amd64/amd64/vm_machdep.c | 8 +------- sys/i386/i386/vm_machdep.c | 8 +------- sys/powerpc/powerpc/exec_machdep.c | 6 +----- sys/sparc64/sparc64/vm_machdep.c | 8 +------- sys/sys/sysent.h | 2 ++ 5 files changed, 6 insertions(+), 26 deletions(-) diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c index ff857bb52293..fc9e634940fc 100644 --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -414,13 +414,7 @@ cpu_set_syscall_retval(struct thread *td, int error) break; default: - if (td->td_proc->p_sysent->sv_errsize) { - if (error >= td->td_proc->p_sysent->sv_errsize) - error = -1; /* XXX */ - else - error = td->td_proc->p_sysent->sv_errtbl[error]; - } - td->td_frame->tf_rax = error; + td->td_frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error); td->td_frame->tf_rflags |= PSL_C; break; } diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index fe6297a8ecd0..65f3a0a1ae75 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -451,13 +451,7 @@ cpu_set_syscall_retval(struct thread *td, int error) break; default: - if (td->td_proc->p_sysent->sv_errsize) { - if (error >= td->td_proc->p_sysent->sv_errsize) - error = -1; /* XXX */ - else - error = td->td_proc->p_sysent->sv_errtbl[error]; - } - td->td_frame->tf_eax = error; + td->td_frame->tf_eax = SV_ABI_ERRNO(td->td_proc, error); td->td_frame->tf_eflags |= PSL_C; break; } diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index c78899db278c..fc88f9deafe7 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -908,11 +908,7 @@ cpu_set_syscall_retval(struct thread *td, int error) tf->srr0 -= 4; break; default: - if (p->p_sysent->sv_errsize) { - error = (error < p->p_sysent->sv_errsize) ? - p->p_sysent->sv_errtbl[error] : -1; - } - tf->fixreg[FIRSTARG] = error; + tf->fixreg[FIRSTARG] = SV_ABI_ERRNO(p, error); tf->cr |= 0x10000000; /* Set summary overflow */ break; } diff --git a/sys/sparc64/sparc64/vm_machdep.c b/sys/sparc64/sparc64/vm_machdep.c index df8be0b4e0c2..5807f29270a3 100644 --- a/sys/sparc64/sparc64/vm_machdep.c +++ b/sys/sparc64/sparc64/vm_machdep.c @@ -167,13 +167,7 @@ cpu_set_syscall_retval(struct thread *td, int error) break; default: - if (td->td_proc->p_sysent->sv_errsize) { - if (error >= td->td_proc->p_sysent->sv_errsize) - error = -1; /* XXX */ - else - error = td->td_proc->p_sysent->sv_errtbl[error]; - } - td->td_frame->tf_out[0] = error; + td->td_frame->tf_out[0] = SV_ABI_ERRNO(td->td_proc, error); td->td_frame->tf_tstate |= TSTATE_XCC_C; break; } diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index a79ff04bb231..1f1ab7ab1b70 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -141,6 +141,8 @@ struct sysentvec { #define SV_TIMEKEEP 0x040000 #define SV_ABI_MASK 0xff +#define SV_ABI_ERRNO(p, e) ((p)->p_sysent->sv_errsize <= 0 ? e : \ + ((e) >= (p)->p_sysent->sv_errsize ? -1 : (p)->p_sysent->sv_errtbl[e])) #define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x)) #define SV_PROC_ABI(p) ((p)->p_sysent->sv_flags & SV_ABI_MASK) #define SV_CURPROC_FLAG(x) SV_PROC_FLAG(curproc, x)