274 |
|
|
275 |
|
if (ftruncate(fd, size) < 0) |
276 |
|
return VM_MAP_FAILED; |
277 |
– |
|
278 |
– |
the_map_flags |= MAP_SHARED; |
277 |
|
} |
278 |
|
#endif |
279 |
|
|
342 |
|
return -1; |
343 |
|
#else |
344 |
|
#ifdef HAVE_MMAP_VM |
345 |
< |
const int extra_map_flags = translate_map_flags(options); |
345 |
> |
int fd = zero_fd; |
346 |
> |
int the_map_flags = translate_map_flags(options) | map_flags | MAP_FIXED; |
347 |
> |
|
348 |
> |
#ifdef USE_33BIT_ADDRESSING |
349 |
> |
const char *shm_file = NULL; |
350 |
> |
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) { |
351 |
> |
the_map_flags &= ~(MAP_PRIVATE | MAP_ANON | MAP_ANONYMOUS); |
352 |
> |
the_map_flags |= MAP_SHARED; |
353 |
|
|
354 |
< |
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, extra_map_flags | map_flags | MAP_FIXED, zero_fd, 0) == (void *)MAP_FAILED) |
354 |
> |
if ((shm_file = build_shm_filename()) == NULL) |
355 |
> |
return -1; |
356 |
> |
|
357 |
> |
if ((fd = shm_open(shm_file, O_RDWR | O_CREAT | O_EXCL, 0644)) < 0) |
358 |
> |
return -1; |
359 |
> |
|
360 |
> |
if (ftruncate(fd, size) < 0) |
361 |
> |
return -1; |
362 |
> |
} |
363 |
> |
#endif |
364 |
> |
|
365 |
> |
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED) |
366 |
|
return -1; |
367 |
|
|
368 |
|
// Since I don't know the standard behavior of mmap(), zero-fill here |
369 |
|
if (memset(addr, 0, size) != addr) |
370 |
|
return -1; |
371 |
+ |
|
372 |
+ |
// Remap to 33-bit space |
373 |
+ |
#ifdef USE_33BIT_ADDRESSING |
374 |
+ |
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) { |
375 |
+ |
if (!add_shm_range(strdup(shm_file), addr, size)) |
376 |
+ |
return -1; |
377 |
+ |
|
378 |
+ |
if (mmap((char *)addr + (1L << 32), size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED) |
379 |
+ |
return -1; |
380 |
+ |
close(fd); |
381 |
+ |
} |
382 |
+ |
#endif |
383 |
|
#else |
384 |
|
#ifdef HAVE_WIN32_VM |
385 |
|
// Windows cannot allocate Low Memory |