Created
April 13, 2015 08:23
-
-
Save kinoyasu/92cb2a5e6d6eae8e1c71 to your computer and use it in GitHub Desktop.
jemalloc-3.6.0-windows4prelink.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -rup jemalloc-3.6.0_orig/configure jemalloc-3.6.0/configure | |
--- jemalloc-3.6.0_orig/configure 2014-04-01 01:38:51 +0900 | |
+++ jemalloc-3.6.0/configure 2015-04-10 16:58:50 +0900 | |
@@ -3669,7 +3669,7 @@ $as_echo "no" >&6; } | |
fi | |
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext | |
- CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat" | |
+ CPPFLAGS="$CPPFLAGS -I${srcroot}include/msvc_compat" | |
fi | |
fi | |
if test "x$EXTRA_CFLAGS" != "x" ; then | |
@@ -5403,7 +5403,7 @@ fi | |
-public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size" | |
+public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size _msize" | |
ac_fn_c_check_func "$LINENO" "memalign" "ac_cv_func_memalign" | |
if test "x$ac_cv_func_memalign" = xyes; then : | |
diff -rup jemalloc-3.6.0_orig/configure.ac jemalloc-3.6.0/configure.ac | |
--- jemalloc-3.6.0_orig/configure.ac 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/configure.ac 2015-04-10 16:58:47 +0900 | |
@@ -141,7 +141,7 @@ if test "x$CFLAGS" = "x" ; then | |
JE_CFLAGS_APPEND([-Zi]) | |
JE_CFLAGS_APPEND([-MT]) | |
JE_CFLAGS_APPEND([-W3]) | |
- CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat" | |
+ CPPFLAGS="$CPPFLAGS -I${srcroot}include/msvc_compat" | |
fi | |
fi | |
dnl Append EXTRA_CFLAGS to CFLAGS, if defined. | |
@@ -428,7 +428,7 @@ AC_PROG_RANLIB | |
AC_PATH_PROG([LD], [ld], [false], [$PATH]) | |
AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH]) | |
-public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size" | |
+public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size _msize" | |
dnl Check for allocator-related functions that should be wrapped. | |
AC_CHECK_FUNC([memalign], | |
diff -rup jemalloc-3.6.0_orig/include/jemalloc/internal/arena.h jemalloc-3.6.0/include/jemalloc/internal/arena.h | |
--- jemalloc-3.6.0_orig/include/jemalloc/internal/arena.h 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/include/jemalloc/internal/arena.h 2015-04-10 17:00:20 +0900 | |
@@ -160,11 +160,18 @@ typedef rb_tree(arena_chunk_map_t) arena | |
typedef rb_tree(arena_chunk_map_t) arena_run_tree_t; | |
typedef ql_head(arena_chunk_map_t) arena_chunk_mapelms_t; | |
+#define JEMALLOC_MAGIC_N 0x6a656d616c6c6f63U | |
+ | |
/* Arena chunk header. */ | |
struct arena_chunk_s { | |
/* Arena that owns the chunk. */ | |
arena_t *arena; | |
+#ifdef _WIN32 | |
+ /* Magic Number */ | |
+ uint64_t magic; | |
+#endif | |
+ | |
/* Linkage for tree of arena chunks that contain dirty runs. */ | |
rb_node(arena_chunk_t) dirty_link; | |
diff -rup jemalloc-3.6.0_orig/include/jemalloc/jemalloc_protos.h.in jemalloc-3.6.0/include/jemalloc/jemalloc_protos.h.in | |
--- jemalloc-3.6.0_orig/include/jemalloc/jemalloc_protos.h.in 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/include/jemalloc/jemalloc_protos.h.in 2015-04-10 17:02:18 +0900 | |
@@ -7,15 +7,15 @@ extern JEMALLOC_EXPORT const char *@je_@ | |
extern JEMALLOC_EXPORT void (*@je_@malloc_message)(void *cbopaque, | |
const char *s); | |
-JEMALLOC_EXPORT void *@je_@malloc(size_t size) JEMALLOC_ATTR(malloc); | |
-JEMALLOC_EXPORT void *@je_@calloc(size_t num, size_t size) | |
- JEMALLOC_ATTR(malloc); | |
+//JEMALLOC_EXPORT void *@je_@malloc(size_t size) JEMALLOC_ATTR(malloc); | |
+//JEMALLOC_EXPORT void *@je_@calloc(size_t num, size_t size) | |
+// JEMALLOC_ATTR(malloc); | |
JEMALLOC_EXPORT int @je_@posix_memalign(void **memptr, size_t alignment, | |
size_t size) JEMALLOC_ATTR(nonnull(1)); | |
JEMALLOC_EXPORT void *@je_@aligned_alloc(size_t alignment, size_t size) | |
JEMALLOC_ATTR(malloc); | |
-JEMALLOC_EXPORT void *@je_@realloc(void *ptr, size_t size); | |
-JEMALLOC_EXPORT void @je_@free(void *ptr); | |
+//JEMALLOC_EXPORT void *@je_@realloc(void *ptr, size_t size); | |
+//JEMALLOC_EXPORT void @je_@free(void *ptr); | |
JEMALLOC_EXPORT void *@je_@mallocx(size_t size, int flags); | |
JEMALLOC_EXPORT void *@je_@rallocx(void *ptr, size_t size, int flags); | |
@@ -36,6 +36,8 @@ JEMALLOC_EXPORT void @je_@malloc_stats_p | |
JEMALLOC_EXPORT size_t @je_@malloc_usable_size( | |
JEMALLOC_USABLE_SIZE_CONST void *ptr); | |
+//JEMALLOC_EXPORT size_t @je_@_msize(void *ptr); | |
+ | |
#ifdef JEMALLOC_OVERRIDE_MEMALIGN | |
JEMALLOC_EXPORT void * @je_@memalign(size_t alignment, size_t size) | |
JEMALLOC_ATTR(malloc); | |
diff -rup jemalloc-3.6.0_orig/include/msvc_compat/stdbool.h jemalloc-3.6.0/include/msvc_compat/stdbool.h | |
--- jemalloc-3.6.0_orig/include/msvc_compat/stdbool.h 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/include/msvc_compat/stdbool.h 2015-04-07 15:48:33 +0900 | |
@@ -5,7 +5,9 @@ | |
/* MSVC doesn't define _Bool or bool in C, but does have BOOL */ | |
/* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ | |
+#if defined(_MSC_VER) && (_MSC_VER < 1700) | |
typedef BOOL _Bool; | |
+#endif | |
#define bool _Bool | |
#define true 1 | |
diff -rup jemalloc-3.6.0_orig/src/arena.c jemalloc-3.6.0/src/arena.c | |
--- jemalloc-3.6.0_orig/src/arena.c 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/src/arena.c 2015-04-10 17:03:09 +0900 | |
@@ -561,6 +561,10 @@ arena_chunk_init_hard(arena_t *arena) | |
if (config_stats) | |
arena->stats.mapped += chunksize; | |
+#ifdef _WIN32 | |
+ chunk->magic = JEMALLOC_MAGIC_N; | |
+#endif | |
+ | |
chunk->arena = arena; | |
/* | |
diff -rup jemalloc-3.6.0_orig/src/chunk.c jemalloc-3.6.0/src/chunk.c | |
--- jemalloc-3.6.0_orig/src/chunk.c 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/src/chunk.c 2015-04-10 17:04:43 +0900 | |
@@ -343,9 +343,9 @@ chunk_boot(void) | |
chunksize_mask = chunksize - 1; | |
chunk_npages = (chunksize >> LG_PAGE); | |
+ if (malloc_mutex_init(&chunks_mtx)) | |
+ return (true); | |
if (config_stats || config_prof) { | |
- if (malloc_mutex_init(&chunks_mtx)) | |
- return (true); | |
memset(&stats_chunks, 0, sizeof(chunk_stats_t)); | |
} | |
if (config_dss && chunk_dss_boot()) | |
diff -rup jemalloc-3.6.0_orig/src/jemalloc.c jemalloc-3.6.0/src/jemalloc.c | |
--- jemalloc-3.6.0_orig/src/jemalloc.c 2014-04-01 01:37:49 +0900 | |
+++ jemalloc-3.6.0/src/jemalloc.c 2015-04-10 17:06:34 +0900 | |
@@ -59,18 +59,9 @@ static bool malloc_initializer = NO_IN | |
#ifdef _WIN32 | |
static malloc_mutex_t init_lock; | |
-JEMALLOC_ATTR(constructor) | |
-static void WINAPI | |
-_init_init_lock(void) | |
-{ | |
- | |
- malloc_mutex_init(&init_lock); | |
-} | |
- | |
#ifdef _MSC_VER | |
-# pragma section(".CRT$XCU", read) | |
-JEMALLOC_SECTION(".CRT$XCU") JEMALLOC_ATTR(used) | |
-static const void (WINAPI *init_init_lock)(void) = _init_init_lock; | |
+/* 0 not yet; 1 initializing; 2 initialized */ | |
+static uint32_t init_lock_init = 0; | |
#endif | |
#else | |
@@ -651,6 +642,19 @@ malloc_init_hard(void) | |
{ | |
arena_t *init_arenas[1]; | |
+#if defined(_WIN32) && defined(_MSC_VER) | |
+ if (init_lock_init < 2) { | |
+ if (InterlockedCompareExchange(&init_lock_init, 1, 0) == 0) { | |
+ malloc_mutex_init(&init_lock); | |
+ init_lock_init = 2; | |
+ } else { | |
+ while (init_lock_init < 2) { | |
+ Sleep(100); | |
+ } | |
+ } | |
+ } | |
+#endif | |
+ | |
malloc_mutex_lock(&init_lock); | |
if (malloc_initialized || IS_INITIALIZER) { | |
/* | |
@@ -1221,6 +1225,30 @@ ifree(void *ptr) | |
assert(ptr != NULL); | |
assert(malloc_initialized || IS_INITIALIZER); | |
+#ifdef _WIN32 | |
+ { | |
+ bool marked = false; | |
+ bool exception = false; | |
+ arena_chunk_t *chunk; | |
+ | |
+ chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); | |
+ __try { | |
+ if (chunk->magic == JEMALLOC_MAGIC_N) { | |
+ marked = true; | |
+ } | |
+ } | |
+ __except(EXCEPTION_EXECUTE_HANDLER) { | |
+ exception = true; | |
+ } | |
+ | |
+ if (exception || (!marked && chunk != ptr)) { | |
+ //allocated by HeapAlloc() ? | |
+ HeapFree(_get_heap_handle(), 0, ptr); | |
+ return; | |
+ } | |
+ } | |
+#endif | |
+ | |
if (config_prof && opt_prof) { | |
usize = isalloc(ptr, config_prof); | |
prof_free(ptr, usize); | |
@@ -1242,6 +1270,29 @@ je_realloc(void *ptr, size_t size) | |
size_t old_usize = 0; | |
UNUSED size_t old_rzsize JEMALLOC_CC_SILENCE_INIT(0); | |
+#ifdef _WIN32 | |
+ if (ptr != NULL) { | |
+ bool marked = false; | |
+ bool exception = false; | |
+ arena_chunk_t *chunk; | |
+ | |
+ chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); | |
+ __try { | |
+ if (chunk->magic == JEMALLOC_MAGIC_N) { | |
+ marked = true; | |
+ } | |
+ } | |
+ __except(EXCEPTION_EXECUTE_HANDLER) { | |
+ exception = true; | |
+ } | |
+ | |
+ if (exception || (!marked && chunk != ptr)) { | |
+ //allocated by HeapAlloc() ? | |
+ return (HeapReAlloc(_get_heap_handle(), 0, ptr, size ? size : 1)); | |
+ } | |
+ } | |
+#endif | |
+ | |
if (size == 0) { | |
if (ptr != NULL) { | |
/* realloc(ptr, 0) is equivalent to free(ptr). */ | |
@@ -1315,6 +1366,34 @@ je_free(void *ptr) | |
/* | |
* Begin non-standard override functions. | |
*/ | |
+size_t | |
+je__msize(void *ptr) | |
+{ | |
+#ifdef _WIN32 | |
+ { | |
+ bool marked = false; | |
+ bool exception = false; | |
+ arena_chunk_t *chunk; | |
+ | |
+ chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); | |
+ __try { | |
+ if (chunk->magic == JEMALLOC_MAGIC_N) { | |
+ marked = true; | |
+ } | |
+ } | |
+ __except(EXCEPTION_EXECUTE_HANDLER) { | |
+ exception = true; | |
+ } | |
+ | |
+ if (exception || (!marked && chunk != ptr)) { | |
+ //allocated by HeapAlloc() ? | |
+ return ((size_t)HeapSize(_get_heap_handle(), 0, ptr)); | |
+ } | |
+ } | |
+#endif | |
+ | |
+ return(je_sallocx(ptr, 0)); | |
+} | |
#ifdef JEMALLOC_OVERRIDE_MEMALIGN | |
void * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment