mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 05:01:33 +00:00
Make emscripten work again
This commit is contained in:
@ -18,7 +18,7 @@ pub fn is_emscripten_module(module: &Module) -> bool {
|
||||
}
|
||||
|
||||
pub unsafe fn write_to_buf(string: *const c_char, buf: u32, max: u32, ctx: &mut Ctx) -> u32 {
|
||||
let buf_addr = ctx.memory(0)[buf as usize] as *mut c_char;
|
||||
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_char;
|
||||
|
||||
for i in 0..max {
|
||||
*buf_addr.add(i as _) = *string.add(i as _);
|
||||
@ -32,7 +32,7 @@ pub unsafe fn copy_cstr_into_wasm(ctx: &mut Ctx, cstr: *const c_char) -> u32 {
|
||||
let s = CStr::from_ptr(cstr).to_str().unwrap();
|
||||
let cstr_len = s.len();
|
||||
let space_offset = env::call_malloc((cstr_len as i32) + 1, ctx);
|
||||
let raw_memory = ctx.memory(0)[space_offset as usize] as *mut u8;
|
||||
let raw_memory = emscripten_memory_pointer!(ctx.memory(0), space_offset) as *mut u8;
|
||||
let slice = slice::from_raw_parts_mut(raw_memory, cstr_len);
|
||||
|
||||
for (byte, loc) in s.bytes().zip(slice.iter_mut()) {
|
||||
@ -48,7 +48,7 @@ pub unsafe fn copy_cstr_into_wasm(ctx: &mut Ctx, cstr: *const c_char) -> u32 {
|
||||
|
||||
pub unsafe fn allocate_on_stack<'a, T: Copy>(count: u32, ctx: &'a mut Ctx) -> (u32, &'a mut [T]) {
|
||||
let offset = (get_emscripten_data(ctx).stack_alloc)(count * (size_of::<T>() as u32), ctx);
|
||||
let addr = ctx.memory(0)[offset as usize] as *mut T;
|
||||
let addr = emscripten_memory_pointer!(ctx.memory(0), offset) as *mut T;
|
||||
let slice = slice::from_raw_parts_mut(addr, count as usize);
|
||||
|
||||
(offset, slice)
|
||||
@ -104,7 +104,7 @@ pub struct GuestStat {
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe fn copy_stat_into_wasm(ctx: &mut Ctx, buf: u32, stat: &stat) {
|
||||
let stat_ptr = ctx.memory(0)[buf as usize] as *mut GuestStat;
|
||||
let stat_ptr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut GuestStat;
|
||||
(*stat_ptr).st_dev = stat.st_dev as _;
|
||||
(*stat_ptr).__st_dev_padding = 0;
|
||||
(*stat_ptr).__st_ino_truncated = stat.st_ino as _;
|
||||
|
Reference in New Issue
Block a user