Merge branch 'mainline' into libretro
[pcsx_rearmed.git] / frontend / vita / sys / mman.h
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)prot;
22    (void)flags;
23    (void)fd;
24    (void)offset;
25
26    int block, ret;
27
28    block = sceKernelAllocMemBlockForVM("code", len);
29    if(block<=0){
30      sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, len);
31      exit(1);
32    }
33
34    // get base address
35    ret = sceKernelGetMemBlockBase(block, &addr);
36    if (ret < 0)
37    {
38      sceClibPrintf("could get address @0x%08X 0x%08X  \n", block, addr);
39      exit(1);
40    }
41
42
43    if(!addr)
44       return MAP_FAILED;
45
46    return addr;
47 }
48
49 static inline int mprotect(void *addr, size_t len, int prot)
50 {
51    (void)addr;
52    (void)len;
53    (void)prot;
54    return 0;
55 }
56
57 static inline int munmap(void *addr, size_t len)
58 {
59   int uid = sceKernelFindMemBlockByAddr(addr, len);
60
61   return sceKernelFreeMemBlock(uid);
62
63 }
64
65 #ifdef __cplusplus
66 };
67 #endif
68
69 #endif // MMAN_H