Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a symbols API #38

Merged
merged 1 commit into from
Sep 19, 2024
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
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