#ifndef __SYS_MMAN_H__
# define __SYS_MMAN_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <stdint.h>

#ifndef __KERNEL_MEMORY_H__
// mapping flags
// Protection (unused)
#define PROT_READ	0x1		/* Page can be read.  */
#define PROT_WRITE	0x2		/* Page can be written.  */
#define PROT_EXEC	0x4		/* Page can be executed.  */
#define PROT_NONE	0x0		/* Page can not be accessed.  */

// Mapping flags
#define MAP_SHARED	0x01		/* Share changes.  */
#define MAP_PRIVATE	0x02		/* Changes are private.  */
#define MAP_ANONYMOUS	0x20		/* Don't use a file.  */
#define MAP_ANON	MAP_ANONYMOUS	/* Don't use a file.  */
#define MAP_FILE	0		/* Ignored.  */
#define MAP_GROWSDOWN	0x00100		/* Stack-like segment.  */
#define MAP_DENYWRITE	0x00800		/* ETXTBSY.  */
#define MAP_EXECUTABLE	0x01000		/* Mark it as an executable.  */
#define MAP_LOCKED	0x02000		/* Lock the mapping.  */
#define MAP_NORESERVE	0x04000		/* Don't check for reservations.  */
#define MAP_POPULATE	0x08000		/* Populate (prefault) pagetables.  */
#define MAP_NONBLOCK	0x10000		/* Do not block on IO.  */
#define MAP_STACK	0x20000		/* Allocation is for a stack.  */
#define MAP_HUGETLB	0x40000		/* Create huge page mapping.  */
#define MAP_SYNC	0x80000		/* Perform synchronous page
					   faults for the mapping.  */
#define MAP_FIXED_NOREPLACE 0x100000	/* MAP_FIXED but do not unmap
					   underlying mapping.  */
#define MAP_UNINITIALIZED   0x200000	/* Don't clear anonymous page */

// Value returned when mmap value
#define MAP_FAILED	((void*) -1)
#endif

/*
** Map addresses starting near ADDR and extending for LEN bytes.  from
** OFFSET into the file FD describes according to PROT and FLAGS.  If ADDR
** is nonzero, it is the desired mapping address.  If the MAP_FIXED bit is
** set in FLAGS, the mapping will be at ADDR exactly (which must be
** page-aligned); otherwise the system chooses a convenient nearby address.
** The return value is the actual mapping address chosen or MAP_FAILED
** for errors (in which case `errno' is set).  A successful `mmap' call
** deallocates any previous mapping for the affected region.
*/
extern void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

/*
** Deallocate any mapping for the region starting at ADDR and extending LEN bytes.
** Returns 0 if successful, -1 for errors (and sets errno).
*/
extern int munmap(void *addr, size_t length);

#ifdef __cplusplus
}
#endif

#endif /*__SYS_MMAN_H__*/