-
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.
* Provide a `malloc` and friends compartment library to be used internally, overriding the previous interception implementation. We use the DDC capability to get the are of memory that is designated as heap space. This is done in a new library, `libcomputils.so`, to be loaded in a compartment. This means further libraries loaded will also use our own internal `malloc` implementation; * Due to the above change, we also remove old intercept stuff, as that has been completely outdated by newer features (might come back for inter-compartment calls); * Fix setting improper bounds for compartment DDC capabilities (i.e., ensure the capability encompasses only the memory region designated for a compartment), and now set the offset to match the start of the compartment heap, to use for internal `malloc`; * Further improve symbol relocation lookup, including support for "raw" relocations that refer only to addresses, not to a given symbol.
- Loading branch information
Showing
20 changed files
with
219 additions
and
530 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 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.