-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace {environ,size}_{sizes_get,get} C code with Rust
- Loading branch information
1 parent
69e44ca
commit da5916e
Showing
4 changed files
with
64 additions
and
78 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
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
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 |
---|---|---|
@@ -1,5 +1,65 @@ | ||
use super::host; | ||
use super::wasm32; | ||
|
||
pub unsafe fn wasmtime_ssp_args_get( | ||
argv_environ: &mut host::argv_environ_values, | ||
argv: &mut [*mut host::char], | ||
argv_buf: *mut host::char, | ||
) -> wasm32::__wasi_errno_t { | ||
for i in 0..(*argv_environ).argc { | ||
let buf_off = isize::checked_sub( | ||
*(*argv_environ).argv.offset(i as isize) as _, | ||
(*argv_environ).argv_buf as _, | ||
) | ||
.expect("argv[i] - argv_buf overflows"); | ||
argv[i] = argv_buf.offset(buf_off); | ||
} | ||
argv[(*argv_environ).argc] = std::ptr::null_mut(); | ||
argv_buf.copy_from((*argv_environ).argv_buf, (*argv_environ).argv_buf_size); | ||
wasm32::__WASI_ESUCCESS | ||
} | ||
|
||
pub fn wasmtime_ssp_args_sizes_get( | ||
argv_environ: &mut host::argv_environ_values, | ||
argc: &mut usize, | ||
argv_buf_size: &mut usize, | ||
) -> wasm32::__wasi_errno_t { | ||
*argc = (*argv_environ).argc; | ||
*argv_buf_size = (*argv_environ).argv_buf_size; | ||
wasm32::__WASI_ESUCCESS | ||
} | ||
|
||
pub unsafe fn wasmtime_ssp_environ_get( | ||
argv_environ: &mut host::argv_environ_values, | ||
environ: &mut [*mut host::char], | ||
environ_buf: *mut host::char, | ||
) -> wasm32::__wasi_errno_t { | ||
for i in 0..(*argv_environ).environ_count { | ||
let buf_off = isize::checked_sub( | ||
*(*argv_environ).environ.offset(i as isize) as _, | ||
(*argv_environ).environ_buf as _, | ||
) | ||
.expect("environ[i] - environ_buf overflows"); | ||
environ[i] = environ_buf.offset(buf_off); | ||
} | ||
environ[(*argv_environ).environ_count] = std::ptr::null_mut(); | ||
environ_buf.copy_from( | ||
(*argv_environ).environ_buf, | ||
(*argv_environ).environ_buf_size, | ||
); | ||
wasm32::__WASI_ESUCCESS | ||
} | ||
|
||
pub fn wasmtime_ssp_environ_sizes_get( | ||
argv_environ: &mut host::argv_environ_values, | ||
environ_count: &mut usize, | ||
environ_buf_size: &mut usize, | ||
) -> wasm32::__wasi_errno_t { | ||
*environ_count = (*argv_environ).environ_count; | ||
*environ_buf_size = (*argv_environ).environ_buf_size; | ||
wasm32::__WASI_ESUCCESS | ||
} | ||
|
||
pub fn wasmtime_ssp_proc_exit(rval: wasm32::__wasi_exitcode_t) { | ||
::std::process::exit(rval as i32) | ||
} |
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