1 /* $Id: mmap.h 6012 2002-12-16 11:19:21Z alexk $
3 ** Portability wrapper around <sys/mman.h>.
5 ** This header file includes <sys/mman.h> and then sets up various
6 ** additional defines and macros to permit a uniform API across platforms
7 ** with varying mmap implementations.
10 #ifndef PORTABLE_MMAP_H
11 #define PORTABLE_MMAP_H 1
16 /* Make sure that the symbolic constant for the error return from mmap is
17 defined (some platforms don't define it). */
19 # define MAP_FAILED ((void *) -1)
22 /* Solaris 8 (at least) prototypes munmap, msync, and madvise as taking char *
23 (actually a caddr_t, which is a typedef for a char *) instead of void * as
24 is required by the standard. This macro adds a cast that silences compiler
25 warnings on Solaris 8 without adversely affecting other platforms. (ISO C
26 allows macro definitions of this sort; this macro is not recursive.) */
27 #define munmap(p, l) munmap((void *)(p), (l))
29 /* On some platforms, msync only takes two arguments. (ANSI C allows macro
30 definitions of this sort; this macro is not recursive.) */
32 # define msync(p, l, f) msync((void *)(p), (l), (f))
34 # define msync(p, l, f) msync((void *)(p), (l))
37 /* Turn calls to madvise into a no-op if that call isn't available. */
39 # define madvise(p, l, o) madvise((void *)(p), (l), (o))
41 # define madvise(p, l, o) /* empty */
44 /* Some platforms don't flush data written to a memory mapped region until
45 msync or munmap; on those platforms, we sometimes need to force an msync
46 so that other parts of INN will see the changed data. Some other
47 platforms don't see writes to a file that's memory-mapped until the
48 memory mappings have been flushed.
50 These platforms can use mmap_flush to schedule a flush to disk and
51 mmap_invalidate to force re-reading from disk. Note that all platforms
52 should still periodically call msync so that data is written out in case
55 # define mmap_flush(p, l) msync((p), (l), MS_ASYNC)
57 # define mmap_flush(p, l) /* empty */
60 #if MMAP_MISSES_WRITES
61 # define mmap_invalidate(p, l) msync((p), (l), MS_INVALIDATE)
63 # define mmap_invalidate(p, l) /* empty */
66 #endif /* PORTABLE_MMAP_H */