Skip to content

Commit

Permalink
Introduce a symbols API
Browse files Browse the repository at this point in the history
Rework how we store and search symbols for relocation, abstracting away
most of the detail, in order to be able to use various underlying
data types. As relocation seems to take most of the runtime based on
initial observations, this is a first step in order to compare against
various backend data types, rather than using an ad-hoc implementation.
  • Loading branch information
0152la committed Sep 19, 2024
1 parent 290b6c6 commit ce8907d
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 170 deletions.
29 changes: 4 additions & 25 deletions include/compartment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <fcntl.h>
#include <fts.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -18,6 +17,8 @@
#include <sys/stat.h>
#include <unistd.h>

#include "symbols.h"

#include "cheriintrin.h"

// Morello `gcc` defines `ptraddr_t` in `stddef.h`, while `clang` does so in
Expand Down Expand Up @@ -94,28 +95,6 @@ struct LibRelaMapping
uint16_t rela_sym_shndx; // section index of underlying symbol
};

/* Struct representing a symbol entry of a dependency library
*/
struct LibDependencySymbol
{
char *sym_name;
void *sym_offset;
unsigned short sym_type;
unsigned short sym_bind;
uint16_t sym_shndx;
};

/* Struct representing the result of searching for a library symbol in a
* compartment; for simplicity, we store the respective library index within
* the compartment, and symbol index within the library's symbols
*/
struct LibSymSearchResult
{
unsigned short lib_idx;
unsigned short sym_idx;
bool found;
};

/**
* Struct representing a library dependency for one of our given compartments
*/
Expand All @@ -131,8 +110,7 @@ struct LibDependency
struct SegmentMap *lib_segs;

// Symbols within this library
size_t lib_syms_count;
struct LibDependencySymbol *lib_syms;
lib_symbol_list *lib_syms;

// Library dependencies for this library
unsigned short lib_dep_count;
Expand Down Expand Up @@ -224,6 +202,7 @@ struct Compartment
void *tls_lookup_func;
size_t total_tls_size;
struct TLSDesc *libs_tls_sects;
comp_symbol_list *comp_syms;

// Hardware info - maybe move
size_t page_size;
Expand Down
74 changes: 74 additions & 0 deletions include/symbols.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef _CHERICOMP_SYMBOLS_H
#define _CHERICOMP_SYMBOLS_H

#include <err.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

struct simple_lds_list
{
struct LibDependencySymbol **data;
size_t data_count;
};

struct simple_cs_list
{
struct CompSymbol **data;
size_t data_count;
};

typedef struct simple_lds_list lib_symbol_list;
typedef struct LibDependencySymbol lib_symbol;

typedef struct simple_cs_list comp_symbol_list;
typedef struct CompSymbol comp_symbol;

/* Struct representing a symbol entry of a dependency library
*/
struct LibDependencySymbol
{
char *sym_name;
void *sym_offset;
unsigned short sym_type;
unsigned short sym_bind;
uint16_t sym_shndx;
};

/* Struct representing a wrapper around a LibDependencySymbol, in order to
* facilitate compartment-level searching
*/
struct CompSymbol
{
struct LibDependencySymbol *sym_ref;
size_t sym_lib_idx;
};

comp_symbol_list *
comp_syms_init();
void
comp_syms_clean(comp_symbol_list *);
void
comp_syms_clean_deep(comp_symbol_list *);
void
comp_syms_insert(comp_symbol *, comp_symbol_list *);
comp_symbol *
comp_syms_search(const char *, const comp_symbol_list *);
comp_symbol_list *
comp_syms_find_all(const char *, const comp_symbol_list *);

lib_symbol_list *
lib_syms_init();
void
lib_syms_clean(lib_symbol_list *);
void
lib_syms_clean_deep(lib_symbol_list *);
void
lib_syms_insert(lib_symbol *, lib_symbol_list *);
lib_symbol *
lib_syms_search(const char *, const lib_symbol_list *);
lib_symbol_list *
lib_syms_find_all(const char *, const lib_symbol_list *);

#endif // _CHERICOMP_SYMBOLS_H
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Compartment management library
add_library(chcomp STATIC
manager.c
compartment.c
intercept.c
manager.c
symbols_comp.c
symbols_lib.c
transition.S
)
target_include_directories(chcomp PRIVATE ${INCLUDE_DIR} ${TOML_INCLUDE_DIR})
Expand Down
Loading

0 comments on commit ce8907d

Please sign in to comment.