svn commit: r365755 - in head/sys: amd64/amd64 amd64/linux amd64/linux32 arm/arm arm64/arm64 arm64/linux i386/i386 i386/linux powerpc/powerpc

Edward Tomasz Napierala trasz at FreeBSD.org
Tue Sep 15 16:41:24 UTC 2020


Author: trasz
Date: Tue Sep 15 16:41:21 2020
New Revision: 365755
URL: https://svnweb.freebsd.org/changeset/base/365755

Log:
  Move SV_ABI_ERRNO translation into linux-specific code, to simplify
  the syscall path and declutter it a bit.  No functional changes intended.
  
  Reviewed by:	kib (earlier version)
  MFC after:	2 weeks
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D26378

Modified:
  head/sys/amd64/amd64/vm_machdep.c
  head/sys/amd64/linux/linux_sysvec.c
  head/sys/amd64/linux32/linux32_sysvec.c
  head/sys/arm/arm/vm_machdep.c
  head/sys/arm64/arm64/vm_machdep.c
  head/sys/arm64/linux/linux_sysvec.c
  head/sys/i386/i386/vm_machdep.c
  head/sys/i386/linux/linux_sysvec.c
  head/sys/powerpc/powerpc/exec_machdep.c

Modified: head/sys/amd64/amd64/vm_machdep.c
==============================================================================
--- head/sys/amd64/amd64/vm_machdep.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/amd64/amd64/vm_machdep.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -543,7 +543,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
 		break;
 
 	default:
-		frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error);
+		frame->tf_rax = error;
 		frame->tf_rflags |= PSL_C;
 		break;
 	}

Modified: head/sys/amd64/linux/linux_sysvec.c
==============================================================================
--- head/sys/amd64/linux/linux_sysvec.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/amd64/linux/linux_sysvec.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -219,6 +219,11 @@ linux_set_syscall_retval(struct thread *td, int error)
 
 	cpu_set_syscall_retval(td, error);
 
+	if (__predict_false(error != 0)) {
+		if (error != ERESTART && error != EJUSTRETURN)
+			frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error);
+	}
+
 	 /* Restore all registers. */
 	set_pcb_flags(td->td_pcb, PCB_FULL_IRET);
 }

Modified: head/sys/amd64/linux32/linux32_sysvec.c
==============================================================================
--- head/sys/amd64/linux32/linux32_sysvec.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/amd64/linux32/linux32_sysvec.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -112,6 +112,7 @@ static void	linux32_fixlimit(struct rlimit *rl, int wh
 static bool	linux32_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	linux32_set_syscall_retval(struct thread *td, int error);
 
 #define LINUX_T_UNKNOWN  255
 static int _bsd_to_linux_trapcode[] = {
@@ -669,6 +670,19 @@ linux32_fetch_syscall_args(struct thread *td)
 	return (0);
 }
 
+static void
+linux32_set_syscall_retval(struct thread *td, int error)
+{
+	struct trapframe *frame = td->td_frame;
+
+	cpu_set_syscall_retval(td, error);
+
+	if (__predict_false(error != 0)) {
+		if (error != ERESTART && error != EJUSTRETURN)
+			frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error);
+	}
+}
+
 /*
  * Clear registers on exec
  * XXX copied from ia32_signal.c.
@@ -906,7 +920,7 @@ struct sysentvec elf_linux_sysvec = {
 	.sv_fixlimit	= linux32_fixlimit,
 	.sv_maxssiz	= &linux32_maxssiz,
 	.sv_flags	= SV_ABI_LINUX | SV_ILP32 | SV_IA32 | SV_SHP,
-	.sv_set_syscall_retval = cpu_set_syscall_retval,
+	.sv_set_syscall_retval = linux32_set_syscall_retval,
 	.sv_fetch_syscall_args = linux32_fetch_syscall_args,
 	.sv_syscallnames = NULL,
 	.sv_shared_page_base = LINUX32_SHAREDPAGE,

Modified: head/sys/arm/arm/vm_machdep.c
==============================================================================
--- head/sys/arm/arm/vm_machdep.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/arm/arm/vm_machdep.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -219,7 +219,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
 		/* nothing to do */
 		break;
 	default:
-		frame->tf_r0 = SV_ABI_ERRNO(td->td_proc, error);
+		frame->tf_r0 = error;
 		frame->tf_spsr |= PSR_C;    /* carry bit */
 		break;
 	}

