Add automatic MAP_POPULATE flag for opening read_only (MAP_PRIVATE) and shared (MAP_SHARED) mmap files.

This commit is contained in:
Nick Greenfield
2014-07-23 11:25:21 -07:00
parent dcf1425eb9
commit 272fd42c97
2 changed files with 4 additions and 2 deletions

View File

@@ -1375,6 +1375,8 @@ var
## Share changes.
MAP_PRIVATE* {.importc, header: "<sys/mman.h>".}: cint
## Changes are private.
MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
## Populate (prefault) page tables for a mapping.
MAP_FIXED* {.importc, header: "<sys/mman.h>".}: cint
## Interpret addr exactly.
MS_ASYNC* {.importc, header: "<sys/mman.h>".}: cint

View File

@@ -54,7 +54,7 @@ proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
nil,
mappedSize,
if readonly: PROT_READ else: PROT_READ or PROT_WRITE,
if readonly: MAP_PRIVATE else: MAP_SHARED,
if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
m.handle, offset)
if result == cast[pointer](MAP_FAILED):
osError(osLastError())
@@ -207,7 +207,7 @@ proc open*(filename: string, mode: TFileMode = fmRead,
nil,
result.size,
if readonly: PROT_READ else: PROT_READ or PROT_WRITE,
if readonly: MAP_PRIVATE else: MAP_SHARED,
if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
result.handle,
offset)