Module Name:    src
Committed By:   alnsn
Date:           Mon Oct  1 21:34:03 UTC 2012

Modified Files:
        src/external/bsd/sljit/dist/sljit_src: sljitConfig.h
            sljitConfigInternal.h sljitUtils.c

Log Message:
Adapt code to compile with -D_KERNEL.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \
    src/external/bsd/sljit/dist/sljit_src/sljitConfig.h \
    src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h \
    src/external/bsd/sljit/dist/sljit_src/sljitUtils.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/sljit/dist/sljit_src/sljitConfig.h
diff -u src/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.1.1.1 src/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.2
--- src/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.1.1.1	Mon Oct  1 21:16:45 2012
+++ src/external/bsd/sljit/dist/sljit_src/sljitConfig.h	Mon Oct  1 21:34:03 2012
@@ -47,6 +47,7 @@
 /* #define SLJIT_CONFIG_PPC_32 1 */
 /* #define SLJIT_CONFIG_PPC_64 1 */
 /* #define SLJIT_CONFIG_MIPS_32 1 */
+#include <machine/sljitarch.h>
 
 /* #define SLJIT_CONFIG_AUTO 1 */
 /* #define SLJIT_CONFIG_UNSUPPORTED 1 */
@@ -88,20 +89,28 @@
    If SLJIT_EXECUTABLE_ALLOCATOR is not defined, the application should
    define both SLJIT_MALLOC_EXEC and SLJIT_FREE_EXEC. */
 #ifndef SLJIT_EXECUTABLE_ALLOCATOR
+#ifdef _KERNEL
+#define SLJIT_EXECUTABLE_ALLOCATOR 0
+#define SLJIT_MALLOC_EXEC(sz) SLJIT_MALLOC(sz)
+#define SLJIT_FREE_EXEC(ptr) SLJIT_FREE(ptr)
+#else
 /* Enabled by default. */
 #define SLJIT_EXECUTABLE_ALLOCATOR 1
 #endif
+#endif
 
 /* Debug checks (assertions, etc.). */
 #ifndef SLJIT_DEBUG
-/* Enabled by default */
+#if defined(_KERNEL) && defined(DIAGNOSTIC)
 #define SLJIT_DEBUG 1
+#else
+#define SLJIT_DEBUG 0
+#endif
 #endif
 
 /* Verbose operations */
 #ifndef SLJIT_VERBOSE
-/* Enabled by default */
-#define SLJIT_VERBOSE 1
+#define SLJIT_VERBOSE 0
 #endif
 
 /* See the beginning of sljitConfigInternal.h */
Index: src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h
diff -u src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.1.1.1 src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.2
--- src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.1.1.1	Mon Oct  1 21:16:44 2012
+++ src/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h	Mon Oct  1 21:34:03 2012
@@ -123,9 +123,14 @@
 
 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
 
+#ifdef _KERNEL
+#include <sys/cdefs.h>
+#include <sys/malloc.h>
+#else
 /* These libraries are needed for the macros below. */
 #include <stdlib.h>
 #include <string.h>
+#endif
 
 #endif /* STD_MACROS_DEFINED */
 
@@ -136,12 +141,20 @@
 */
 
 #ifndef SLJIT_MALLOC
+#ifdef _KERNEL
+#define SLJIT_MALLOC(size) malloc((size), M_TEMP, M_WAITOK)
+#else
 #define SLJIT_MALLOC(size) malloc(size)
 #endif
+#endif
 
 #ifndef SLJIT_FREE
+#ifdef _KERNEL
+#define SLJIT_FREE(ptr) free((ptr), M_TEMP)
+#else
 #define SLJIT_FREE(ptr) free(ptr)
 #endif
+#endif
 
 #ifndef SLJIT_MEMMOVE
 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
@@ -216,9 +229,18 @@
 
 #else
 
