Skip to content

Commit

Permalink
move unix code to unix only location
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Jul 1, 2019
1 parent 623bec0 commit a417189
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
38 changes: 0 additions & 38 deletions lib/emscripten/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,44 +276,6 @@ pub fn ___syscall75(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}

// readlink
pub fn ___syscall85(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall85 (readlink)");
let pathname_addr = varargs.get_str(ctx);
let buf = varargs.get_str(ctx);
// let buf_addr: i32 = varargs.get(ctx);
let buf_size: i32 = varargs.get(ctx);
let real_path_owned = get_cstr_path(ctx, pathname_addr);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
pathname_addr
};
// let fd = 3;
// let ret = unsafe { read(fd, buf as _, buf_size as _) as i32 };
// debug!(
// "=> buf: {}, buf_size: {}, return: {} ",
// unsafe { std::ffi::CStr::from_ptr(buf as _).to_str().unwrap() },
// buf_size,
// ret
// );
let ret = unsafe { libc::readlink(real_path, buf as _, buf_size as _) as i32 };
if ret == -1 {
debug!("readlink failed");
return ret;
}
debug!(
"=> path: {}, buf: {}, buf_size: {}, return: {} ",
unsafe { std::ffi::CStr::from_ptr(real_path).to_str().unwrap() },
unsafe { std::ffi::CStr::from_ptr(buf as _).to_str().unwrap() },
// std::ffi::CStr::from_ptr(buf).to_str().unwrap(),
// buf,
buf_size,
ret
);
ret
}

pub fn ___syscall91(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall91 - stub");
0
Expand Down
31 changes: 30 additions & 1 deletion lib/emscripten/src/syscalls/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use std::ffi::CStr;
use wasmer_runtime_core::{memory::ptr::WasmPtr, vm::Ctx};

use crate::env::EmSockAddr;
use crate::utils;
use crate::utils::{self, get_cstr_path};
#[allow(unused_imports)]
use std::io::Error;
use std::mem;
Expand Down Expand Up @@ -187,6 +187,35 @@ pub fn ___syscall83(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
result
}

/// readlink
pub fn ___syscall85(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall85 (readlink)");
let pathname_addr = varargs.get_str(ctx);
let buf = varargs.get_str(ctx);
// let buf_addr: i32 = varargs.get(ctx);
let buf_size: i32 = varargs.get(ctx);
let real_path_owned = get_cstr_path(ctx, pathname_addr);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
pathname_addr
};

let ret = unsafe { libc::readlink(real_path, buf as _, buf_size as _) as i32 };
if ret == -1 {
debug!("readlink failed");
return ret;
}
debug!(
"=> path: {}, buf: {}, buf_size: {}, return: {} ",
unsafe { std::ffi::CStr::from_ptr(real_path).to_str().unwrap() },
unsafe { std::ffi::CStr::from_ptr(buf as _).to_str().unwrap() },
buf_size,
ret
);
ret
}

/// ftruncate64
pub fn ___syscall194(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall194 (ftruncate64) {}", _which);
Expand Down
6 changes: 6 additions & 0 deletions lib/emscripten/src/syscalls/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ pub fn ___syscall83(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
unimplemented!()
}

/// readlink
pub fn ___syscall85(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall85 (readlink) {}", _which);
-1
}

/// lchown
pub fn ___syscall198(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall198 (lchown) {}", _which);
Expand Down

0 comments on commit a417189

Please sign in to comment.