summaryrefslogtreecommitdiffabout
path: root/src/mmap.c
Side-by-side diff
Diffstat (limited to 'src/mmap.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/mmap.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mmap.c b/src/mmap.c
index 3d57b11..273f64c 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -30,12 +30,20 @@
/* Some systems fail to define this */
# ifndef MAP_FAILED
# define MAP_FAILED ((void*)-1)
# endif
+# if defined(MAP_POPULATE)
+# define GDBM_MMAP_FLAGS MAP_POPULATE
+# elif defined(MAP_PREFAULT_READ)
+# define GDBM_MMAP_FLAGS MAP_PREFAULT_READ
+# else
+# define GDBM_MMAP_FLAGS 0
+# endif
+
/* Translate current offset in the mapped region into the absolute position */
# define _GDBM_MMAPPED_POS(dbf) ((dbf)->mapped_off + (dbf)->mapped_pos)
/* Return true if the absolute offset OFF lies within the currentlty mmapped
region */
# define _GDBM_IN_MAPPED_REGION_P(dbf, off) \
((off) >= (dbf)->mapped_off \
@@ -87,13 +95,13 @@ _gdbm_mapped_unmap (GDBM_FILE dbf)
Take care to recompute {mapped_off,mapped_pos} so that the former lies
on a page size boundary. */
int
_gdbm_internal_remap (GDBM_FILE dbf, size_t size)
{
void *p;
- int flags = PROT_READ;
+ int prot = PROT_READ;
size_t page_size = sysconf (_SC_PAGESIZE);
if (dbf->mapped_region)
{
munmap (dbf->mapped_region, dbf->mapped_size);
dbf->mapped_region = NULL;
@@ -104,15 +112,15 @@ _gdbm_internal_remap (GDBM_FILE dbf, size_t size)
return 0;
dbf->mapped_pos += dbf->mapped_off % page_size;
dbf->mapped_off = (dbf->mapped_off / page_size) * page_size;
if (dbf->read_write)
- flags |= PROT_WRITE;
+ prot |= PROT_WRITE;
- p = mmap (NULL, dbf->mapped_size, flags, MAP_SHARED,
+ p = mmap (NULL, dbf->mapped_size, prot, MAP_SHARED | GDBM_MMAP_FLAGS,
dbf->desc, dbf->mapped_off);
if (p == MAP_FAILED)
{
dbf->mapped_region = NULL;
GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, FALSE);
return -1;

Return to:

Send suggestions and report system problems to the System administrator.