vita: add a seemingly missing include
[pcsx_rearmed.git] / frontend / vita / sys / mman.h
1 #ifndef MMAN_H
2 #define MMAN_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <psp2/kernel/sysmem.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #define PROT_READ       0b001
13 #define PROT_WRITE      0b010
14 #define PROT_EXEC       0b100
15 #define MAP_PRIVATE     2
16 #define MAP_ANONYMOUS   0x20
17
18 #define MAP_FAILED      ((void *)-1)
19
20 static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
21 {
22    (void)prot;
23    (void)flags;
24    (void)fd;
25    (void)offset;
26
27    int block, ret;
28
29    block = sceKernelAllocMemBlockForVM("code", len);
30    if(block<=0){
31      sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, len);
32      exit(1);
33    }
34
35    // get base address
36    ret = sceKernelGetMemBlockBase(block, &addr);
37    if (ret < 0)
38    {
39      sceClibPrintf("could get address @0x%08X 0x%08X  \n", block, addr);
40      exit(1);
41    }
42
43
44    if(!addr)
45       return MAP_FAILED;
46
47    return addr;
48 }
49
50 static inline int mprotect(void *addr, size_t len, int prot)
51 {
52    (void)addr;
53    (void)len;
54    (void)prot;
55    return 0;
56 }
57
58 static inline int munmap(void *addr, size_t len)
59 {
60   int uid = sceKernelFindMemBlockByAddr(addr, len);
61
62   return sceKernelFreeMemBlock(uid);
63
64 }
65
66 #ifdef __cplusplus
67 };
68 #endif
69
70 #endif // MMAN_H