Modified: head/sys/arm64/arm64/vm_machdep.c
==============================================================================
--- head/sys/arm64/arm64/vm_machdep.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/arm64/arm64/vm_machdep.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -153,7 +153,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
 		break;
 	default:
 		frame->tf_spsr |= PSR_C;	/* carry bit */
-		frame->tf_x[0] = SV_ABI_ERRNO(td->td_proc, error);
+		frame->tf_x[0] = error;
 		break;
 	}
 }

Modified: head/sys/arm64/linux/linux_sysvec.c
==============================================================================
--- head/sys/arm64/linux/linux_sysvec.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/arm64/linux/linux_sysvec.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -141,6 +141,13 @@ linux_set_syscall_retval(struct thread *td, int error)
 
 	td->td_retval[1] = td->td_frame->tf_x[1];
 	cpu_set_syscall_retval(td, error);
+
+	if (__predict_false(error != 0)) {
+		if (error != ERESTART && error != EJUSTRETURN) {
+			td->td_frame->tf_x[0] =
+				SV_ABI_ERRNO(td->td_proc, error);
+		}
+	}
 }
 
 static int

Modified: head/sys/i386/i386/vm_machdep.c
==============================================================================
--- head/sys/i386/i386/vm_machdep.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/i386/i386/vm_machdep.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -407,7 +407,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
 		break;
 
 	default:
-		td->td_frame->tf_eax = SV_ABI_ERRNO(td->td_proc, error);
+		td->td_frame->tf_eax = error;
 		td->td_frame->tf_eflags |= PSL_C;
 		break;
 	}

Modified: head/sys/i386/linux/linux_sysvec.c
==============================================================================
--- head/sys/i386/linux/linux_sysvec.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/i386/linux/linux_sysvec.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -792,6 +792,19 @@ linux_fetch_syscall_args(struct thread *td)
 	return (0);
 }
 
+static void
+linux_set_syscall_retval(struct thread *td, int error)
+{
+	struct trapframe *frame = td->td_frame;
+
+	cpu_set_syscall_retval(td, error);
+
+	if (__predict_false(error != 0)) {
+		if (error != ERESTART && error != EJUSTRETURN)
+			frame->tf_eax = SV_ABI_ERRNO(td->td_proc, error);
+	}
+}
+
 /*
  * exec_setregs may initialize some registers differently than Linux
  * does, thus potentially confusing Linux binaries. If necessary, we
@@ -855,7 +868,7 @@ struct sysentvec linux_sysvec = {
 	.sv_fixlimit	= NULL,
 	.sv_maxssiz	= NULL,
 	.sv_flags	= SV_ABI_LINUX | SV_AOUT | SV_IA32 | SV_ILP32,
-	.sv_set_syscall_retval = cpu_set_syscall_retval,
+	.sv_set_syscall_retval = linux_set_syscall_retval,
 	.sv_fetch_syscall_args = linux_fetch_syscall_args,
 	.sv_syscallnames = NULL,
 	.sv_shared_page_base = LINUX_SHAREDPAGE,
@@ -891,7 +904,7 @@ struct sysentvec elf_linux_sysvec = {
 	.sv_fixlimit	= NULL,
 	.sv_maxssiz	= NULL,
 	.sv_flags	= SV_ABI_LINUX | SV_IA32 | SV_ILP32 | SV_SHP,
-	.sv_set_syscall_retval = cpu_set_syscall_retval,
+	.sv_set_syscall_retval = linux_set_syscall_retval,
 	.sv_fetch_syscall_args = linux_fetch_syscall_args,
 	.sv_syscallnames = NULL,
 	.sv_shared_page_base = LINUX_SHAREDPAGE,

Modified: head/sys/powerpc/powerpc/exec_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/exec_machdep.c	Tue Sep 15 16:38:44 2020	(r365754)
+++ head/sys/powerpc/powerpc/exec_machdep.c	Tue Sep 15 16:41:21 2020	(r365755)
@@ -955,7 +955,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
 		tf->srr0 -= 4;
 		break;
 	default:
-		tf->fixreg[FIRSTARG] = SV_ABI_ERRNO(p, error);
+		tf->fixreg[FIRSTARG] = error;
 		tf->cr |= 0x10000000;		/* Set summary overflow */
 		break;
 	}


More information about the svn-src-head mailing list