Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/sljit Turn on executable allocator an use m...



details:   https://anonhg.NetBSD.org/src/rev/7763e5dc4791
branches:  trunk
changeset: 325315:7763e5dc4791
user:      alnsn <alnsn%NetBSD.org@localhost>
date:      Tue Dec 17 22:39:23 2013 +0000

description:
Turn on executable allocator an use module_map with UVM_KMF_EXEC flag.

This should fix execution of code generated by librumpkern_sljit.
Also enable global lock.

diffstat:

 sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h        |   6 --
 sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c |  15 +++++
 sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c         |  38 ++++++++++++++
 sys/external/bsd/sljit/sljit/sljit_mod.c                   |  12 +++-
 4 files changed, 63 insertions(+), 8 deletions(-)

diffs (162 lines):

diff -r 3815955e6f56 -r 7763e5dc4791 sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h
--- a/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h       Tue Dec 17 22:14:24 2013 +0000
+++ b/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h       Tue Dec 17 22:39:23 2013 +0000
@@ -66,12 +66,6 @@
 #error "SLJIT_CACHE_FLUSH must be defined."
 #endif
 
-#if defined(_KERNEL)
-#define SLJIT_UTIL_GLOBAL_LOCK 0
-#define SLJIT_EXECUTABLE_ALLOCATOR 0
-#define SLJIT_MALLOC_EXEC(sz) SLJIT_MALLOC(sz)
-#define SLJIT_FREE_EXEC(ptr) SLJIT_FREE(ptr)
-#endif
 
 #ifdef _KERNEL
 
diff -r 3815955e6f56 -r 7763e5dc4791 sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c
--- a/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c        Tue Dec 17 22:14:24 2013 +0000
+++ b/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c        Tue Dec 17 22:39:23 2013 +0000
@@ -94,17 +94,32 @@
 
 #else
 
+#ifdef _KERNEL
+#include <sys/param.h>
+#include <sys/module.h> /* for module_map */
+#include <uvm/uvm.h>
+#else
 #include <sys/mman.h>
+#endif
 
 static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
 {
+#ifdef _KERNEL
+       return (void *)uvm_km_alloc(module_map, size,
+           PAGE_SIZE, UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_EXEC);
+#else
        void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
        return (retval != MAP_FAILED) ? retval : NULL;
+#endif
 }
 
 static SLJIT_INLINE void free_chunk(void* chunk, sljit_uw size)
 {
+#ifdef _KERNEL
+       uvm_km_free(module_map, (vaddr_t)chunk, size, UVM_KMF_WIRED);
+#else
        munmap(chunk, size);
+#endif
 }
 
 #endif
diff -r 3815955e6f56 -r 7763e5dc4791 sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c
--- a/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c        Tue Dec 17 22:14:24 2013 +0000
+++ b/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c        Tue Dec 17 22:39:23 2013 +0000
@@ -108,6 +108,24 @@
 
 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
 
+#ifdef _KERNEL
+
+#include <sys/mutex.h>
+
+/* Defined in sljit_mod.c */
+extern kmutex_t sljit_allocator_mutex;
+
+static SLJIT_INLINE void allocator_grab_lock(void)
+{
+       mutex_enter(&sljit_allocator_mutex);
+}
+
+static SLJIT_INLINE void allocator_release_lock(void)
+{
+       mutex_exit(&sljit_allocator_mutex);
+}
+#else
+
 #include <pthread.h>
 
 static pthread_mutex_t allocator_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -121,11 +139,30 @@
 {
        pthread_mutex_unlock(&allocator_mutex);
 }
+#endif
 
 #endif /* SLJIT_EXECUTABLE_ALLOCATOR */
 
 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
 
+#ifdef _KERNEL
+
+#include <sys/mutex.h>
+
+/* Defined in sljit_mod.c */
+extern kmutex_t sljit_global_mutex;
+
+SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void)
+{
+       mutex_enter(&sljit_global_mutex);
+}
+
+SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void)
+{
+       mutex_exit(&sljit_global_mutex);
+}
+#else
+
 #include <pthread.h>
 
 static pthread_mutex_t global_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -139,6 +176,7 @@
 {
        pthread_mutex_unlock(&global_mutex);
 }
+#endif
 
 #endif /* SLJIT_UTIL_GLOBAL_LOCK */
 
diff -r 3815955e6f56 -r 7763e5dc4791 sys/external/bsd/sljit/sljit/sljit_mod.c
--- a/sys/external/bsd/sljit/sljit/sljit_mod.c  Tue Dec 17 22:14:24 2013 +0000
+++ b/sys/external/bsd/sljit/sljit/sljit_mod.c  Tue Dec 17 22:39:23 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sljit_mod.c,v 1.1 2012/10/22 21:21:07 christos Exp $   */
+/*     $NetBSD: sljit_mod.c,v 1.2 2013/12/17 22:39:23 alnsn Exp $      */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -27,14 +27,18 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sljit_mod.c,v 1.1 2012/10/22 21:21:07 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sljit_mod.c,v 1.2 2013/12/17 22:39:23 alnsn Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
+#include <sys/mutex.h>
 
 MODULE(MODULE_CLASS_MISC, sljit, NULL)
 
+/* Used in sljitUtils.c */
+kmutex_t sljit_allocator_mutex;
+kmutex_t sljit_global_mutex;
 
 static int
 sljit_modcmd(modcmd_t cmd, void *arg)
@@ -42,9 +46,13 @@
 
        switch (cmd) {
        case MODULE_CMD_INIT:
+               mutex_init(&sljit_allocator_mutex, MUTEX_DEFAULT, IPL_NONE);
+               mutex_init(&sljit_global_mutex, MUTEX_DEFAULT, IPL_NONE);
                return 0;
 
        case MODULE_CMD_FINI:
+               mutex_destroy(&sljit_global_mutex);
+               mutex_destroy(&sljit_allocator_mutex);
                return EOPNOTSUPP;
 
        default:



Home | Main Index | Thread Index | Old Index