test whole program
This commit is contained in:
@@ -64,33 +64,33 @@
|
||||
assert ((a) == 0); \
|
||||
}
|
||||
|
||||
// static inline void *MALLOC(size_t size)
|
||||
// {
|
||||
// void * temp = malloc(size);
|
||||
// assert(temp);
|
||||
// return temp;
|
||||
// }
|
||||
static inline void *MALLOC(size_t size)
|
||||
{
|
||||
void * temp = malloc(size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
// static inline void *CALLOC(size_t num, size_t size)
|
||||
// {
|
||||
// void * temp = calloc(num, size);
|
||||
// assert(temp);
|
||||
// return temp;
|
||||
// }
|
||||
static inline void *CALLOC(size_t num, size_t size)
|
||||
{
|
||||
void * temp = calloc(num, size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
// static inline void *REALLOC(void *ptr, size_t size)
|
||||
// {
|
||||
// void * temp = realloc(ptr, size);
|
||||
// assert(temp);
|
||||
// return temp;
|
||||
// }
|
||||
static inline void *REALLOC(void *ptr, size_t size)
|
||||
{
|
||||
void * temp = realloc(ptr, size);
|
||||
assert(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
// static inline char *GETENV(char *envstr)
|
||||
// {
|
||||
// char *env = getenv(envstr);
|
||||
// if (!env) return "0";
|
||||
// else return env;
|
||||
// }
|
||||
static inline char *GETENV(char *envstr)
|
||||
{
|
||||
char *env = getenv(envstr);
|
||||
if (!env) return "0";
|
||||
else return env;
|
||||
}
|
||||
|
||||
#define GET_TIME(start, end, duration) \
|
||||
duration.tv_sec = (end.tv_sec - start.tv_sec); \
|
||||
@@ -131,57 +131,88 @@ static inline void get_time (struct timeval *t)
|
||||
|
||||
// Expirement work
|
||||
|
||||
// #define FILENAME "/dev/contigmem"
|
||||
#define FILENAME "/dev/contigmem"
|
||||
|
||||
static char *heap_start;
|
||||
static char *heap;
|
||||
static size_t HEAP_SIZE = 1024 * 1024 * 1024;
|
||||
|
||||
static void *ptr;
|
||||
static int MallocCounter = 0;
|
||||
void *ptr;
|
||||
int MallocCounter;
|
||||
|
||||
static size_t sizeUsed;
|
||||
size_t sizeUsed;
|
||||
|
||||
// INITAlloc(void) {
|
||||
static void INITAlloc(void) {
|
||||
|
||||
// size_t sz;
|
||||
// // Pre Allocate 600 MB
|
||||
// sz = 100000000;
|
||||
size_t sz;
|
||||
// Pre Allocate 600 MB
|
||||
sz = 100000000;
|
||||
|
||||
// int fd = open(FILENAME, O_RDWR, 0600);
|
||||
int fd = open(FILENAME, O_RDWR, 0600);
|
||||
|
||||
// if (fd < 0) {
|
||||
// perror("open");
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// off_t offset = 0; // offset to seek to.
|
||||
off_t offset = 0; // offset to seek to.
|
||||
|
||||
// if (ftruncate(fd, sz) < 0) {
|
||||
// perror("ftruncate");
|
||||
// close(fd);
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
|
||||
// // ptr = mmap(NULL, sz,
|
||||
// // PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0);
|
||||
if (ftruncate(fd, sz) < 0) {
|
||||
perror("ftruncate");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// ptr = mmap(NULL, sz,
|
||||
// PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
||||
// PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0);
|
||||
|
||||
// // Added error handling
|
||||
// if(ptr == MAP_FAILED)
|
||||
// {
|
||||
// perror("mmap");
|
||||
// exit(EXIT_FAILURE);
|
||||
ptr = mmap(NULL, sz,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
||||
|
||||
// Added error handling
|
||||
if(ptr == MAP_FAILED)
|
||||
{
|
||||
perror("mmap");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
MallocCounter = (int)sz;
|
||||
|
||||
}
|
||||
|
||||
// Quick malloc implementation with mmap
|
||||
void* malloc(size_t sz)
|
||||
{
|
||||
sz = __builtin_align_up(sz, _Alignof(max_align_t));
|
||||
|
||||
// printf("%d \n", sz);
|
||||
// printf("%d Malloc counter\n", MallocCounter);
|
||||
|
||||
MallocCounter -= sz;
|
||||
void *ptrLink = &ptr[MallocCounter];
|
||||
ptrLink = cheri_setbounds(ptrLink, sz);
|
||||
|
||||
return ptrLink;
|
||||
|
||||
// if (heap + sz > heap_start + HEAP_SIZE) return NULL;
|
||||
// heap += sz;
|
||||
// return heap - sz;
|
||||
|
||||
}
|
||||
|
||||
// Quick cheri free implementation
|
||||
// void free(void *ptr) {
|
||||
|
||||
// // printf("free called \n");
|
||||
|
||||
// // get bounds from
|
||||
// int len = cheri_getlen(ptr);
|
||||
|
||||
// // printf("free len %d \n", len);
|
||||
|
||||
// munmap(ptr, len);
|
||||
// }
|
||||
|
||||
// MallocCounter = (int)sz;
|
||||
|
||||
// }
|
||||
|
||||
static int notrun = 0;
|
||||
|
||||
static int
|
||||
pagesizes(size_t ps[MAXPAGESIZES])
|
||||
{
|
||||
@@ -199,10 +230,10 @@ pagesizes(size_t ps[MAXPAGESIZES])
|
||||
return (pscnt);
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void INITREGULARALLOC(void) {
|
||||
__attribute__((constuctor))
|
||||
static INITREGULARALLOC(void) {
|
||||
size_t sz;
|
||||
// Pre Allocate 400 MB
|
||||
// Hard-coded for 1GB huge page
|
||||
sz = 1073741824;
|
||||
|
||||
int error, fd, pscnt, pn;
|
||||
@@ -254,45 +285,6 @@ static void INITREGULARALLOC(void) {
|
||||
}
|
||||
|
||||
MallocCounter = (int)sz;
|
||||
notrun = 1;
|
||||
}
|
||||
|
||||
|
||||
// Quick malloc implementation with mmap
|
||||
void* malloc(size_t sz)
|
||||
{
|
||||
// If malloc is called for the first time then allocate huge page
|
||||
if (notrun == 0) {
|
||||
INITREGULARALLOC();
|
||||
}
|
||||
sz = __builtin_align_up(sz, _Alignof(max_align_t));
|
||||
|
||||
// printf("%d \n", sz);
|
||||
// printf("%d Malloc counter\n", MallocCounter);
|
||||
|
||||
MallocCounter -= sz;
|
||||
void *ptrLink = &ptr[MallocCounter];
|
||||
ptrLink = cheri_setbounds(ptrLink, sz);
|
||||
|
||||
return ptrLink;
|
||||
|
||||
// if (heap + sz > heap_start + HEAP_SIZE) return NULL;
|
||||
// heap += sz;
|
||||
// return heap - sz;
|
||||
|
||||
}
|
||||
|
||||
// Quick cheri free implementation
|
||||
void free(void *ptr) {
|
||||
|
||||
// printf("free called \n");
|
||||
|
||||
// get bounds from
|
||||
int len = cheri_getlen(ptr);
|
||||
|
||||
// printf("free len %d \n", len);
|
||||
|
||||
munmap(ptr, len);
|
||||
}
|
||||
// Standard Alloc
|
||||
// void* MALLOCREGULAR(size_t sz) {
|
||||
|
||||
Reference in New Issue
Block a user