Module Name: src Committed By: alnsn Date: Tue Dec 17 22:39:23 UTC 2013
Modified Files: src/sys/external/bsd/sljit/dist/sljit_src: sljitConfig.h sljitExecAllocator.c sljitUtils.c src/sys/external/bsd/sljit/sljit: sljit_mod.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 \ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h cvs rdiff -u -r1.1.1.1 -r1.2 \ src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c cvs rdiff -u -r1.2 -r1.3 \ src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/sljit/sljit/sljit_mod.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.7 src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.8 --- src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.7 Mon Nov 18 07:13:13 2013 +++ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h Tue Dec 17 22:39:23 2013 @@ -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 Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.1.1.1 src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.2 --- src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.1.1.1 Sat Oct 6 18:24:25 2012 +++ src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c Tue Dec 17 22:39:23 2013 @@ -94,17 +94,32 @@ static SLJIT_INLINE void free_chunk(void #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 Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.2 src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.3 --- src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.2 Sat Oct 6 19:23:01 2012 +++ src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c Tue Dec 17 22:39:23 2013 @@ -108,6 +108,24 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL #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 @@ static SLJIT_INLINE void allocator_relea { 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 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL { pthread_mutex_unlock(&global_mutex); } +#endif #endif /* SLJIT_UTIL_GLOBAL_LOCK */ Index: src/sys/external/bsd/sljit/sljit/sljit_mod.c diff -u src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.1 src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.2 --- src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.1 Mon Oct 22 21:21:07 2012 +++ src/sys/external/bsd/sljit/sljit/sljit_mod.c Tue Dec 17 22:39:23 2013 @@ -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 @@ sljit_modcmd(modcmd_t cmd, void *arg) 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: