Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
0152la committed Apr 18, 2024
1 parent 06b708a commit cd39a1d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 33 deletions.
13 changes: 7 additions & 6 deletions include/comp_utils.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef _COMP_UTILS_H
#define _COMP_UTILS_H

#include <stddef.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);

void *malloc(size_t);
void
free(void *);
void *calloc(size_t, size_t);
void *
realloc(void *, size_t);

#endif // _COMP_UTILS_H
1 change: 0 additions & 1 deletion include/compartment.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ struct Compartment

// Hardware info - maybe move
size_t page_size;

};

int
Expand Down
3 changes: 2 additions & 1 deletion include/intercept.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exec_comp(struct Compartment *, char *, char **);
struct Compartment *manager_get_compartment_by_id(size_t);

extern void *__capability manager_ddc;
extern void comp_exec_out();
extern void
comp_exec_out();

// Number of capabilities required to perform a transition
#define COMP_RETURN_CAPS_COUNT 2
Expand Down
19 changes: 10 additions & 9 deletions src/comp_utils.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
#include "comp_utils.h"

static void* malloc_ptr;
static void *malloc_ptr;
static size_t heap_mem_left;

void*
void *
malloc(size_t to_alloc)
{
if (!malloc_ptr)
{
void* __capability ddc = cheri_ddc_get();
malloc_ptr = (char*) cheri_address_get(ddc);
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;
void *to_ret = malloc_ptr;
memset(to_ret, 0, to_alloc);
malloc_ptr = (char*) malloc_ptr + to_alloc;
malloc_ptr = (char *) malloc_ptr + to_alloc;
heap_mem_left -= to_alloc;
return to_ret;
}

void
free(void* to_free)
free(void *to_free)
{
// TODO temp usage for bump allocator implementation to satisfy compiler
to_free = to_free;
}

void*
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)
void *
realloc(void *to_realloc, size_t new_size)
{
// TODO temp usage for bump allocator implementation to satisfy compiler
to_realloc = to_realloc;
Expand Down
18 changes: 11 additions & 7 deletions src/compartment.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,17 @@ parse_lib_rela(Elf64_Shdr *rela_shdr, Elf64_Ehdr *lib_ehdr, int lib_fd,
// TODO at least right now
if (!strcmp(&dyn_str_tbl[curr_rela_sym.st_name], "environ"))
{
warnx("Currently not relocating symbol `environ` from library %s - "
warnx("Currently not relocating symbol `environ` from library "
"%s - "
"using within a container might cause a crash.",
lib_dep->lib_name);
continue;
}
else if (!strcmp(&dyn_str_tbl[curr_rela_sym.st_name], "__progname"))
{
warnx(
"Currently not relocating symbol `__progname` from library %s "
"- using within a container might cause a crash.",
warnx("Currently not relocating symbol `__progname` from "
"library %s "
"- using within a container might cause a crash.",
lib_dep->lib_name);
continue;
}
Expand All @@ -653,14 +654,17 @@ parse_lib_rela(Elf64_Shdr *rela_shdr, Elf64_Ehdr *lib_ehdr, int lib_fd,
= curr_rela_sym.st_value + (char *) lib_dep->lib_mem_base;
}
// TODO
assert(curr_rela.r_addend == 0 && "I want to check if we have symbol-related relocations with addends");
assert(curr_rela.r_addend == 0
&& "I want to check if we have symbol-related relocations with "
"addends");
}
else
{
lrm.target_func_address = curr_rela.r_addend + (char*) lib_dep->lib_mem_base;
lrm.target_func_address
= curr_rela.r_addend + (char *) lib_dep->lib_mem_base;
}

lrm.rela_address = curr_rela.r_offset + (char*) lib_dep->lib_mem_base;
lrm.rela_address = curr_rela.r_offset + (char *) lib_dep->lib_mem_base;
memcpy(new_relas + actual_relas, &lrm, sizeof(struct LibRelaMapping));

actual_relas += 1;
Expand Down
11 changes: 6 additions & 5 deletions src/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ register_new_comp(char *filename, bool allow_default_entry)
strcpy(ep_names[i], new_cep[i].name);
}

struct Compartment *new_comp
= comp_from_elf(filename, ep_names, new_comp_ep_count, get_next_comp_addr());
struct Compartment *new_comp = comp_from_elf(
filename, ep_names, new_comp_ep_count, get_next_comp_addr());
new_comp->id = comps_count;
void *__capability new_comp_ddc
= cheri_address_set(cheri_ddc_get(), (uintptr_t) new_comp->base);
new_comp_ddc = cheri_bounds_set(
new_comp_ddc, (char*) new_comp->scratch_mem_stack_top - (char*) new_comp->base);
new_comp_ddc = cheri_offset_set(new_comp_ddc, (char*) new_comp->scratch_mem_base - (char*) new_comp->base);
new_comp_ddc = cheri_bounds_set(new_comp_ddc,
(char *) new_comp->scratch_mem_stack_top - (char *) new_comp->base);
new_comp_ddc = cheri_offset_set(new_comp_ddc,
(char *) new_comp->scratch_mem_base - (char *) new_comp->base);
new_comp->ddc = new_comp_ddc;

struct CompWithEntries *new_cwe = malloc(sizeof(struct CompWithEntries));
Expand Down
3 changes: 2 additions & 1 deletion tests/simple_global_var.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <assert.h>

int get_ext_val();
int
get_ext_val();

int
main(void)
Expand Down
4 changes: 2 additions & 2 deletions tests/simple_open_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
int
main(void)
{
char* buf = "Hello File!\n";
char* file = "out_syscall_write";
char *buf = "Hello File!\n";
char *file = "out_syscall_write";
int fd = open(file, O_WRONLY | O_CREAT);
if (fd == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/simple_various.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

static const char *hw = "Hello World!";

Expand Down

0 comments on commit cd39a1d

Please sign in to comment.