a3c46b7f |
1 | #ifndef MMAN_H |
2 | #define MMAN_H |
3 | |
4 | #include <stdlib.h> |
c50a1845 |
5 | //#include <psp2/kernel/sysmem.h> |
a3c46b7f |
6 | |
7 | #ifdef __cplusplus |
8 | extern "C" { |
9 | #endif |
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 | |
c50a1845 |
19 | #if 0 // not used |
a3c46b7f |
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 | } |
c50a1845 |
65 | #endif |
a3c46b7f |
66 | |
67 | #ifdef __cplusplus |
68 | }; |
69 | #endif |
70 | |
71 | #endif // MMAN_H |