summaryrefslogtreecommitdiff
path: root/src/lib/escape/escape_mman.c
blob: 995c72e7f499ca6855c588f411c1043dc8bae19f (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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#include "sys/mman.h"

/***** API *****/

void *
mmap(void  *addr __UNUSED__,
     size_t len,
     int    prot,
     int    flags,
     int    fd,
     off_t  offset)
{
   void *data;
   size_t size;

   data = malloc(len);
   if (!data)
     {
        fprintf (stderr, "[Escape] [mmap] malloc failed\n");
        return MAP_FAILED;
     }

   size = read(fd, data, len);
   if (size != len)
     {
        fprintf (stderr, "[Escape] [mmap] read failed\n");
        free(data);
        return MAP_FAILED;
     }

   if (lseek(fd, -len, SEEK_CUR) == -1)
     {
        fprintf (stderr, "[Escape] [mmap] lseek failed\n");
        free(data);
        return MAP_FAILED;
     }

   return data;
}

int
munmap(void  *addr,
       size_t len __UNUSED__)
{
   if (addr && (addr != MAP_FAILED))
     free(addr);

   return 0;
}

int
madvise(void  *addr __UNUSED__,
        size_t length __UNUSED__,
        int    advice __UNUSED__)
{
   return 0;
}