16 #include <sys/types.h>
22 #define MAP_ANONYMOUS MAP_ANON
25 #define handle_error(msg) \
26 do { perror(msg); exit(EXIT_FAILURE); } while (0)
28 uint8_t *
GetMMAP(
const char *filename, uint64_t mapSize,
int &fd,
bool zero)
34 memblock = (uint8_t *)mmap(NULL, mapSize, PROT_WRITE|PROT_READ, MAP_SHARED|
MAP_ANONYMOUS, -1, 0);
35 if (memblock == MAP_FAILED)
45 printf(
"Size of off_t is (%lu), uint64_t is (%lu)\n",
sizeof(off_t),
sizeof(uint64_t));
48 if ((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1)
52 if (lseek(fd, mapSize-1, SEEK_SET) == -1)
56 if (write(fd,
"", 1) != 1)
62 printf(
"Size: %" PRId64
" \n",(uint64_t)sb.st_size);
63 assert(sb.st_size == mapSize);
66 if ((fd = open(filename, O_RDWR, 0666)) == -1)
73 printf(
"Size: %" PRId64
" \n",(uint64_t)sb.st_size);
74 assert(sb.st_size >= mapSize);
76 memblock = (uint8_t *)mmap(NULL, sb.st_size, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
78 if (memblock == MAP_FAILED)
85 void CloseMMap(uint8_t *mem, uint64_t mapSizeBytes,
int fd)
87 if (munmap(mem, mapSizeBytes) != 0)