| 1 | #ifndef MMAN_H |
| 2 | #define MMAN_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "stdlib.h" |
| 9 | #include "stdio.h" |
| 10 | |
| 11 | #define PROT_READ 0b001 |
| 12 | #define PROT_WRITE 0b010 |
| 13 | #define PROT_EXEC 0b100 |
| 14 | #define MAP_PRIVATE 2 |
| 15 | #define MAP_ANONYMOUS 0x20 |
| 16 | |
| 17 | #define MAP_FAILED ((void *)-1) |
| 18 | |
| 19 | static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) |
| 20 | { |
| 21 | (void)addr; |
| 22 | (void)prot; |
| 23 | (void)flags; |
| 24 | (void)fd; |
| 25 | (void)offset; |
| 26 | |
| 27 | void* addr_out; |
| 28 | |
| 29 | addr_out = malloc(len); |
| 30 | if(!addr_out) |
| 31 | return MAP_FAILED; |
| 32 | |
| 33 | return addr_out; |
| 34 | } |
| 35 | |
| 36 | static inline int mprotect(void *addr, size_t len, int prot) |
| 37 | { |
| 38 | (void)addr; |
| 39 | (void)len; |
| 40 | (void)prot; |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static inline int munmap(void *addr, size_t len) |
| 45 | { |
| 46 | free(addr); |
| 47 | return 0; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | }; |
| 53 | #endif |
| 54 | |
| 55 | #endif // MMAN_H |
| 56 | |