Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/amd64/amd64 don't cast void *



details:   https://anonhg.NetBSD.org/src/rev/960229fe7fd4
branches:  trunk
changeset: 452316:960229fe7fd4
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 27 01:59:30 2019 +0000

description:
don't cast void *

diffstat:

 sys/arch/amd64/amd64/machdep.c         |  28 +++++++++++++++++-----------
 sys/arch/amd64/amd64/process_machdep.c |   7 +++----
 2 files changed, 20 insertions(+), 15 deletions(-)

diffs (106 lines):

diff -r 93949f250a2a -r 960229fe7fd4 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Thu Jun 27 01:58:49 2019 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Thu Jun 27 01:59:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.332 2019/06/12 14:28:38 christos Exp $   */
+/*     $NetBSD: machdep.c,v 1.333 2019/06/27 01:59:30 christos Exp $   */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.332 2019/06/12 14:28:38 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.333 2019/06/27 01:59:30 christos Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -2095,44 +2095,50 @@
 int
 cpu_mcontext_validate(struct lwp *l, const mcontext_t *mcp)
 {
-       struct proc *p __diagused = l->l_proc;
+       struct proc *p = l->l_proc;
        struct trapframe *tf = l->l_md.md_regs;
        const __greg_t *gr;
        uint16_t sel;
+       const bool pk32 = (p->p_flag & PK_32) != 0;
 
-       KASSERT((p->p_flag & PK_32) == 0);
        gr = mcp->__gregs;
 
        if (((gr[_REG_RFLAGS] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0)
                return EINVAL;
+#define VUD(sel) (pk32 ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel))
+#define VUF(sel) (pk32 ? (VALID_USER_DSEL32(sel) || VALID_USER_FSEL32(sel)) \
+    : VALID_USER_DSEL(sel))
+#define VUG(sel) (pk32 ? (VALID_USER_DSEL32(sel) || VALID_USER_GSEL32(sel)) \
+    : VALID_USER_DSEL(sel))
+#define VUC(sel) (pk32 ? VALID_USER_CSEL32(sel) : VALID_USER_CSEL(sel))
 
        sel = gr[_REG_ES] & 0xffff;
-       if (sel != 0 && !VALID_USER_DSEL(sel))
+       if (sel != 0 && !VUD(sel))
                return EINVAL;
 
        sel = gr[_REG_FS] & 0xffff;
-       if (sel != 0 && !VALID_USER_DSEL(sel))
+       if (sel != 0 && !VUF(sel))
                return EINVAL;
 
        sel = gr[_REG_GS] & 0xffff;
-       if (sel != 0 && !VALID_USER_DSEL(sel))
+       if (sel != 0 && !VUG(sel))
                return EINVAL;
 
        sel = gr[_REG_DS] & 0xffff;
-       if (!VALID_USER_DSEL(sel))
+       if (!VUD(sel))
                return EINVAL;
 
 #ifndef XENPV
        sel = gr[_REG_SS] & 0xffff;
-       if (!VALID_USER_DSEL(sel))
+       if (!VUD(sel))
                return EINVAL;
 
        sel = gr[_REG_CS] & 0xffff;
-       if (!VALID_USER_CSEL(sel))
+       if (!VUC(sel))
                return EINVAL;
 #endif
 
-       if (gr[_REG_RIP] >= VM_MAXUSER_ADDRESS)
+       if (gr[_REG_RIP] >= (pk32 ? VM_MAXUSER_ADDRESS32 : VM_MAXUSER_ADDRESS))
                return EINVAL;
 
        return 0;
diff -r 93949f250a2a -r 960229fe7fd4 sys/arch/amd64/amd64/process_machdep.c
--- a/sys/arch/amd64/amd64/process_machdep.c    Thu Jun 27 01:58:49 2019 +0000
+++ b/sys/arch/amd64/amd64/process_machdep.c    Thu Jun 27 01:59:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: process_machdep.c,v 1.40 2019/06/26 12:30:12 mgorny Exp $      */
+/*     $NetBSD: process_machdep.c,v 1.41 2019/06/27 01:59:30 christos Exp $    */
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.40 2019/06/26 12:30:12 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.41 2019/06/27 01:59:30 christos Exp $");
 
 #include "opt_xen.h"
 #include <sys/param.h>
@@ -339,8 +339,7 @@
                if (!process_machdep_validxstate(lt->l_proc))
                        return EINVAL;
                if (__predict_false(l->l_proc->p_flag & PK_32)) {
-                       struct netbsd32_iovec *user_iov;
-                       user_iov = (struct netbsd32_iovec*)addr;
+                       struct netbsd32_iovec *user_iov = addr;
                        iov.iov_base = NETBSD32PTR64(user_iov->iov_base);
                        iov.iov_len = user_iov->iov_len;
                } else {



Home | Main Index | Thread Index | Old Index