Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jan 2020 19:01:59 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356839 - in head/sys: arm64/arm64 riscv/riscv
Message-ID:  <202001171901.00HJ1xeg027296@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Jan 17 19:01:59 2020
New Revision: 356839
URL: https://svnweb.freebsd.org/changeset/base/356839

Log:
  Save and restore floating point registers in get/set_mcontext().
  
  arm64 and riscv were only saving and restoring floating point
  registers for sendsig() and sys_sigreturn(), but not for getcontext(),
  setcontext(), and swapcontext().
  
  While here, remove an always-false check for uap being NULL from
  sys_sigreturn().
  
  Reviewed by:	br, mhorne
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D23218

Modified:
  head/sys/arm64/arm64/machdep.c
  head/sys/riscv/riscv/machdep.c

Modified: head/sys/arm64/arm64/machdep.c
==============================================================================
--- head/sys/arm64/arm64/machdep.c	Fri Jan 17 17:57:34 2020	(r356838)
+++ head/sys/arm64/arm64/machdep.c	Fri Jan 17 19:01:59 2020	(r356839)
@@ -98,6 +98,8 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/openfirm.h>
 #endif
 
+static void get_fpcontext(struct thread *td, mcontext_t *mcp);
+static void set_fpcontext(struct thread *td, mcontext_t *mcp);
 
 enum arm64_bus arm64_bus_method = ARM64_BUS_NONE;
 
@@ -473,6 +475,7 @@ get_mcontext(struct thread *td, mcontext_t *mcp, int c
 	mcp->mc_gpregs.gp_sp = tf->tf_sp;
 	mcp->mc_gpregs.gp_lr = tf->tf_lr;
 	mcp->mc_gpregs.gp_elr = tf->tf_elr;
+	get_fpcontext(td, mcp);
 
 	return (0);
 }
@@ -495,6 +498,7 @@ set_mcontext(struct thread *td, mcontext_t *mcp)
 	tf->tf_lr = mcp->mc_gpregs.gp_lr;
 	tf->tf_elr = mcp->mc_gpregs.gp_elr;
 	tf->tf_spsr = mcp->mc_gpregs.gp_spsr;
+	set_fpcontext(td, mcp);
 
 	return (0);
 }
@@ -667,15 +671,12 @@ sys_sigreturn(struct thread *td, struct sigreturn_args
 	ucontext_t uc;
 	int error;
 
-	if (uap == NULL)
-		return (EFAULT);
 	if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
 		return (EFAULT);
 
 	error = set_mcontext(td, &uc.uc_mcontext);
 	if (error != 0)
 		return (error);
-	set_fpcontext(td, &uc.uc_mcontext);
 
 	/* Restore signal mask. */
 	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
@@ -747,7 +748,6 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask
 	/* Fill in the frame to copy out */
 	bzero(&frame, sizeof(frame));
 	get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
-	get_fpcontext(td, &frame.sf_uc.uc_mcontext);
 	frame.sf_si = ksi->ksi_info;
 	frame.sf_uc.uc_sigmask = *mask;
 	frame.sf_uc.uc_stack = td->td_sigstk;

Modified: head/sys/riscv/riscv/machdep.c
==============================================================================
--- head/sys/riscv/riscv/machdep.c	Fri Jan 17 17:57:34 2020	(r356838)
+++ head/sys/riscv/riscv/machdep.c	Fri Jan 17 19:01:59 2020	(r356839)
@@ -99,6 +99,9 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/openfirm.h>
 #endif
 
+static void get_fpcontext(struct thread *td, mcontext_t *mcp);
+static void set_fpcontext(struct thread *td, mcontext_t *mcp);
+
 struct pcpu __pcpu[MAXCPU];
 
 static struct trapframe proc0_tf;
@@ -352,6 +355,7 @@ get_mcontext(struct thread *td, mcontext_t *mcp, int c
 	mcp->mc_gpregs.gp_tp = tf->tf_tp;
 	mcp->mc_gpregs.gp_sepc = tf->tf_sepc;
 	mcp->mc_gpregs.gp_sstatus = tf->tf_sstatus;
+	get_fpcontext(td, mcp);
 
 	return (0);
 }
@@ -372,6 +376,7 @@ set_mcontext(struct thread *td, mcontext_t *mcp)
 	tf->tf_gp = mcp->mc_gpregs.gp_gp;
 	tf->tf_sepc = mcp->mc_gpregs.gp_sepc;
 	tf->tf_sstatus = mcp->mc_gpregs.gp_sstatus;
+	set_fpcontext(td, mcp);
 
 	return (0);
 }
@@ -522,8 +527,6 @@ sys_sigreturn(struct thread *td, struct sigreturn_args
 	ucontext_t uc;
 	int error;
 
-	if (uap == NULL)
-		return (EFAULT);
 	if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
 		return (EFAULT);
 
@@ -540,8 +543,6 @@ sys_sigreturn(struct thread *td, struct sigreturn_args
 	if (error != 0)
 		return (error);
 
-	set_fpcontext(td, &uc.uc_mcontext);
-
 	/* Restore signal mask. */
 	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
 
@@ -612,7 +613,6 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask
 	/* Fill in the frame to copy out */
 	bzero(&frame, sizeof(frame));
 	get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
-	get_fpcontext(td, &frame.sf_uc.uc_mcontext);
 	frame.sf_si = ksi->ksi_info;
 	frame.sf_uc.uc_sigmask = *mask;
 	frame.sf_uc.uc_stack = td->td_sigstk;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001171901.00HJ1xeg027296>