Skip to content

Instantly share code, notes, and snippets.

@webmaster128
Last active June 20, 2023 10:49
Show Gist options
  • Save webmaster128/abbd468ffe8ffc568779aa32e16dbd43 to your computer and use it in GitHub Desktop.
Save webmaster128/abbd468ffe8ffc568779aa32e16dbd43 to your computer and use it in GitHub Desktop.
diff --git a/packages/std/src/memory.rs b/packages/std/src/memory.rs
index c331a53c..09462d25 100644
--- a/packages/std/src/memory.rs
+++ b/packages/std/src/memory.rs
@@ -15,9 +15,21 @@ pub struct Region {
pub length: u32,
}
+
+extern "C" {
+ fn addr_validate(source_ptr: u32) -> u32;
+}
+
/// Creates a memory region of capacity `size` and length 0. Returns a pointer to the Region.
/// This is the same as the `allocate` export, but designed to be called internally.
pub fn alloc(size: usize) -> *mut Region {
+
+ let source = build_region("".as_bytes());
+ let source_ptr = &*source as *const Region as u32;
+
+ let result = unsafe { addr_validate(source_ptr) };
+
+
let data: Vec<u8> = Vec::with_capacity(size);
let data_ptr = data.as_ptr() as usize;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment