Merge pull request #21 from phaseIV/master
[pcsx_rearmed.git] / frontend / 3ds / sys / mman.h
CommitLineData
fc99395c 1#ifndef MMAN_H
2#define MMAN_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "3ds.h"
9#include "stdlib.h"
10#include "stdio.h"
11
12#define PROT_READ MEMPERM_READ
13#define PROT_WRITE MEMPERM_WRITE
14#define PROT_EXEC MEMPERM_EXECUTE
15#define MAP_PRIVATE 2
16#define MAP_ANONYMOUS 0x20
17
18#define MAP_FAILED ((void *)-1)
19
20static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
21{
22 (void)addr;
23 (void)prot;
24 (void)flags;
25 (void)fd;
26 (void)offset;
27
28 void* addr_out;
29
30 addr_out = malloc(len);
31 if(!addr_out)
32 return MAP_FAILED;
33
34 return addr_out;
35}
36
37static inline int mprotect(void *addr, size_t len, int prot)
38{
39 extern int ctr_svchack_init_success;
40
41 if(ctr_svchack_init_success)
42 {
43 uint32_t currentHandle;
44 svcDuplicateHandle(&currentHandle, 0xFFFF8001);
45 svcControlProcessMemory(currentHandle, (u32)addr, 0x0,
46 len, MEMOP_PROT, prot);
47 svcCloseHandle(currentHandle);
48 return 0;
49 }
50
1f3b70a9 51 printf("mprotect called without svcControlProcessMemory access !\n");
fc99395c 52 return -1;
53}
54
55static inline int munmap(void *addr, size_t len)
56{
57 free(addr);
58 return 0;
fc99395c 59}
60
61#ifdef __cplusplus
62};
63#endif
64
65#endif // MMAN_H
66