diff --git a/memory/jemalloc/jemalloc.c b/memory/jemalloc/jemalloc.c --- a/memory/jemalloc/jemalloc.c +++ b/memory/jemalloc/jemalloc.c @@ -1830,19 +1830,16 @@ base_pages_alloc_mmap(size_t minsize) if (opt_pagefile) { pfd = pagefile_init(csize); if (pfd == -1) return (true); } else #endif pfd = -1; base_pages = pages_map(NULL, csize, pfd); -#ifdef MOZ_MEMORY_WINCE - pages_commit(base_pages, csize); -#endif if (base_pages == NULL) { ret = true; goto RETURN; } base_next_addr = base_pages; base_past_addr = (void *)((uintptr_t)base_pages + csize); #ifdef MALLOC_DECOMMIT /* @@ -2162,37 +2159,64 @@ rb_wrap(static, extent_tree_ad_, extent_ */ #ifdef MOZ_MEMORY_WINDOWS static void * pages_map(void *addr, size_t size, int pfd) { void *ret; #if defined(MOZ_MEMORY_WINCE) + size_t offset; + + if (addr) + DebugBreak(); /* XXX assert */ + ret = VirtualAlloc(addr, size, MEM_RESERVE, PAGE_NOACCESS); + + offset = CHUNK_ADDR2OFFSET(ret); + if (offset == 0) { + VirtualAlloc(ret, size, MEM_COMMIT, PAGE_READWRITE); + } else { + VirtualFree(addr, 0, MEM_RELEASE); + + /* + * Over-allocate in order to map a memory region that + * is definitely large enough. + */ + ret = VirtualAlloc(NULL, size + chunksize, PAGE_NOACCESS); + if (ret == NULL) + return NULL; + + /* XXX we need to store the actual 'ret' somewhere */ + offset = CHUNK_ADDR2OFFSET(ret); + ret = ret + offset; /* XXX should this be -? */ + VirtualAlloc(ret, size - offset, MEM_COMMIT, PAGE_READWRITE); + } #elif defined(MOZ_MEMORY_WINDOWS) ret = VirtualAlloc(addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); #endif return (ret); } static void pages_unmap(void *addr, size_t size) { #ifdef MOZ_MEMORY_WINCE - VirtualFree(addr, size, MEM_RELEASE); -#else + MEMORY_BASIC_INFORMATION info; + VirtualQuery(addr, &info, sizeof(info)); + addr = info.BaseAddress; +#endif if (VirtualFree(addr, 0, MEM_RELEASE) == 0) { _malloc_message(_getprogname(), ": (malloc) Error in VirtualFree()\n", "", ""); if (opt_abort) abort(); } -#endif + } #elif (defined(MOZ_MEMORY_DARWIN)) static void * pages_map(void *addr, size_t size, int pfd) { void *ret; kern_return_t err; int flags; @@ -2498,19 +2522,16 @@ chunk_alloc_mmap(size_t size, bool pagef chunksize - offset), size, pfd); } /* * Failure here indicates a race with another thread, so * try again. */ } } -#ifdef MOZ_MEMORY_WINCE - pages_commit(ret, size); -#endif RETURN: #endif #ifdef MALLOC_PAGEFILE if (pfd != -1) pagefile_close(pfd); #endif #ifdef MALLOC_STATS if (ret != NULL) @@ -5011,19 +5032,16 @@ huge_palloc(size_t alignment, size_t siz ret = (void *)((uintptr_t)over + offset); chunk_dealloc(over, alloc_size); ret = pages_map(ret, chunk_size, pfd); /* * Failure here indicates a race with another thread, so try * again. */ } while (ret == NULL); -#ifdef MOZ_MEMORY_WINCE - pages_commit(ret, chunk_size); -#endif /* Insert node into huge. */ node->addr = ret; #ifdef MALLOC_DECOMMIT psize = PAGE_CEILING(size); node->size = psize; #else node->size = chunk_size; #endif