Blame src/logic/pe_map_raw_image.c
|
|
c0fbae |
#include <stdint.h>
|
|
|
fa22b4 |
#include <stdbool.h>
|
|
|
c0fbae |
#include <unistd.h>
|
|
|
c0fbae |
#include <fcntl.h>
|
|
|
c0fbae |
#include <sys/mman.h>
|
|
|
c0fbae |
#include <sys/types.h>
|
|
|
c0fbae |
#include <sys/stat.h>
|
|
|
c0fbae |
|
|
|
c0fbae |
#include <perk/perk.h>
|
|
|
c0fbae |
|
|
|
2b71e8 |
int pe_map_raw_image (int fd, const char * fname, int prot, struct pe_raw_image * map)
|
|
|
c0fbae |
{
|
|
|
fa22b4 |
struct stat stat;
|
|
|
fa22b4 |
bool fnew;
|
|
|
c0fbae |
|
|
|
fa22b4 |
if (fnew = (fd < 0))
|
|
|
c0fbae |
fd = open(fname,O_RDONLY | O_CLOEXEC);
|
|
|
c0fbae |
|
|
|
c0fbae |
if ((fd < 0) || (fstat(fd,&stat) < 0))
|
|
|
fa22b4 |
return -1;
|
|
|
c0fbae |
|
|
|
c0fbae |
map->size = stat.st_size;
|
|
|
664d5b |
map->addr = mmap(0,map->size,prot,MAP_PRIVATE,fd,0);
|
|
|
c0fbae |
|
|
|
fa22b4 |
if (fnew)
|
|
|
fa22b4 |
close(fd);
|
|
|
c0fbae |
|
|
|
fa22b4 |
return (map->addr == MAP_FAILED) ? -1 : 0;
|
|
|
c0fbae |
}
|
|
|
c0fbae |
|
|
|
c0fbae |
int pe_unmap_raw_image (struct pe_raw_image * map)
|
|
|
c0fbae |
{
|
|
|
fa22b4 |
return munmap(map->addr,map->size);
|
|
|
b5f7f5 |
}
|