chiark / gitweb /
Commit 2.4.5-5 as unpacked
[inn-innduct.git] / include / portable / mmap.h
1 /*  $Id: mmap.h 6012 2002-12-16 11:19:21Z alexk $
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.  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))
28
29 /* On some platforms, msync only takes two arguments.  (ANSI C allows macro
30    definitions of this sort; this macro is not recursive.) */
31 #if HAVE_MSYNC_3_ARG
32 # define msync(p, l, f)         msync((void *)(p), (l), (f))
33 #else
34 # define msync(p, l, f)         msync((void *)(p), (l))
35 #endif
36
37 /* Turn calls to madvise into a no-op if that call isn't available. */
38 #if HAVE_MADVISE
39 # define madvise(p, l, o)       madvise((void *)(p), (l), (o))
40 #else
41 # define madvise(p, l, o)       /* empty */
42 #endif
43
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.
49
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
53    of a crash. */
54 #if MMAP_NEEDS_MSYNC
55 # define mmap_flush(p, l)       msync((p), (l), MS_ASYNC)
56 #else
57 # define mmap_flush(p, l)       /* empty */
58 #endif
59
60 #if MMAP_MISSES_WRITES
61 # define mmap_invalidate(p, l)  msync((p), (l), MS_INVALIDATE)
62 #else
63 # define mmap_invalidate(p, l)  /* empty */
64 #endif
65
66 #endif /* PORTABLE_MMAP_H */