mmap-util.h revision e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch#ifndef __MMAP_UTIL_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define __MMAP_UTIL_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#include <unistd.h>
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifdef HAVE_LINUX_MREMAP
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen# define __USE_GNU /* for MREMAP_MAYMOVE */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
d04f3e064ceb2ba1d734182937a7115739ebadbeTimo Sirainen
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#include <sys/mman.h>
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#undef __USE_GNU
e98e8ba55a01427844b2d24becd791dde8b0178bTimo Sirainen
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#if !defined (MREMAP_MAYMOVE) && !defined (HAVE_LINUX_MREMAP)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# define MREMAP_MAYMOVE 1
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifndef HAVE_MADVISE
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# define madvise my_madvise
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschint my_madvise(void *start, size_t length, int advice);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# ifndef MADV_NORMAL
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# define MADV_NORMAL 0
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen# define MADV_RANDOM 0
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen# define MADV_SEQUENTIAL 0
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen# define MADV_WILLNEED 0
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen# define MADV_DONTNEED 0
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch# endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschvoid *mmap_file(int fd, size_t *length, int prot);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschvoid *mmap_ro_file(int fd, size_t *length);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschvoid *mmap_rw_file(int fd, size_t *length);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* for allocating anonymous mmap()s, with portable mremap(). these must not
84a31ddebcf8c3aeaef7b9e54171a48ee1374c45Timo Sirainen be mixed with any standard mmap calls. */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschvoid *mmap_anon(size_t length);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschvoid *mremap_anon(void *old_address, size_t old_size, size_t new_size,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch unsigned long flags);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschint munmap_anon(void *start, size_t length);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschsize_t mmap_get_page_size(void);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
204ee6ed414f5e4eeb6f6c10763b55daf56f11acJosef 'Jeff' Sipek