Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ FILES = \
dist/SizeClass.c \
dist/SizeClassSelection.c \
dist/PtrdiffWrapper.c \
dist/Constants.c \
c/utils.c \
c/fatal_error.c \
c/memory.c \
Expand Down Expand Up @@ -126,6 +127,10 @@ SHARED_FLAGS = \
-std=c17 -D_DEFAULT_SOURCE \
-shared -fPIC

# use HACL*'s zeroing function
SHARED_FLAGS += -I vendor/hacl-star
FILES += vendor/hacl-star/Lib_Memzero0.c

INCLUDE_FLAGS = \
-I $(KRML_HOME)/include \
-I $(KRML_LIB)/dist/minimal \
Expand Down
1 change: 1 addition & 0 deletions c/lib-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "internal/StarMalloc.h"
#include "fatal_error.h"

// https://sourceware.org/glibc/manual/latest/html_node/Replacing-malloc.html
__attribute__((tls_model("initial-exec")))
static _Thread_local unsigned thread_arena = CONFIG_NB_ARENAS;
static atomic_uint thread_arena_counter = 0;
Expand Down
18 changes: 12 additions & 6 deletions c/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@

#include "internal/StarMalloc.h"
#include "fatal_error.h"
#include "Constants.h"

/// Mman.fst

// syscall wrapper: initialization (fatal error on failure)
uint8_t *mmap_init(size_t size) {
void* ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
size_t size2 = size + Constants_max_slab_size;
void* ptr = mmap(NULL, size2, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
if (ptr == MAP_FAILED) {
if (errno != ENOMEM) {
fatal_error("non-ENOMEM mmap failure");
}
fatal_error ("mmap failed during initialization (returned NULL)");
fatal_error("mmap failed during initialization (returned NULL)");
}
uintptr_t addr = (uintptr_t) ptr;
if (addr % Constants_max_slab_size != 0) {
ptr += (size_t) (Constants_max_slab_size - addr % Constants_max_slab_size);
}
addr = (uintptr_t) ptr;
if (addr % Constants_max_slab_size != 0) {
fatal_error("mmap failed during initialization (misaligned)");
}
return ptr;
}
Expand Down Expand Up @@ -115,10 +125,6 @@ void mmap_strict_untrap (uint8_t* ptr, size_t len) {

// syscall wrapper
void mmap_trap (uint8_t* ptr, size_t len) {
int r = madvise((void*) ptr, len, MADV_DONTNEED);
if (r && errno != ENOMEM) {
fatal_error("non-ENOMEM MADV_DONTNEED madvise failure");
}
return;
}

Expand Down
3 changes: 2 additions & 1 deletion c/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdint.h>
#include "internal/StarMalloc.h"
#include "fatal_error.h"
#include "lib_memzero0.h"

// glue
uint32_t ffs64(uint64_t x) {
Expand Down Expand Up @@ -45,7 +46,7 @@ uint8_t* memcpy_u8(uint8_t* dest, uint8_t* src, size_t n) {
// monomorphized (from void* to uint8_t*) glue
// TODO: compat, use hacl-star libmemzero
void apply_zeroing_u8(uint8_t* dest, size_t n) {
explicit_bzero(dest, n);
Lib_Memzero0_memzero0(dest, (size_t) n);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "Config.h"

bool Config_enable_sc_fast_selection = true;

size_t Config_metadata_max = (size_t)16777216U;

bool Config_enable_sc_fast_selection = true;

bool Config_enable_guard_pages = true;

size_t Config_guard_pages_interval = (size_t)2U;
Expand Down
8 changes: 4 additions & 4 deletions dist/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

#include "krmllib.h"

#define CONFIG_NB_SIZE_CLASSES ((size_t)27U)

extern bool Config_enable_sc_fast_selection;

#define CONFIG_NB_ARENAS ((size_t)4U)

extern size_t Config_metadata_max;

#define CONFIG_NB_SIZE_CLASSES ((size_t)47U)

extern bool Config_enable_sc_fast_selection;

extern bool Config_enable_guard_pages;

extern size_t Config_guard_pages_interval;
Expand Down
2 changes: 2 additions & 0 deletions dist/Constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

uint32_t Constants_page_size = 4096U;

uint32_t Constants_max_slab_size = 131072U;

10 changes: 10 additions & 0 deletions dist/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

extern uint32_t Constants_page_size;

extern uint32_t Constants_max_slab_size;

typedef struct Constants_sc_full__s
{
uint32_t sc;
uint32_t slab_size;
size_t md_max;
}
Constants_sc_full_;


#define Constants_H_DEFINED
#endif /* Constants_H */
1 change: 1 addition & 0 deletions dist/SizeClass.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "SizeClass.h"

#include "Constants.h"
#include "ArrayList.h"
#include "internal/Slabs.h"

Expand Down
3 changes: 2 additions & 1 deletion dist/SizeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

#include "krmllib.h"

#include "Constants.h"
#include "ArrayList.h"

typedef struct SizeClass_size_class_struct__s
{
uint32_t size;
Constants_sc_full_ size;
size_t *slabs_idxs;
size_t *md_count;
uint8_t *slab_region;
Expand Down
4 changes: 4 additions & 0 deletions dist/SizeClassSelection.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "ExternUtils.h"

krml_checked_int_t SizeClassSelection__n = (krml_checked_int_t)131072;

krml_checked_int_t SizeClassSelection__k = (krml_checked_int_t)17;

uint32_t SizeClassSelection_log2u64(uint64_t x)
{
uint32_t r = clz(x);
Expand Down
4 changes: 4 additions & 0 deletions dist/SizeClassSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "krmllib.h"

extern krml_checked_int_t SizeClassSelection__n;

extern krml_checked_int_t SizeClassSelection__k;

uint32_t SizeClassSelection_log2u64(uint64_t x);

uint32_t SizeClassSelection_inv_impl(uint32_t x);
Expand Down
Loading
Loading