diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index 6b88651e6b7..b342bd962e0 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -19,8 +19,9 @@ extern "C" { /// emscripten: _getenv // (name: *const char) -> *const c_char; pub fn _getenv(mut ctx: FunctionEnvMut, name: u32) -> u32 { debug!("emscripten::_getenv"); - let memory = ctx.data().memory_view(0, &ctx); - let name_string = read_string_from_wasm(&memory, name); + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); + let name_string = read_string_from_wasm(&view, name); debug!("=> name({:?})", name_string); let c_str = unsafe { getenv(name_string.as_ptr() as *const libc::c_char) }; if c_str.is_null() { @@ -32,10 +33,11 @@ pub fn _getenv(mut ctx: FunctionEnvMut, name: u32) -> u32 { /// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int); pub fn _setenv(ctx: FunctionEnvMut, name: u32, value: u32, _overwrite: u32) -> c_int { debug!("emscripten::_setenv"); - let memory = ctx.data().memory_view(0, &ctx); + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); // setenv does not exist on windows, so we hack it with _putenv - let name = read_string_from_wasm(&memory, name); - let value = read_string_from_wasm(&memory, value); + let name = read_string_from_wasm(&view, name); + let value = read_string_from_wasm(&view, value); let putenv_string = format!("{}={}", name, value); let putenv_cstring = CString::new(putenv_string).unwrap(); let putenv_raw_ptr = putenv_cstring.as_ptr(); @@ -47,8 +49,9 @@ pub fn _setenv(ctx: FunctionEnvMut, name: u32, value: u32, _overwrite: u3 /// emscripten: _putenv // (name: *const char); pub fn _putenv(ctx: FunctionEnvMut, name: c_int) -> c_int { debug!("emscripten::_putenv"); - let memory = ctx.data().memory_view(0, &ctx); - let name_addr = emscripten_memory_pointer!(&memory, name) as *const c_char; + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); + let name_addr = emscripten_memory_pointer!(&view, name) as *const c_char; debug!("=> name({:?})", unsafe { std::ffi::CStr::from_ptr(name_addr) }); @@ -58,8 +61,9 @@ pub fn _putenv(ctx: FunctionEnvMut, name: c_int) -> c_int { /// emscripten: _unsetenv // (name: *const char); pub fn _unsetenv(ctx: FunctionEnvMut, name: u32) -> c_int { debug!("emscripten::_unsetenv"); - let memory = ctx.data().memory_view(0, &ctx); - let name = read_string_from_wasm(&memory, name); + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); + let name = read_string_from_wasm(&view, name); // no unsetenv on windows, so use putenv with an empty value let unsetenv_string = format!("{}=", name); let unsetenv_cstring = CString::new(unsetenv_string).unwrap(); @@ -88,9 +92,10 @@ pub fn _getpwnam(mut ctx: FunctionEnvMut, name_ptr: c_int) -> c_int { // stub this in windows as it is not valid unsafe { let passwd_struct_offset = call_malloc(&mut ctx, mem::size_of::() as _); - let memory = ctx.data().memory_view(0, &ctx); + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); let passwd_struct_ptr = - emscripten_memory_pointer!(&memory, passwd_struct_offset) as *mut GuestPasswd; + emscripten_memory_pointer!(&view, passwd_struct_offset) as *mut GuestPasswd; (*passwd_struct_ptr).pw_name = 0; (*passwd_struct_ptr).pw_passwd = 0; (*passwd_struct_ptr).pw_gecos = 0; @@ -120,9 +125,10 @@ pub fn _getgrnam(mut ctx: FunctionEnvMut, name_ptr: c_int) -> c_int { // stub the group struct as it is not supported on windows unsafe { let group_struct_offset = call_malloc(&mut ctx, mem::size_of::() as _); - let memory = ctx.data().memory_view(0, &ctx); + let memory = ctx.data().memory(0); + let view = memory.view(&ctx); let group_struct_ptr = - emscripten_memory_pointer!(&memory, group_struct_offset) as *mut GuestGroup; + emscripten_memory_pointer!(&view, group_struct_offset) as *mut GuestGroup; (*group_struct_ptr).gr_name = 0; (*group_struct_ptr).gr_passwd = 0; (*group_struct_ptr).gr_gid = 0;