right to the out buffer that was passed in syscall183

This commit is contained in:
Mackenzie Clark 2019-02-22 14:54:01 -08:00
parent 0f9369c67d
commit 966be3ee8f

View File

@ -48,6 +48,7 @@ use std::slice;
// Other platforms do otherwise. // Other platforms do otherwise.
use crate::env::get_emscripten_data; use crate::env::get_emscripten_data;
use crate::utils::copy_cstr_into_wasm; use crate::utils::copy_cstr_into_wasm;
use crate::utils::read_string_from_wasm;
#[cfg(target_os = "darwin")] #[cfg(target_os = "darwin")]
use libc::SO_NOSIGPIPE; use libc::SO_NOSIGPIPE;
use std::ffi::CString; use std::ffi::CString;
@ -191,20 +192,21 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
} }
// getcwd // getcwd
pub fn ___syscall183(ctx: &mut Ctx, buf: u32, _size: u32) -> u32 { pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 {
debug!("emscripten::___syscall183"); debug!("emscripten::___syscall183");
use std::env; use std::env;
let path = env::current_dir(); let path = env::current_dir();
match path { let path_string = path.unwrap().display().to_string();
Ok(path_buf) => { let len = path_string.len();
// write path into buffer unsafe {
let path_string = path_buf.display().to_string(); let pointer_to_buffer = emscripten_memory_pointer!(ctx.memory(0), buf_offset) as *mut libc::c_char;
let path_c_string = CString::new(path_string).unwrap(); let slice = slice::from_raw_parts_mut(pointer_to_buffer, len.clone());
let offset = unsafe { copy_cstr_into_wasm(ctx, path_c_string.as_ptr()) }; for (byte, loc) in path_string.bytes().zip(slice.iter_mut()) {
offset *loc = byte as _;
} }
Err(e) => panic!("Failed to read current directory from environment."), *pointer_to_buffer.add(len.clone()) = 0;
} }
buf_offset
} }
// mmap2 // mmap2