+#ifdef _KERNEL
+/*
+ * SLJIT_CACHE_FLUSH can be defined in <machine/sljitarch.h>
+ */
+#ifndef SLJIT_CACHE_FLUSH
+#define SLJIT_CACHE_FLUSH(from, to)
+#endif
+#else
 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
 #define SLJIT_CACHE_FLUSH(from, to) \
 	__clear_cache((char*)(from), (char*)(to))
+#endif
 
 #endif
 
@@ -378,8 +400,12 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free
 #endif
 
 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
+#ifdef _KERNEL
+#include <sys/systm.h>
+#else
 #include <stdio.h>
 #endif
+#endif
 
 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
 
Index: src/external/bsd/sljit/dist/sljit_src/sljitUtils.c
diff -u src/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.1.1.1 src/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.2
--- src/external/bsd/sljit/dist/sljit_src/sljitUtils.c:1.1.1.1	Mon Oct  1 21:16:42 2012
+++ src/external/bsd/sljit/dist/sljit_src/sljitUtils.c	Mon Oct  1 21:34:03 2012
@@ -104,7 +104,49 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL
 
 #endif /* SLJIT_UTIL_GLOBAL_LOCK */
 
-#else /* _WIN32 */
+#elif defined(_KERNEL) /* _WIN32 */
+
+#include <sys/mutex.h>
+
+#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
+
+/*
+ * Defined in sys/modules/sljit/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);
+}
+
+#endif /* SLJIT_EXECUTABLE_ALLOCATOR */
+
+#if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
+
+/*
+ * Defined in sys/modules/sljit/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);
+}
+
+#endif /* SLJIT_UTIL_GLOBAL_LOCK */
+
+#else /* _KERNEL */
 
 #include <pthread.h>
 
@@ -148,7 +190,10 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL
 
 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
 
-#ifdef _WIN32
+#ifdef _KERNEL
+#include <sys/param.h>
+#include <uvm/uvm.h>
+#elif defined(_WIN32)
 #include "windows.h"
 #else
 #include <sys/mman.h>
@@ -168,6 +213,9 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
 #ifdef _WIN32
 	SYSTEM_INFO si;
 #endif
+#ifdef _KERNEL
+	vaddr_t v;
+#endif
 
 	if (limit > max_limit || limit < 1)
 		return NULL;
@@ -179,7 +227,12 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
 	}
 #else
 	if (!sljit_page_align) {
-		sljit_page_align = sysconf(_SC_PAGESIZE);
+		sljit_page_align =
+#ifdef _KERNEL
+		    PAGE_SIZE;
+#else
+		    sysconf(_SC_PAGESIZE);
+#endif
 		/* Should never happen. */
 		if (sljit_page_align < 0)
 			sljit_page_align = 4096;
@@ -194,7 +247,17 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
 	if (!stack)
 		return NULL;
 
-#ifdef _WIN32
+#ifdef _KERNEL
+	v = uvm_km_alloc(kernel_map, max_limit, PAGE_SIZE, UVM_KMF_WIRED|UVM_KMF_ZERO);
+	base.ptr = (void *)v;
+	if (base.ptr == NULL) {
+		SLJIT_FREE(stack);
+		return NULL;
+	}
+	stack->base = base.uw;
+	stack->limit = stack->base + limit;
+	stack->max_limit = stack->base + max_limit;
+#elif defined(_WIN32)
 	base.ptr = VirtualAlloc(0, max_limit, MEM_RESERVE, PAGE_READWRITE);
 	if (!base.ptr) {
 		SLJIT_FREE(stack);
@@ -225,7 +288,10 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
 
 SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack)
 {
-#ifdef _WIN32
+#ifdef _KERNEL
+	uvm_km_free(kernel_map, (vaddr_t)stack->base,
+	    stack->max_limit - stack->base, UVM_KMF_WIRED);
+#elif defined(_WIN32)
 	VirtualFree((void*)stack->base, 0, MEM_RELEASE);
 #else
 	munmap((void*)stack->base, stack->max_limit - stack->base);

Reply via email to