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

Hashtable backend #39

Merged
merged 1 commit into from
Sep 27, 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
7 changes: 5 additions & 2 deletions .buildbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ ${CLANG_FORMAT_BIN} --dry-run -Werror ${CLANG_FORMAT_SOURCES[*]}
# Update submodules
git submodule update --init

# Apply lua patch
# Apply `lua` patch
lua_dir="$src_dir/third-party/lua"
patch -d $lua_dir -i ../lua.patch

# Apply toml patch
# Apply `toml` patch
toml_dir="$src_dir/third-party/tomlc99"
patch -d $toml_dir -i ../tomlc99.patch

# Link `tommyds` Makefile appropriately
ln -s $(pwd)/third-party/tommyds-makefile $(pwd)/third-party/tommyds/tommyds/Makefile

# Prepare python virtual env
export PATH=$PATH:$HOME/.local/bin
pip3 install --break-system-packages fabric
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "third-party/tomlc99"]
path = third-party/tomlc99
url = https://github.com/cktan/tomlc99
[submodule "third-party/tommyds"]
path = third-party/tommyds
url = https://github.com/amadvance/tommyds.git
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,34 @@ add_custom_target(
toml
DEPENDS ${TOML_LIB_PATH}
)
add_library(tomllib SHARED IMPORTED)
add_library(tomllib STATIC IMPORTED)
add_dependencies(tomllib toml)
set_target_properties(tomllib
PROPERTIES
IMPORTED_LOCATION ${TOML_LIB_PATH}
)

# Build tommyds
set(TOMMYDS_DIR ${CMAKE_SOURCE_DIR}/third-party/tommyds/tommyds)
set(TOMMYDS_LIB ${CMAKE_SOURCE_DIR}/third-party/tommyds/tommyds/libtommyds.a)

add_custom_command(
OUTPUT ${TOMMYDS_LIB}
COMMAND make
WORKING_DIRECTORY ${TOMMYDS_DIR}
)

add_custom_target(
tommyds
DEPENDS ${TOMMYDS_LIB}
)
add_library(tommydslib STATIC IMPORTED)
add_dependencies(tommydslib tommyds)
set_target_properties(tommydslib
PROPERTIES
IMPORTED_LOCATION ${TOMMYDS_LIB}
)

# Build sources
add_subdirectory(${SRC_DIR})

Expand Down
3 changes: 2 additions & 1 deletion include/compartment.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <sys/stat.h>
#include <unistd.h>

#include "symbols.h"
// TODO consider re-organizing
#include "symbols_comp.h"

#include "cheriintrin.h"

Expand Down
66 changes: 5 additions & 61 deletions include/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,15 @@
#include <err.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct simple_lds_list
{
struct LibDependencySymbol **data;
size_t data_count;
};
#include "tommy.h"

struct simple_cs_list
{
struct CompSymbol **data;
size_t data_count;
};
#define HASHTABLE_MAX_SZ 1024
#define hashtable_hash(x) tommy_hash_u64(0, x, strlen(x))

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 *);
#define MAX_FIND_ALL_COUNT 1024

#endif // _CHERICOMP_SYMBOLS_H
36 changes: 36 additions & 0 deletions include/symbols_comp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef _CHERICOMP_SYMBOLS_COMP_H
#define _CHERICOMP_SYMBOLS_COMP_H

#include "symbols.h"
#include "symbols_lib.h"

typedef tommy_hashtable comp_symbol_list;
typedef struct CompSymbol comp_symbol;

/* 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;
tommy_node node;
};

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 *, comp_symbol_list *);
comp_symbol **
comp_syms_find_all(const char *, comp_symbol_list *);

void
update_comp_syms(comp_symbol_list *, lib_symbol_list *, const size_t);

#endif // _CHERICOMP_SYMBOLS_COMP_H
36 changes: 36 additions & 0 deletions include/symbols_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef _CHERICOMP_SYMBOLS_LIB_H
#define _CHERICOMP_SYMBOLS_LIB_H

#include "symbols.h"

typedef tommy_hashtable lib_symbol_list;
typedef struct LibDependencySymbol lib_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;
tommy_node node;
};

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 *, lib_symbol_list *);
lib_symbol **
lib_syms_find_all(const char *, lib_symbol_list *);
void
lib_syms_print(lib_symbol_list *);

#endif // _CHERICOMP_SYMBOLS_LIB_H
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ add_library(chcomp STATIC
symbols_lib.c
transition.S
)
target_include_directories(chcomp PRIVATE ${INCLUDE_DIR} ${TOML_INCLUDE_DIR})
target_link_libraries(chcomp PRIVATE tomllib)
target_include_directories(chcomp PRIVATE ${INCLUDE_DIR} ${TOML_INCLUDE_DIR} ${TOMMYDS_DIR})
target_link_libraries(chcomp PRIVATE tomllib tommydslib)

add_library(computils SHARED
comp_utils.c)
Expand Down
Loading