From c037f5112292b114521325973e3b2d66f3217bae Mon Sep 17 00:00:00 2001 From: Josiah Savary Date: Tue, 27 Jun 2023 22:32:44 -0500 Subject: [PATCH 1/5] Create memory.rs --- src/memory.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/memory.rs diff --git a/src/memory.rs b/src/memory.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/memory.rs @@ -0,0 +1 @@ + From e1775708e8273b99211621273fc159cbe8b54705 Mon Sep 17 00:00:00 2001 From: Josiah Savary Date: Tue, 27 Jun 2023 22:36:19 -0500 Subject: [PATCH 2/5] Create memory_host.rs --- src/memory_host.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/memory_host.rs diff --git a/src/memory_host.rs b/src/memory_host.rs new file mode 100644 index 0000000..3da9b78 --- /dev/null +++ b/src/memory_host.rs @@ -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; + } From 62509d82660fb880ca196d8969e00b0755152f6d Mon Sep 17 00:00:00 2001 From: Josiah Savary Date: Tue, 27 Jun 2023 22:38:39 -0500 Subject: [PATCH 3/5] Add read_stdin --- src/memory.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/memory.rs b/src/memory.rs index 8b13789..0d42802 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1 +1,11 @@ +use crate::memory_host::*; +pub fn read_stdin(buf: &mut [u8]) -> std::io::Result { + 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) +} From cf834d8ae5e93ba054b9c01629568f73792b4aee Mon Sep 17 00:00:00 2001 From: Josiah Savary Date: Tue, 27 Jun 2023 22:41:02 -0500 Subject: [PATCH 4/5] Add read_env_vars --- src/memory.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/memory.rs b/src/memory.rs index 0d42802..7d9879a 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -9,3 +9,13 @@ pub fn read_stdin(buf: &mut [u8]) -> std::io::Result { 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 { + 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) +} From 1804f9a47383f4b67bd265fe28ef3410f1bc7701 Mon Sep 17 00:00:00 2001 From: Josiah Savary Date: Tue, 27 Jun 2023 22:41:40 -0500 Subject: [PATCH 5/5] Update lib.rs --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9bbae56..b4a81a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::*;