294 |
|
return -1; |
295 |
|
#endif |
296 |
|
|
297 |
< |
#ifdef HAVE_MACH_VM |
297 |
> |
#if defined(HAVE_MACH_VM) |
298 |
|
// vm_allocate() returns a zero-filled memory region |
299 |
|
kern_return_t ret_code = vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, 0); |
300 |
|
if (ret_code != KERN_SUCCESS) { |
301 |
|
errno = vm_error(ret_code); |
302 |
|
return -1; |
303 |
|
} |
304 |
< |
#else |
305 |
< |
#ifdef HAVE_MMAP_VM |
304 |
> |
#elif defined(HAVE_MMAP_VM) |
305 |
|
int fd = zero_fd; |
306 |
|
int the_map_flags = translate_map_flags(options) | map_flags | MAP_FIXED; |
307 |
|
|
308 |
|
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED) |
309 |
|
return -1; |
310 |
< |
#else |
312 |
< |
#ifdef HAVE_WIN32_VM |
310 |
> |
#elif defined(HAVE_WIN32_VM) |
311 |
|
// Windows cannot allocate Low Memory |
312 |
|
if (addr == NULL) |
313 |
|
return -1; |
326 |
|
// Unsupported |
327 |
|
return -1; |
328 |
|
#endif |
329 |
< |
#endif |
332 |
< |
#endif |
333 |
< |
|
329 |
> |
|
330 |
|
// Explicitely protect the newly mapped region here because on some systems, |
331 |
|
// say MacOS X, mmap() doesn't honour the requested protection flags. |
332 |
|
if (vm_protect(addr, size, VM_PAGE_DEFAULT) != 0) |
333 |
|
return -1; |
334 |
< |
|
334 |
> |
|
335 |
|
return 0; |
336 |
|
} |
337 |
|
|