You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.1 KiB
68 lines
1.1 KiB
12 years ago
|
#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)
|
||
|
{
|
||
12 years ago
|
void *data;
|
||
|
size_t size;
|
||
12 years ago
|
|
||
12 years ago
|
data = malloc(len);
|
||
|
if (!data)
|
||
|
{
|
||
|
fprintf (stderr, "[Escape] [mmap] malloc failed\n");
|
||
|
return MAP_FAILED;
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
size = read(fd, data, len);
|
||
|
if (size != len)
|
||
|
{
|
||
|
fprintf (stderr, "[Escape] [mmap] read failed\n");
|
||
|
free(data);
|
||
|
return MAP_FAILED;
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
if (lseek(fd, -len, SEEK_CUR) == -1)
|
||
|
{
|
||
|
fprintf (stderr, "[Escape] [mmap] lseek failed\n");
|
||
|
free(data);
|
||
|
return MAP_FAILED;
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
return data;
|
||
12 years ago
|
}
|
||
|
|
||
|
int
|
||
|
munmap(void *addr,
|
||
|
size_t len __UNUSED__)
|
||
|
{
|
||
12 years ago
|
if (addr && (addr != MAP_FAILED))
|
||
|
free(addr);
|
||
12 years ago
|
|
||
12 years ago
|
return 0;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
int
|
||
|
madvise(void *addr __UNUSED__,
|
||
|
size_t length __UNUSED__,
|
||
|
int advice __UNUSED__)
|
||
12 years ago
|
{
|
||
12 years ago
|
return 0;
|
||
12 years ago
|
}
|
||
12 years ago
|
|