1 /* $Id: mmap.h 9718 2014-09-22 19:18:44Z iulius $ 2 ** 3 ** Portability wrapper around <sys/mman.h>. 4 ** 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. 8 */ 9 10 #ifndef PORTABLE_MMAP_H 11 #define PORTABLE_MMAP_H 1 12 13 #include "config.h" 14 #include <sys/mman.h> 15 16 /* Make sure that the symbolic constant for the error return from mmap is 17 defined (some platforms don't define it). */ 18 #ifndef MAP_FAILED 19 # define MAP_FAILED ((void *) -1) 20 #endif 21 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. These macros add casts 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 Do not redefine mmap because at least AIX 7.1 redefines it to mmap64. */ 28 #define munmap(p, l) munmap((void *)(p), (l)) 29 30 /* On some platforms, msync only takes two arguments. (ANSI C allows macro 31 definitions of this sort; this macro is not recursive.) */ 32 #if HAVE_MSYNC_3_ARG 33 # define msync(p, l, f) msync((void *)(p), (l), (f)) 34 #else 35 # define msync(p, l, f) msync((void *)(p), (l)) 36 #endif 37 38 /* Turn calls to madvise into a no-op if that call isn't available. */ 39 #if HAVE_MADVISE 40 # define madvise(p, l, o) madvise((void *)(p), (l), (o)) 41 #else 42 # define madvise(p, l, o) /* empty */ 43 #endif 44 45 /* Some platforms don't flush data written to a memory mapped region until 46 msync or munmap; on those platforms, we sometimes need to force an msync 47 so that other parts of INN will see the changed data. Some other 48 platforms don't see writes to a file that's memory-mapped until the 49 memory mappings have been flushed. 50 51 These platforms can use mmap_flush to schedule a flush to disk and 52 mmap_invalidate to force re-reading from disk. Note that all platforms 53 should still periodically call msync so that data is written out in case 54 of a crash. */ 55 #if MMAP_NEEDS_MSYNC 56 # define mmap_flush(p, l) msync((p), (l), MS_ASYNC) 57 #else 58 # define mmap_flush(p, l) /* empty */ 59 #endif 60 61 #if MMAP_MISSES_WRITES 62 # define mmap_invalidate(p, l) msync((p), (l), MS_INVALIDATE) 63 #else 64 # define mmap_invalidate(p, l) /* empty */ 65 #endif 66 67 #endif /* PORTABLE_MMAP_H */ 68