Mesa (master): mapi/glapi: Don' t allocate a page for every function on windows.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Fri May 7 06:31:53 UTC 2010


Module: Mesa
Branch: master
Commit: 5065d3327617977c93e5ced5eefafc8f62310012
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5065d3327617977c93e5ced5eefafc8f62310012

Author: José Fonseca <jfonseca at vmware.com>
Date:   Fri May  7 07:31:44 2010 +0100

mapi/glapi: Don't allocate a page for every function on windows.

---

 src/mapi/mapi/u_execmem.c |   75 ++++++++++++++++++++++++---------------------
 src/mapi/mapi/u_thread.h  |    3 +-
 2 files changed, 42 insertions(+), 36 deletions(-)

diff --git a/src/mapi/mapi/u_execmem.c b/src/mapi/mapi/u_execmem.c
index fae2c75..00df830 100644
--- a/src/mapi/mapi/u_execmem.c
+++ b/src/mapi/mapi/u_execmem.c
@@ -37,6 +37,15 @@
 #include "u_execmem.h"
 
 
+#define EXEC_MAP_SIZE (4*1024)
+
+u_mutex_declare_static(exec_mutex);
+
+static unsigned int head = 0;
+
+static unsigned char *exec_mem = (unsigned char *)0;
+
+
 #if defined(__linux__) || defined(__OpenBSD__) || defined(_NetBSD__) || defined(__sun)
 
 #include <unistd.h>
@@ -52,15 +61,6 @@
 #endif
 
 
-#define EXEC_MAP_SIZE (4*1024)
-
-u_mutex_declare_static(exec_mutex);
-
-static unsigned int head = 0;
-
-static unsigned char *exec_mem = NULL;
-
-
 /*
  * Dispatch stubs are of fixed size and never freed. Thus, we do not need to
  * overlay a heap, we just mmap a page and manage through an index.
@@ -85,6 +85,37 @@ init_map(void)
 }
 
 
+#elif defined(_WIN32)
+
+#include <windows.h>
+
+
+/*
+ * Avoid Data Execution Prevention.
+ */
+
+static int
+init_map(void)
+{
+   exec_mem = VirtualAlloc(NULL, EXEC_MAP_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+
+   return (exec_mem != NULL);
+}
+
+
+#else
+
+static int
+init_map(void)
+{
+   exec_mem = malloc(EXEC_MAP_SIZE);
+
+   return (exec_mem != NULL);
+}
+
+
+#endif
+
 void *
 u_execmem_alloc(unsigned int size)
 {
@@ -110,29 +141,3 @@ bail:
 }
 
 
-#elif defined(_WIN32)
-
-#include <windows.h>
-
-
-/*
- * Avoid Data Execution Prevention.
- */
-
-void *
-u_execmem_alloc(unsigned int size)
-{
-   return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-}
-
-
-#else
-
-void *
-u_execmem_alloc(unsigned int size)
-{
-   return malloc(size);
-}
-
-
-#endif
diff --git a/src/mapi/mapi/u_thread.h b/src/mapi/mapi/u_thread.h
index 992dbaa..b4487a3 100644
--- a/src/mapi/mapi/u_thread.h
+++ b/src/mapi/mapi/u_thread.h
@@ -95,8 +95,9 @@ struct u_tsd {
 
 typedef CRITICAL_SECTION u_mutex;
 
+/* http://locklessinc.com/articles/pthreads_on_windows/ */
 #define u_mutex_declare_static(name) \
-   /* static */ u_mutex name = { 0, 0, 0, 0, 0, 0 }
+   /* static */ u_mutex name = {(void*)-1, -1, 0, 0, 0, 0}
 
 #define u_mutex_init(name)    InitializeCriticalSection(&name)
 #define u_mutex_destroy(name) DeleteCriticalSection(&name)




More information about the mesa-commit mailing list