diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index 51120a7f5..7b660af4d 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -1,7 +1,11 @@ /// NOTE: TODO: These emscripten api implementation only support wasm32 for now because they assume offsets are u32 +<<<<<<< HEAD use crate::webassembly::{ImportObject, ImportValue, LinearMemory}; use byteorder::{ByteOrder, LittleEndian}; use std::mem; +======= +use crate::webassembly::{ImportObject, ImportValue}; +>>>>>>> Add some syscalls // EMSCRIPTEN APIS mod env; @@ -159,6 +163,7 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "env", "___syscall140", ImportValue::Func(syscalls::___syscall140 as *const u8), +<<<<<<< HEAD ); import_object.set( "env", @@ -172,6 +177,21 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { ); import_object.set( "env", +======= + ); + import_object.set( + "env", + "___syscall145", + ImportValue::Func(syscalls::___syscall145 as *const u8), + ); + import_object.set( + "env", + "___syscall146", + ImportValue::Func(syscalls::___syscall146 as *const u8), + ); + import_object.set( + "env", +>>>>>>> Add some syscalls "___syscall221", ImportValue::Func(syscalls::___syscall221 as *const u8), ); @@ -220,8 +240,13 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { ); import_object.set( "env", +<<<<<<< HEAD "nullFunc_iii", ImportValue::Func(nullfunc::nullfunc_iii as *const u8), +======= + "nullFunc_iiii", + ImportValue::Func(nullfunc::nullfunc_iiii as *const u8), +>>>>>>> Add some syscalls ); import_object.set( "env", diff --git a/src/apis/emscripten/storage.rs b/src/apis/emscripten/storage.rs index d349e3fc0..262b770da 100644 --- a/src/apis/emscripten/storage.rs +++ b/src/apis/emscripten/storage.rs @@ -1,8 +1,18 @@ use crate::webassembly::{LinearMemory, Instance}; +<<<<<<< HEAD pub fn align_memory(ptr: u32) -> u32 { (ptr + 15) & !15 +======= +pub fn align_memory(size: u32, factor: u32) -> u32 { + assert!(factor != 0, "memory cannot be aligned by 0 offset!"); + if size % factor == 1 { + (size) - (size % factor) + (factor) + } else { + size + } +>>>>>>> Add some syscalls } // pub fn static_alloc(size: u32, instance: &mut Instance) -> u32 { @@ -15,7 +25,11 @@ pub fn align_memory(ptr: u32) -> u32 { pub fn static_alloc(size: u32, static_top: &mut u32, memory: &LinearMemory) -> u32 { let old_static_top = *static_top; +<<<<<<< HEAD let total_memory = memory.maximum_size() * LinearMemory::PAGE_SIZE; +======= + let total_memory = memory.maximum.unwrap_or(LinearMemory::MAX_PAGES as u32) * LinearMemory::PAGE_SIZE; +>>>>>>> Add some syscalls // NOTE: The `4294967280` is a u32 conversion of -16 as gotten from emscripten. *static_top = (*static_top + size + 15) & 4294967280; assert!(*static_top < total_memory, "not enough memory for static allocation - increase total_memory!"); diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index aec3ca8a3..9e8ff6696 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -30,6 +30,8 @@ use super::memory::LinearMemory; use super::module::{Export, ImportableExportable, Module}; use super::relocation::{Reloc, RelocSink, RelocationType}; +use crate::apis::emscripten::{align_memory, static_alloc}; + type TablesSlice = UncheckedSlice>; // TODO: this should be `type MemoriesSlice = UncheckedSlice>;`, but that crashes for some reason. type MemoriesSlice = UncheckedSlice>; @@ -98,6 +100,9 @@ pub struct Instance { pub start_func: Option, // Region start memory location // code_base: *const (), + + /// TODO: This should probably be passed as globals to the module. + pub emscripten_data: EmscriptenData, } /// Contains pointers to data (heaps, globals, tables) needed @@ -116,6 +121,27 @@ pub struct DataPointers { pub globals: GlobalsSlice, } +#[derive(Debug)] +#[repr(C)] +pub struct EmscriptenData { + pub static_sealed: bool, + + // global section + pub global_base: u32, + pub static_base: u32, + pub static_top: u32, + + // stack + pub total_stack: u32, + pub stack_base: u32, + pub stack_max: u32, + pub stack_top: u32, + + // heap + pub dynamic_base: u32, + pub dynamictop_ptr: u32, +} + pub struct InstanceOptions { // Shall we mock automatically the imported functions if they don't exist? pub mock_missing_imports: bool, @@ -502,7 +528,7 @@ impl Instance { functions, import_functions, start_func, - // emscripten_data, + emscripten_data, }) }