a3c46b7f |
1 | #ifndef MMAN_H |
2 | #define MMAN_H |
3 | |
4 | #ifdef __cplusplus |
5 | extern "C" { |
6 | #endif |
7 | |
8 | #include <stdlib.h> |
9 | #include <string.h> |
10 | #include <switch.h> |
11 | |
12 | #define PROT_READ 0b001 |
13 | #define PROT_WRITE 0b010 |
14 | #define PROT_EXEC 0b100 |
15 | #define MAP_PRIVATE 2 |
16 | #define MAP_FIXED 0x10 |
17 | #define MAP_ANONYMOUS 0x20 |
18 | |
19 | #define MAP_FAILED ((void *)-1) |
20 | |
21 | #define ALIGNMENT 0x1000 |
22 | |
4db13cab |
23 | #if 0 // not used |
a3c46b7f |
24 | static inline void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) |
25 | { |
26 | (void)fd; |
27 | (void)offset; |
28 | |
29 | // match Linux behavior |
30 | len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1); |
31 | |
32 | Result rc = svcMapPhysicalMemory(addr, len); |
33 | if (R_FAILED(rc)) |
34 | { |
35 | //printf("mmap failed\n"); |
36 | addr = aligned_alloc(ALIGNMENT, len); |
37 | } |
38 | if (!addr) |
39 | return MAP_FAILED; |
40 | memset(addr, 0, len); |
41 | return addr; |
42 | } |
43 | |
44 | static inline int munmap(void *addr, size_t len) |
45 | { |
46 | len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1); |
47 | Result rc = svcUnmapPhysicalMemory(addr, len); |
48 | if (R_FAILED(rc)) |
49 | { |
50 | //printf("munmap failed\n"); |
51 | free(addr); |
52 | } |
53 | return 0; |
54 | } |
4db13cab |
55 | #endif |
a3c46b7f |
56 | |
57 | #ifdef __cplusplus |
58 | }; |
59 | #endif |
60 | |
61 | #endif // MMAN_H |
62 | |