mmap-util.h revision 4ff6d11dc314dd2c88630f34850a6850b94e7095
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef MMAP_UTIL_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define MMAP_UTIL_H
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainen
8e9666f46faceeef0f3c6f706f10f3a873e4b0ebTimo Sirainen#include <unistd.h>
8e9666f46faceeef0f3c6f706f10f3a873e4b0ebTimo Sirainen
8e9666f46faceeef0f3c6f706f10f3a873e4b0ebTimo Sirainen#ifdef HAVE_LINUX_MREMAP
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define __USE_GNU /* for MREMAP_MAYMOVE */
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#endif
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#include <sys/mman.h>
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#undef __USE_GNU
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#if !defined (MREMAP_MAYMOVE) && !defined (HAVE_LINUX_MREMAP)
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define MREMAP_MAYMOVE 1
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#endif
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#define madvise my_madvise
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainenint my_madvise(void *start, size_t length, int advice);
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen#ifndef HAVE_MADVISE
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# ifndef MADV_NORMAL
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define MADV_NORMAL 0
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define MADV_RANDOM 0
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define MADV_SEQUENTIAL 0
0b2b090cdc3d36f30d6d2ec99b35ac0b7657d538Timo Sirainen# define MADV_WILLNEED 0
f2de6ecc4424533633aea705f12d0f691d7ddf81Timo Sirainen# define MADV_DONTNEED 0
f2de6ecc4424533633aea705f12d0f691d7ddf81Timo Sirainen# endif
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainen#endif
54df49100a0111a956662cb8a327969badd2d72dTimo Sirainen
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainenvoid *mmap_file(int fd, size_t *length, int prot);
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainenvoid *mmap_ro_file(int fd, size_t *length);
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainenvoid *mmap_rw_file(int fd, size_t *length);
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen/* for allocating anonymous mmap()s, with portable mremap(). these must not
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen be mixed with any standard mmap calls. */
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainenvoid *mmap_anon(size_t length);
f2de6ecc4424533633aea705f12d0f691d7ddf81Timo Sirainenvoid *mremap_anon(void *old_address, size_t old_size, size_t new_size,
2a7605bb97dc9ed8accf2537fad1073a5fc5ff48Timo Sirainen unsigned long flags);
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainenint munmap_anon(void *start, size_t length);
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainen
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainensize_t mmap_get_page_size(void) ATTR_CONST;
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainen
aa883f5fbc68920c48c4f52919e8a5bb9611e678Timo Sirainen#endif
54df49100a0111a956662cb8a327969badd2d72dTimo Sirainen