-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from 0152la/printf
Internal `malloc` and various improvements
- Loading branch information
Showing
19 changed files
with
223 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef _COMP_UTILS_H | ||
#define _COMP_UTILS_H | ||
|
||
#include <err.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
#include "cheriintrin.h" | ||
|
||
void *malloc(size_t); | ||
void | ||
free(void *); | ||
void *calloc(size_t, size_t); | ||
void * | ||
realloc(void *, size_t); | ||
|
||
#endif // _COMP_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# Compartment management library | ||
add_library(chcomp STATIC | ||
manager.c | ||
mem_mng.c | ||
compartment.c | ||
intercept.c | ||
transition.S | ||
) | ||
target_include_directories(chcomp PRIVATE ${INCLUDE_DIR} ${TOML_INCLUDE_DIR}) | ||
target_link_libraries(chcomp PRIVATE tomllib) | ||
|
||
add_library(computils SHARED | ||
comp_utils.c) | ||
target_include_directories(computils PRIVATE ${INCLUDE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "comp_utils.h" | ||
|
||
static void *malloc_ptr; | ||
static size_t heap_mem_left; | ||
|
||
void * | ||
malloc(size_t to_alloc) | ||
{ | ||
if (!malloc_ptr) | ||
{ | ||
void *__capability ddc = cheri_ddc_get(); | ||
malloc_ptr = (char *) cheri_address_get(ddc); | ||
heap_mem_left = cheri_length_get(ddc) - cheri_offset_get(ddc); | ||
} | ||
if (to_alloc > heap_mem_left) | ||
{ | ||
errx(1, "Insufficient heap space left."); | ||
} | ||
void *to_ret = malloc_ptr; | ||
memset(to_ret, 0, to_alloc); | ||
malloc_ptr = (char *) malloc_ptr + to_alloc; | ||
heap_mem_left -= to_alloc; | ||
return to_ret; | ||
} | ||
|
||
void | ||
free(void *to_free) | ||
{ | ||
// TODO temp usage for bump allocator implementation to satisfy compiler | ||
to_free = to_free; | ||
} | ||
|
||
void * | ||
calloc(size_t elem_count, size_t elem_size) | ||
{ | ||
return malloc(elem_count * elem_size); | ||
} | ||
|
||
void * | ||
realloc(void *to_realloc, size_t new_size) | ||
{ | ||
// TODO temp usage for bump allocator implementation to satisfy compiler | ||
to_realloc = to_realloc; | ||
|
||
return malloc(new_size); | ||
} |
Oops, something went wrong.