aboutsummaryrefslogtreecommitdiff
path: root/frontend/vita/sys/mman.h
blob: 89da513ca8aa07ae5e0459eca53e5be05338c2f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef MMAN_H
#define MMAN_H

#ifdef __cplusplus
extern "C" {
#endif

#include "stdlib.h"
#include "stdio.h"

#define PROT_READ       0b001
#define PROT_WRITE      0b010
#define PROT_EXEC       0b100
#define MAP_PRIVATE     2
#define MAP_ANONYMOUS   0x20

#define MAP_FAILED      ((void *)-1)

static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
{
   (void)prot;
   (void)flags;
   (void)fd;
   (void)offset;

   int block, ret;

   block = sceKernelAllocMemBlockForVM("code", len);
   if(block<=0){
     sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, len);
     exit(1);
   }

   // get base address
   ret = sceKernelGetMemBlockBase(block, &addr);
   if (ret < 0)
   {
     sceClibPrintf("could get address @0x%08X 0x%08X  \n", block, addr);
     exit(1);
   }


   if(!addr)
      return MAP_FAILED;

   return addr;
}

static inline int mprotect(void *addr, size_t len, int prot)
{
   (void)addr;
   (void)len;
   (void)prot;
   return 0;
}

static inline int munmap(void *addr, size_t len)
{
  int uid = sceKernelFindMemBlockByAddr(addr, len);

  return sceKernelFreeMemBlock(uid);

}

#ifdef __cplusplus
};
#endif

#endif // MMAN_H