-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jozanza/patch-1
Add basic memory module
- Loading branch information
Showing
3 changed files
with
31 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
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,21 @@ | ||
use crate::memory_host::*; | ||
|
||
pub fn read_stdin(buf: &mut [u8]) -> std::io::Result<u32> { | ||
let mut len = 0; | ||
let errno = unsafe { memory_read(buf.as_mut_ptr(), buf.len() as _, &mut len) }; | ||
if errno == 0 { | ||
return Ok(len); | ||
} | ||
let err = std::io::Error::from_raw_os_error(errno as i32); | ||
Err(err) | ||
} | ||
|
||
pub fn read_env_vars(buf: &mut [u8]) -> std::io::Result<u32> { | ||
let mut len = 0; | ||
let errno = unsafe { env_var_read(buf.as_mut_ptr(), buf.len() as _, &mut len) }; | ||
if errno == 0 { | ||
return Ok(len); | ||
} | ||
let err = std::io::Error::from_raw_os_error(errno as i32); | ||
Err(err) | ||
} |
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,7 @@ | ||
#[link(wasm_import_module = "blockless_memory")] | ||
extern "C" { | ||
#[link_name = "memory_read"] | ||
pub(crate) fn memory_read(buf: *mut u8, len: u32, num: *mut u32) -> u32; | ||
#[link_name = "env_var_read"] | ||
pub(crate) fn env_var_read(buf: *mut u8, len: u32, num: *mut u32) -> u32; | ||
} |