[Midnightbsd-cvs] src [10178] trunk/sys/amd64/ia32/ia32_syscall.c: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jun 1 19:00:27 EDT 2018
Revision: 10178
http://svnweb.midnightbsd.org/src/?rev=10178
Author: laffer1
Date: 2018-06-01 19:00:27 -0400 (Fri, 01 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/sys/amd64/ia32/ia32_exception.S
trunk/sys/amd64/ia32/ia32_misc.c
trunk/sys/amd64/ia32/ia32_reg.c
trunk/sys/amd64/ia32/ia32_signal.c
trunk/sys/amd64/ia32/ia32_sigtramp.S
trunk/sys/amd64/ia32/ia32_syscall.c
Property Changed:
----------------
trunk/sys/amd64/ia32/ia32_exception.S
trunk/sys/amd64/ia32/ia32_sigtramp.S
Modified: trunk/sys/amd64/ia32/ia32_exception.S
===================================================================
--- trunk/sys/amd64/ia32/ia32_exception.S 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_exception.S 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Peter Wemm
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/amd64/ia32/ia32_exception.S 220451 2011-04-08 13:30:48Z jhb $
*/
#include <machine/asmacros.h>
Property changes on: trunk/sys/amd64/ia32/ia32_exception.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/amd64/ia32/ia32_misc.c
===================================================================
--- trunk/sys/amd64/ia32/ia32_misc.c 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_misc.c 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2009 Konstantin Belousov
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/amd64/ia32/ia32_misc.c 220238 2011-04-01 11:16:29Z kib $");
#include "opt_compat.h"
Modified: trunk/sys/amd64/ia32/ia32_reg.c
===================================================================
--- trunk/sys/amd64/ia32/ia32_reg.c 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_reg.c 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2005 Peter Wemm
* All rights reserved.
@@ -23,11 +24,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/amd64/ia32/ia32_reg.c 320525 2017-07-01 03:38:12Z kib $
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/amd64/ia32/ia32_reg.c 320525 2017-07-01 03:38:12Z kib $");
#include "opt_compat.h"
@@ -65,7 +66,6 @@
#include <compat/freebsd32/freebsd32_util.h>
#include <compat/freebsd32/freebsd32_proto.h>
#include <machine/fpu.h>
-#include <compat/ia32/ia32_reg.h>
#include <machine/psl.h>
#include <machine/segments.h>
#include <machine/specialreg.h>
@@ -80,11 +80,9 @@
int
fill_regs32(struct thread *td, struct reg32 *regs)
{
- struct pcb *pcb;
struct trapframe *tp;
tp = td->td_frame;
- pcb = td->td_pcb;
if (tp->tf_flags & TF_HASSEGS) {
regs->r_gs = tp->tf_gs;
regs->r_fs = tp->tf_fs;
@@ -114,18 +112,16 @@
int
set_regs32(struct thread *td, struct reg32 *regs)
{
- struct pcb *pcb;
struct trapframe *tp;
tp = td->td_frame;
if (!EFL_SECURE(regs->r_eflags, tp->tf_rflags) || !CS_SECURE(regs->r_cs))
return (EINVAL);
- pcb = td->td_pcb;
tp->tf_gs = regs->r_gs;
tp->tf_fs = regs->r_fs;
tp->tf_es = regs->r_es;
tp->tf_ds = regs->r_ds;
- set_pcb_flags(pcb, PCB_FULL_IRET);
+ set_pcb_flags(td->td_pcb, PCB_FULL_IRET);
tp->tf_flags = TF_HASSEGS;
tp->tf_rdi = regs->r_edi;
tp->tf_rsi = regs->r_esi;
@@ -161,7 +157,7 @@
/* FPU control/status */
penv_87->en_cw = penv_xmm->en_cw;
penv_87->en_sw = penv_xmm->en_sw;
- penv_87->en_tw = penv_xmm->en_tw;
+
/*
* XXX for en_fip/fcs/foo/fos, check if the fxsave format
* uses the old-style layout for 32 bit user apps. If so,
@@ -175,9 +171,13 @@
/* Entry into the kernel always sets TF_HASSEGS */
penv_87->en_fos = td->td_frame->tf_ds;
- /* FPU registers */
- for (i = 0; i < 8; ++i)
+ /* FPU registers and tags */
+ penv_87->en_tw = 0xffff;
+ for (i = 0; i < 8; ++i) {
sv_87->sv_ac[i] = sv_fpu->sv_fp[i].fp_acc;
+ if ((penv_xmm->en_tw & (1 << i)) != 0)
+ penv_87->en_tw &= ~(3 << i * 2);
+ }
return (0);
}
@@ -194,15 +194,19 @@
/* FPU control/status */
penv_xmm->en_cw = penv_87->en_cw;
penv_xmm->en_sw = penv_87->en_sw;
- penv_xmm->en_tw = penv_87->en_tw;
penv_xmm->en_rip = penv_87->en_fip;
/* penv_87->en_fcs and en_fos ignored, see above */
penv_xmm->en_opcode = penv_87->en_opcode;
penv_xmm->en_rdp = penv_87->en_foo;
- /* FPU registers */
- for (i = 0; i < 8; ++i)
+ /* FPU registers and tags */
+ penv_xmm->en_tw = 0;
+ for (i = 0; i < 8; ++i) {
sv_fpu->sv_fp[i].fp_acc = sv_87->sv_ac[i];
+ if ((penv_87->en_tw & (3 << i * 2)) != (3 << i * 2))
+ penv_xmm->en_tw |= 1 << i;
+ }
+
for (i = 8; i < 16; ++i)
bzero(&sv_fpu->sv_fp[i].fp_acc, sizeof(sv_fpu->sv_fp[i].fp_acc));
fpuuserinited(td);
Modified: trunk/sys/amd64/ia32/ia32_signal.c
===================================================================
--- trunk/sys/amd64/ia32/ia32_signal.c 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_signal.c 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Peter Wemm
* Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
@@ -32,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/amd64/ia32/ia32_signal.c 293581 2016-01-09 17:39:41Z dchagin $");
#include "opt_compat.h"
@@ -118,7 +119,7 @@
}
static int
-ia32_set_fpcontext(struct thread *td, const struct ia32_mcontext *mcp,
+ia32_set_fpcontext(struct thread *td, struct ia32_mcontext *mcp,
char *xfpustate, size_t xfpustate_len)
{
int error;
@@ -197,7 +198,7 @@
* touch the cs selector.
*/
static int
-ia32_set_mcontext(struct thread *td, const struct ia32_mcontext *mcp)
+ia32_set_mcontext(struct thread *td, struct ia32_mcontext *mcp)
{
struct trapframe *tp;
char *xfpustate;
@@ -360,10 +361,6 @@
} else
fp = (struct ia32_sigframe3 *)regs->tf_rsp - 1;
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
/* Build the argument list for the signal handler. */
sf.sf_signum = sig;
sf.sf_scp = (register_t)&fp->sf_siginfo.si_sc;
@@ -498,10 +495,6 @@
sfp = (struct ia32_sigframe4 *)regs->tf_rsp - 1;
PROC_UNLOCK(p);
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
/* Build the argument list for the signal handler. */
sf.sf_signum = sig;
sf.sf_ucontext = (register_t)&sfp->sf_uc;
@@ -643,10 +636,6 @@
sfp = (struct ia32_sigframe *)((uintptr_t)sp & ~0xF);
PROC_UNLOCK(p);
- /* Translate the signal if appropriate. */
- if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
- sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
-
/* Build the argument list for the signal handler. */
sf.sf_signum = sig;
sf.sf_ucontext = (register_t)&sfp->sf_uc;
@@ -719,7 +708,7 @@
return (error);
scp = ≻
eflags = scp->sc_eflags;
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) {
+ if (!EFL_SECURE(eflags, regs->tf_rflags)) {
return (EINVAL);
}
if (!CS_SECURE(scp->sc_cs)) {
@@ -787,17 +776,7 @@
/*
* Don't allow users to change privileged or reserved flags.
*/
- /*
- * XXX do allow users to change the privileged flag PSL_RF.
- * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
- * should sometimes set it there too. tf_eflags is kept in
- * the signal context during signal handling and there is no
- * other place to remember it, so the PSL_RF bit may be
- * corrupted by the signal handler without us knowing.
- * Corruption of the PSL_RF bit at worst causes one more or
- * one less debugger trap, so allowing it is fairly harmless.
- */
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) {
+ if (!EFL_SECURE(eflags, regs->tf_rflags)) {
uprintf("pid %d (%s): freebsd4_freebsd32_sigreturn eflags = 0x%x\n",
td->td_proc->p_pid, td->td_name, eflags);
return (EINVAL);
@@ -873,17 +852,7 @@
/*
* Don't allow users to change privileged or reserved flags.
*/
- /*
- * XXX do allow users to change the privileged flag PSL_RF.
- * The cpu sets PSL_RF in tf_eflags for faults. Debuggers
- * should sometimes set it there too. tf_eflags is kept in
- * the signal context during signal handling and there is no
- * other place to remember it, so the PSL_RF bit may be
- * corrupted by the signal handler without us knowing.
- * Corruption of the PSL_RF bit at worst causes one more or
- * one less debugger trap, so allowing it is fairly harmless.
- */
- if (!EFL_SECURE(eflags & ~PSL_RF, regs->tf_rflags & ~PSL_RF)) {
+ if (!EFL_SECURE(eflags, regs->tf_rflags)) {
uprintf("pid %d (%s): freebsd32_sigreturn eflags = 0x%x\n",
td->td_proc->p_pid, td->td_name, eflags);
return (EINVAL);
Modified: trunk/sys/amd64/ia32/ia32_sigtramp.S
===================================================================
--- trunk/sys/amd64/ia32/ia32_sigtramp.S 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_sigtramp.S 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Peter Wemm
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/amd64/ia32/ia32_sigtramp.S 276601 2015-01-03 01:41:10Z kib $
*/
#include "opt_compat.h"
@@ -86,34 +87,14 @@
* executed, we would have a window where the ring 0 code is
* executed with the wrong gsbase.
*
- * Instead, reflect the lcall $7,$0 back to ring 3 trampoline
- * which sets up the frame for int $0x80.
+ * Instead, set LDT descriptor 0 as code segment, which reflects
+ * the lcall $7,$0 back to ring 3 trampoline. The trampoline sets up
+ * the frame for int $0x80.
*/
ALIGN_TEXT
lcall_tramp:
- .code64
- /*
- * There, we are in 64bit mode and need to return to 32bit.
- * First, convert call frame from 64 to 32 bit format.
- */
- pushq %rax
- movl 16(%rsp),%eax
- movl %eax,20(%rsp) /* ret %cs */
- movl 8(%rsp),%eax
- movl %eax,16(%rsp) /* ret %rip -> %eip */
- popq %rax
- addq $8,%rsp
- /* Now return to 32bit */
- pushq $0x33 /* _ucode32sel UPL */
- callq 1f
-1:
- addq $2f-1b,(%rsp)
- lretq
-2:
- /* Back in 32bit mode */
- .code32
cmpl $SYS_vfork,%eax
- je 4f
+ je 1f
pushl %ebp
movl %esp,%ebp
pushl 0x24(%ebp) /* arg 6 */
@@ -122,21 +103,20 @@
pushl 0x18(%ebp)
pushl 0x14(%ebp)
pushl 0x10(%ebp) /* arg 1 */
- pushl 0xc(%ebp) /* gap */
+ subl $4,%esp /* gap */
int $0x80
leavel
-3:
lretl
-4:
+1:
/*
* vfork handling is special and relies on the libc stub saving
- * the return ip in %ecx. If vfork failed, then there is no
- * child which can corrupt the frame created by call gate.
+ * the return ip in %ecx. Also, we assume that the call was done
+ * with ucode32 selector in %cs.
*/
int $0x80
- jb 3b
- addl $8,%esp
- jmpl *%ecx
+ movl $0x33,4(%esp) /* GUCODE32_SEL | SEL_UPL */
+ movl %ecx,(%esp)
+ lretl
#endif
ALIGN_TEXT
Property changes on: trunk/sys/amd64/ia32/ia32_sigtramp.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/amd64/ia32/ia32_syscall.c
===================================================================
--- trunk/sys/amd64/ia32/ia32_syscall.c 2018-06-01 23:00:12 UTC (rev 10177)
+++ trunk/sys/amd64/ia32/ia32_syscall.c 2018-06-01 23:00:27 UTC (rev 10178)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (C) 1994, David Greenman
* Copyright (c) 1990, 1993
@@ -36,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/amd64/ia32/ia32_syscall.c 276601 2015-01-03 01:41:10Z kib $");
/*
* 386 Trap and System call handling
@@ -110,7 +111,7 @@
struct proc *p;
struct trapframe *frame;
caddr_t params;
- u_int32_t args[8];
+ u_int32_t args[8], tmp;
int error, i;
p = td->td_proc;
@@ -126,7 +127,10 @@
/*
* Code is first argument, followed by actual args.
*/
- sa->code = fuword32(params);
+ error = fueword32(params, &tmp);
+ if (error == -1)
+ return (EFAULT);
+ sa->code = tmp;
params += sizeof(int);
} else if (sa->code == SYS___syscall) {
/*
@@ -135,7 +139,10 @@
* We use a 32-bit fetch in case params is not
* aligned.
*/
- sa->code = fuword32(params);
+ error = fueword32(params, &tmp);
+ if (error == -1)
+ return (EFAULT);
+ sa->code = tmp;
params += sizeof(quad_t);
}
if (p->p_sysent->sv_mask)
@@ -217,39 +224,28 @@
setup_lcall_gate(void)
{
struct i386_ldt_args uap;
- struct user_segment_descriptor descs[2];
- struct gate_descriptor *ssd;
+ struct user_segment_descriptor desc;
uint32_t lcall_addr;
int error;
bzero(&uap, sizeof(uap));
uap.start = 0;
- uap.num = 2;
-
- /*
- * This is the easiest way to cut the space for system
- * descriptor in ldt. Manually adjust the descriptor type to
- * the call gate later.
- */
- bzero(&descs[0], sizeof(descs));
- descs[0].sd_type = SDT_SYSNULL;
- descs[1].sd_type = SDT_SYSNULL;
- error = amd64_set_ldt(curthread, &uap, descs);
+ uap.num = 1;
+ lcall_addr = curproc->p_sysent->sv_psstrings - sz_lcall_tramp;
+ bzero(&desc, sizeof(desc));
+ desc.sd_type = SDT_MEMERA;
+ desc.sd_dpl = SEL_UPL;
+ desc.sd_p = 1;
+ desc.sd_def32 = 1;
+ desc.sd_gran = 1;
+ desc.sd_lolimit = 0xffff;
+ desc.sd_hilimit = 0xf;
+ desc.sd_lobase = lcall_addr;
+ desc.sd_hibase = lcall_addr >> 24;
+ error = amd64_set_ldt(curthread, &uap, &desc);
if (error != 0)
return (error);
- lcall_addr = curproc->p_sysent->sv_psstrings - sz_lcall_tramp;
- mtx_lock(&dt_lock);
- ssd = (struct gate_descriptor *)(curproc->p_md.md_ldt->ldt_base);
- bzero(ssd, sizeof(*ssd));
- ssd->gd_looffset = lcall_addr;
- ssd->gd_hioffset = lcall_addr >> 16;
- ssd->gd_selector = _ucodesel;
- ssd->gd_type = SDT_SYSCGT;
- ssd->gd_dpl = SEL_UPL;
- ssd->gd_p = 1;
- mtx_unlock(&dt_lock);
-
return (0);
}
#endif
More information about the Midnightbsd-cvs
mailing list