-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ version = "0.1.0" | |
license = "MIT" | ||
authors = ["Nervos Core Dev <[email protected]>"] | ||
edition = "2018" | ||
build = "build.rs" | ||
|
||
[lib] | ||
crate-type = ["lib", "staticlib", "cdylib"] | ||
|
@@ -18,3 +19,6 @@ lazy_static = "1.4" | |
serde = "1.0" | ||
serde_derive = "1.0" | ||
serde_json = "1.0" | ||
|
||
[build-dependencies] | ||
cc = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
cc::Build::new().file("src/dlopen.c").compile("dlopen"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <dlfcn.h> | ||
#include <stdint.h> | ||
|
||
#define ERROR_MEMORY_NOT_ENOUGH -23 | ||
#define ERROR_DYNAMIC_LOADING -24 | ||
#define RISCV_PGSIZE 4096 | ||
#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b)) | ||
|
||
int simulator_internal_dlopen2(const char* native_library_path, | ||
const uint8_t* code, size_t length, | ||
uint8_t* aligned_addr, size_t aligned_size, | ||
void** handle, size_t* consumed_size) { | ||
/* TODO: parse ELF and consume proper pages */ | ||
(void)code; | ||
(void)aligned_addr; | ||
size_t aligned_length = ROUNDUP(length, RISCV_PGSIZE); | ||
if (aligned_size < aligned_length) { | ||
return ERROR_MEMORY_NOT_ENOUGH; | ||
} | ||
*consumed_size = aligned_length; | ||
*handle = dlopen(native_library_path, RTLD_NOW); | ||
return -1; | ||
} | ||
|
||
void* ckb_dlsym(void* handle, const char* symbol) { | ||
return dlsym(handle, symbol); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters