Fix the issue of invalid symbols in the identifiers (#101)

* Fix the issue of invalid symbols in the identifiers
* fix comment typos
* format
* fix the c-compliant identifiers for the internal funcs too
pull/96/merge
Emil 3 years ago committed by GitHub
parent 28f3cbfb45
commit 9a94550574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,7 +38,7 @@ $sudo apt install libc++-11-dev libc++abi-11-dev --yes
# Install Binaryen
# Clang uses Binaryen's wasm-opt utility to optimize WebAssembly
sudo apt install binaryen --yes
$sudo apt install binaryen --yes
# Install Rust
if [[ -x "$(command -v rustup)" ]]; then

@ -25,7 +25,7 @@ The file `wasi_main.c` is a simple example of a Unix process that initializes a
An example of this is SLEdge, which uses very different startup and execution logic based around the idea of serverless. In this repo, `wasi_main.c` registers an atexit handler because the backing functions for the WASI proc_exit syscall in wasi_impl_uvwasi and wasi_impl_minimal both directly call POSIX exit, exiting the parent process. This requires us to shift cleanup to an atexit handler. This approach does not work with SLEdge, because the runtime should outlive any sandbox and run the next sandbox on its runqueue when any single sandbox exits.
To deal with this, SLEdge wraps the call to the wasmf\_\_start entrypoint in setjmp and calls longjmp in the WASI prox_exit syscall. This only exits the sandbox and returns control flow to the runtime's parent process.
To deal with this, SLEdge wraps the call to the wasmf\_\_start entrypoint in setjmp and calls longjmp in the WASI proc_exit syscall. This only exits the sandbox and returns control flow to the runtime's parent process.
Assuming that rc and buf are globals, a minimal example of this might look as follows:

@ -1,7 +1,7 @@
#pragma once
/* The functions in this header are responsible for swizzling and unswizzling wasm offsets and narrowing
* arguments that were automatically zero-extended to 32-bits. The pass host pointers and proper wasm types
* arguments that were automatically zero-extended to 32-bits. They pass host pointers and proper wasm types
* to a WASI backing.
*/

@ -3,7 +3,7 @@
* wasi_snapshot_preview1.witx and then hand modified for use in awsm. The
* reason for this is that the original libc file was intended to be used
* inside of programs that target wasm. As such, the WASI syscall signatures
* differ from those that a WASI backed much actually implement.
* differ from those that a WASI backing might actually implement.
*
* For example, consider the path_create_directory syscall. In the auto-generated
* file, the second argument is a traditional null-terminated C string.

@ -94,7 +94,7 @@ void* wasi_context_init(wasi_options_t* options) {
/* Copy the binary name minux the path as the first arg */
strncpy(wasi_context->argv_buf, &options->argv[0][first_arg_offset], first_arg_len);
/* Copy the binary name minux the path as the first arg */
/* Copy the binary name minus the path as the first arg */
for (int i = 1; i < options->argc; i++) {
strncpy(&wasi_context->argv_buf[argv_buffer_offsets[i]], options->argv[i],
argv_buffer_offsets[i + 1] - argv_buffer_offsets[i]);

@ -35,13 +35,13 @@ void* wasi_context_init(wasi_options_t* options) {
/* Pass through environment from host process */
init_options.envp = options->envp;
/* Mount local directory as /home */
/* Mount local directory as /sandbox */
init_options.preopenc = 1;
init_options.preopens = calloc(1, sizeof(uvwasi_preopen_t));
init_options.preopens[0].mapped_path = "/sandbox";
init_options.preopens[0].real_path = ".";
/* Initialize the sandbox */
/* Initialize the wasi_context */
uvwasi_errno_t err = uvwasi_init(wasi_context, &init_options);
free(init_options.argv);

@ -69,11 +69,15 @@ pub fn process_to_llvm(
match e {
Export::Function { index, name } => {
// We namespace these, so they can't conflict with our actual native code
wasm_module.functions[index].set_name("wasmf_".to_string() + &name);
let name_c_compliant =
name.replace(|c: char| !(c.is_alphanumeric() || c == '_'), "_");
wasm_module.functions[index].set_name("wasmf_".to_string() + &name_c_compliant);
}
Export::Global { index, name } => {
// We namespace these, so they can't conflict with our actual native code
wasm_module.globals[index].set_name("wasmg_".to_string() + &name);
let name_c_compliant =
name.replace(|c: char| !(c.is_alphanumeric() || c == '_'), "_");
wasm_module.globals[index].set_name("wasmg_".to_string() + &name_c_compliant);
}
// Exporting memory is meaningless in our native embedding
Export::Memory { .. } => {}

@ -892,7 +892,10 @@ impl WasmModule {
for (i, func) in m.functions.iter_mut().enumerate() {
if let Function::Implemented { f: _ } = func {
if let Some(function_name_map) = m.function_name_maps.get(&(i as u32)) {
func.set_name("wasmf_internal_".to_string() + &function_name_map.name);
let name_c_compliant = &function_name_map
.name
.replace(|c: char| !(c.is_alphanumeric() || c == '_'), "_");
func.set_name("wasmf_internal_".to_string() + &name_c_compliant);
func.set_locals_name_map(function_name_map.locals.clone());
}

Loading…
Cancel
Save