Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 May 2020 14:53:08 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r360874 - in stable/12/sys: arm64/arm64 riscv/riscv
Message-ID:  <202005101453.04AEr8NP004304@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Sun May 10 14:53:08 2020
New Revision: 360874
URL: https://svnweb.freebsd.org/changeset/base/360874

Log:
  MFC 356839: 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().

Modified:
  stable/12/sys/arm64/arm64/machdep.c
  stable/12/sys/riscv/riscv/machdep.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/arm64/arm64/machdep.c
==============================================================================
--- stable/12/sys/arm64/arm64/machdep.c	Sun May 10 14:46:46 2020	(r360873)
+++ stable/12/sys/arm64/arm64/machdep.c	Sun May 10 14:53:08 2020	(r360874)
@@ -95,6 +95,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;
 
@@ -385,6 +387,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);
 }
@@ -406,6 +409,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);
 }
@@ -577,15 +581,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);
@@ -657,7 +658,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.ss_flags = (td->td_pflags & TDP_ALTSTACK) ?

Modified: stable/12/sys/riscv/riscv/machdep.c
==============================================================================
--- stable/12/sys/riscv/riscv/machdep.c	Sun May 10 14:46:46 2020	(r360873)
+++ stable/12/sys/riscv/riscv/machdep.c	Sun May 10 14:53:08 2020	(r360874)
@@ -95,6 +95,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;
@@ -350,6 +353,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);
 }
@@ -370,6 +374,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);
 }
@@ -519,8 +524,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);
 
@@ -537,8 +540,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);
 
@@ -606,7 +607,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.ss_flags = (td->td_pflags & TDP_ALTSTACK) ?



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