65
65
#define MAP_EXTRA_FLAGS (MAP_32BIT)
67
67
#ifdef HAVE_MMAP_VM
68
#if defined(__linux__) && defined(__i386__)
68
#if (defined(__linux__) && defined(__i386__)) || HAVE_LINKER_SCRIPT
69
69
/* Force a reasonnable address below 0x80000000 on x86 so that we
70
70
don't get addresses above when the program is run on AMD64.
71
71
NOTE: this is empirically determined on Linux/x86. */
287
285
return VM_MAP_FAILED;
289
287
next_address = (char *)addr + size;
291
// Since I don't know the standard behavior of mmap(), zero-fill here
292
if (memset(addr, 0, size) != addr)
293
return VM_MAP_FAILED;
295
289
// Remap to 33-bit space
296
290
#ifdef USE_33BIT_ADDRESSING
307
301
#ifdef HAVE_WIN32_VM
308
302
if ((addr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)) == NULL)
309
303
return VM_MAP_FAILED;
311
// Zero newly allocated memory
312
if (memset(addr, 0, size) != addr)
313
return VM_MAP_FAILED;
315
305
if ((addr = calloc(size, 1)) == 0)
316
306
return VM_MAP_FAILED;
346
336
#ifdef HAVE_MMAP_VM
347
const int extra_map_flags = translate_map_flags(options);
349
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, extra_map_flags | map_flags | MAP_FIXED, zero_fd, 0) == (void *)MAP_FAILED)
352
// Since I don't know the standard behavior of mmap(), zero-fill here
353
if (memset(addr, 0, size) != addr)
338
int the_map_flags = translate_map_flags(options) | map_flags | MAP_FIXED;
340
#ifdef USE_33BIT_ADDRESSING
341
const char *shm_file = NULL;
342
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
343
the_map_flags &= ~(MAP_PRIVATE | MAP_ANON | MAP_ANONYMOUS);
344
the_map_flags |= MAP_SHARED;
346
if ((shm_file = build_shm_filename()) == NULL)
349
if ((fd = shm_open(shm_file, O_RDWR | O_CREAT | O_EXCL, 0644)) < 0)
352
if (ftruncate(fd, size) < 0)
357
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED)
360
// Remap to 33-bit space
361
#ifdef USE_33BIT_ADDRESSING
362
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
363
if (!add_shm_range(strdup(shm_file), addr, size))
366
if (mmap((char *)addr + (1L << 32), size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED)
356
372
#ifdef HAVE_WIN32_VM
357
373
// Windows cannot allocate Low Memory
364
380
LPVOID ret_addr = VirtualAlloc(req_addr, req_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
365
381
if (ret_addr != req_addr)
368
// Zero newly allocated memory
369
if (memset(addr, 0, size) != addr)