switch sh port's __unmapself to generic version when running on sh2/nommu
authorRich Felker <dalias@aerifal.cx>
Tue, 16 Jun 2015 14:55:06 +0000 (14:55 +0000)
committerRich Felker <dalias@aerifal.cx>
Tue, 16 Jun 2015 14:55:06 +0000 (14:55 +0000)
due to the way the interrupt and syscall trap mechanism works,
userspace on sh2 must never set the stack pointer to an invalid value.
thus, the approach used on most archs, where __unmapself executes with
no stack for the interval between SYS_munmap and SYS_exit, is not
viable on sh2.

in order not to pessimize sh3/sh4, the sh asm version of __unmapself
is not removed. instead it's renamed and redirected through code that
calls either the generic (safe) __unmapself or the sh3/sh4 asm,
depending on compile-time and run-time conditions.

arch/sh/src/__unmapself.c [new file with mode: 0644]
src/thread/sh/__unmapself.s

diff --git a/arch/sh/src/__unmapself.c b/arch/sh/src/__unmapself.c
new file mode 100644 (file)
index 0000000..4df9e7b
--- /dev/null
@@ -0,0 +1,19 @@
+#include "pthread_impl.h"
+
+void __unmapself_sh_mmu(void *, size_t);
+void __unmapself_sh_nommu(void *, size_t);
+
+#if !defined(__SH3__) && !defined(__SH4__)
+#define __unmapself __unmapself_sh_nommu
+#include "../../../src/thread/__unmapself.c"
+#undef __unmapself
+extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
+#else
+#define __sh_nommu 0
+#endif
+
+void __unmapself(void *base, size_t size)
+{
+       if (__sh_nommu) __unmapself_sh_nommu(base, size);
+       else __unmapself_sh_mmu(base, size);
+}
index b34c3c804de0432184a7133ebedf3110ad329c79..cad91bf60b32041deb471b80f4ff2f6cd8484f9c 100644 (file)
@@ -1,7 +1,7 @@
 .text
-.global __unmapself
-.type   __unmapself, @function
-__unmapself:
+.global __unmapself_sh_mmu
+.type   __unmapself_sh_mmu, @function
+__unmapself_sh_mmu:
        mov   #91, r3  ! SYS_munmap
        trapa #18