Skip to content

Commit

Permalink
Merge pull request #10 from jozanza/patch-1
Browse files Browse the repository at this point in the history
Add basic memory module
  • Loading branch information
Joinhack authored Jun 28, 2023
2 parents 2702f61 + 1804f9a commit 4ac8277
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ mod cgi_host;
mod error;
mod http;
mod http_host;
mod memory;
mod memory_host;
mod socket;
mod socket_host;

pub use cgi::*;
pub use error::*;
pub use http::*;
pub use memory::*;
pub use socket::*;
21 changes: 21 additions & 0 deletions src/memory.rs
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)
}
7 changes: 7 additions & 0 deletions src/memory_host.rs
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;
}

0 comments on commit 4ac8277

Please sign in to comment.