Skip to content

Commit

Permalink
Review comments addressed and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aditijannu committed Jun 25, 2024
1 parent 93a9e46 commit 106b8c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
21 changes: 12 additions & 9 deletions snmalloc-edp/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use elf::ElfStream;
use elf::endian::LittleEndian;
use std::fs::{DirEntry, File};
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -35,6 +37,7 @@ fn main() {
assert!(ar.status().unwrap().success());

// # Read the symbols from the shim ELF object
assert_eq!(files_in_dir(&objs).count(), 1);
let f = files_in_dir(&objs).next().unwrap();
let mut elf = elf::ElfStream::<elf::endian::LittleEndian, _>::open_stream(File::open(f.path()).unwrap()).unwrap();
let (symtab, strtab) = elf.symbol_table().unwrap().unwrap();
Expand All @@ -50,19 +53,19 @@ fn main() {
let sn_alloc_size = sn_alloc_size.expect("sn_alloc_size");
let sn_alloc_align = sn_alloc_align.expect("sn_alloc_align");

let mut get_u64_at_symbol = |sym: elf::symbol::Symbol| {
assert_eq!(sym.st_size, 8);
let (data, _) = elf.section_data(&elf.section_headers()[sym.st_shndx as usize].clone()).unwrap();
let data: &[u8; 8] = data.split_at(8).0.try_into().unwrap();
u64::from_le_bytes(*data)
};

let sn_alloc_size = get_u64_at_symbol(sn_alloc_size);
let sn_alloc_align = get_u64_at_symbol(sn_alloc_align);
let sn_alloc_size = get_u64_at_symbol(sn_alloc_size, &mut elf);
let sn_alloc_align = get_u64_at_symbol(sn_alloc_align, &mut elf);

// # Write the type
let contents = format!("#[repr(align({}), C)] pub struct Alloc {{ _0: [u8; {}] }}", sn_alloc_align, sn_alloc_size);
let mut alloc_type_rs = out_dir.clone();
alloc_type_rs.push("alloc-type.rs");
std::fs::write(alloc_type_rs, contents).unwrap();
}

fn get_u64_at_symbol(sym: elf::symbol::Symbol, elf: &mut ElfStream<LittleEndian, File>) -> u64 {
assert_eq!(sym.st_size, 8);
let (data, _) = elf.section_data(&elf.section_headers()[sym.st_shndx as usize].clone()).unwrap();
let data: &[u8; 8] = data.split_at(8).0.try_into().unwrap();
u64::from_le_bytes(*data)
}
8 changes: 4 additions & 4 deletions snmalloc-edp/src/rust-sgx-snmalloc-shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern "C" size_t get_tcs_addr();

// from Rust std
extern "C" void __rust_print_err(const char *m, size_t s);
extern "C" void __rust_print_err(const char* m, size_t s);
extern "C" [[noreturn]] void __rust_abort();

/*******************************************************/
Expand All @@ -46,7 +46,7 @@ extern "C" [[noreturn]] void abort() __THROW {
__rust_abort();
}

// definition needs to match GNU header
// definition needs to match GNU header and will not return an actual errno
extern "C" inline int * __attribute_const__ __errno_location (void) __THROW {
static int errno;
return &errno;
Expand All @@ -65,15 +65,15 @@ extern "C" inline int * __attribute_const__ __errno_location (void) __THROW {

namespace snmalloc {
void register_clean_up() {
// TODO: not sure what this is supposed to do
// Unused on SGX
abort();
}

class EdpErrorHandler {
public:
static void print_stack_trace() {}

[[noreturn]] static void error(const char *const str) {
[[noreturn]] static void error(const char* const str) {
__rust_print_err(str, strlen(str));
abort();
}
Expand Down

0 comments on commit 106b8c3

Please sign in to comment.