Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64/aarch64 Fix clone(2) for COMPAT_NETBSD32.



details:   https://anonhg.NetBSD.org/src/rev/99c6c4e64383
branches:  trunk
changeset: 944903:99c6c4e64383
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Oct 15 22:52:08 2020 +0000

description:
Fix clone(2) for COMPAT_NETBSD32.

(1) Set r13 (sp for arm32 processes) appropriately when stack is
    specified to fork1().

(2) For arm32 processes, align stack to 8-byte boundary, instead of
    16-byte for native aarch64 processes, to match our 32-bit ABI:

https://nxr.netbsd.org/xref/src/sys/arch/arm/arm32/vm_machdep.c#150

Note that sp alignment checking is disabled in aarch32 mode, and
this works fine with AARCH64_EL0_STACK_ALIGNMENT_CHECK option.

OK ryo

diffstat:

 sys/arch/aarch64/aarch64/vm_machdep.c |  21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diffs (46 lines):

diff -r 7f02da0fa1e5 -r 99c6c4e64383 sys/arch/aarch64/aarch64/vm_machdep.c
--- a/sys/arch/aarch64/aarch64/vm_machdep.c     Thu Oct 15 22:41:02 2020 +0000
+++ b/sys/arch/aarch64/aarch64/vm_machdep.c     Thu Oct 15 22:52:08 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.8 2020/05/23 18:08:59 ryo Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.9 2020/10/15 22:52:08 rin Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_compat_netbsd32.h"
 #include "opt_ddb.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.8 2020/05/23 18:08:59 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.9 2020/10/15 22:52:08 rin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -143,11 +144,19 @@
        *utf = *l1->l_md.md_utf;
 
        /*
-        * If specified, give the child a different stack
-        * (make sure it's 16-byte aligned).
+        * If specified, give the child a different stack (make sure it's
+        * 16- or 8-byte aligned for 64- or 32-bit processes, respectively).
         */
-       if (stack != NULL)
-               utf->tf_sp = ((vaddr_t)(stack) + stacksize) & -16;
+       if (stack != NULL) {
+               utf->tf_sp = (vaddr_t)(stack) + stacksize;
+#ifdef COMPAT_NETBSD32
+               if (__predict_false(l2->l_proc->p_flag & PK_32)) {
+                       utf->tf_sp &= -8;
+                       utf->tf_reg[13] = utf->tf_sp;
+               } else
+#endif
+                       utf->tf_sp &= -16;
+       }
 
        /* build a new switchframe */
        struct trapframe * const ktf = utf - 1;



Home | Main Index | Thread Index | Old Index