mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 21:21:33 +00:00
Squashed commit of the following:
commit 62d9da4e3e02251a0f61c904e826bc06cf964ff7 Author: Syrus <me@syrusakbary.com> Date: Sun Jul 7 18:16:34 2019 -0700 Fixed syscall221 commit a8fde9148d50d89616d8a85a68110b89e3273229 Author: Syrus <me@syrusakbary.com> Date: Sun Jul 7 18:16:04 2019 -0700 Improved ioctl use case commit 5ad109d39838624ad84232a4c17714b885835893 Merge:61526e2c
5cab8161
Author: Syrus <me@syrusakbary.com> Date: Sun Jul 7 17:44:25 2019 -0700 Merge branch 'command/dash' into feature/emscripten-update commit5cab816193
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 20:11:49 2019 +0200 Generic IOCTLs mapping commit5a0dc0374c
Merge:61cfed79
9d120ed3
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 17:15:02 2019 +0200 Merge remote-tracking branch 'origin/master' into command/dash commit61cfed7916
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 13:04:04 2019 +0200 Fixed implementation for syscalls 200, 201 and 202 commit91e26d1a0e
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 13:03:26 2019 +0200 Improved debug messages commit53a8fbeb2a
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 13:03:04 2019 +0200 [___syscall146] Move loop out of `unsafe` zone commitd6dd3696f1
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 13:01:31 2019 +0200 [___syscall140] Fixed types commitc827a6a993
Merge:2bc16826
5e18d04d
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Sat Jul 6 12:21:33 2019 +0200 Merge remote-tracking branch 'origin/master' into command/dash commit2bc16826b5
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Thu Jul 4 07:05:00 2019 +0200 Implement `getpgid` syscall commitd464954f58
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Thu Jul 4 07:04:36 2019 +0200 [fcntl64] Replace mock for real implementation commit3fe0183d85
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Thu Jul 4 07:03:39 2019 +0200 [ioctl] No-of for `TIOCSPGRP` command & code clean-up commitcc83ec9ac1
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Thu Jul 4 07:02:47 2019 +0200 [___syscall5] debug messages commit91587c8bde
Author: Jesús Leganés-Combarro 'piranna <piranna@gmail.com> Date: Thu Jul 4 07:02:20 2019 +0200 [___syscall57] debug messages
This commit is contained in:
@ -17,21 +17,22 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||
/// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32
|
||||
/// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html
|
||||
use libc::{
|
||||
// ENOTTY,
|
||||
c_int,
|
||||
c_void,
|
||||
chdir,
|
||||
// fcntl, setsockopt, getppid
|
||||
// setsockopt, getppid
|
||||
close,
|
||||
dup2,
|
||||
exit,
|
||||
fcntl,
|
||||
fstat,
|
||||
getpgid,
|
||||
getpid,
|
||||
// readlink,
|
||||
// iovec,
|
||||
lseek,
|
||||
off_t,
|
||||
// open,
|
||||
pid_t,
|
||||
read,
|
||||
rename,
|
||||
// sockaddr_in,
|
||||
@ -40,6 +41,7 @@ use libc::{
|
||||
// writev,
|
||||
stat,
|
||||
write,
|
||||
// ENOTTY,
|
||||
};
|
||||
use wasmer_runtime_core::{
|
||||
memory::ptr::{Array, WasmPtr},
|
||||
@ -227,6 +229,9 @@ pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
|
||||
let result: c_int = unsafe { libc::pipe(fd_ptr, 2048, 0) };
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let result: c_int = unsafe { libc::pipe(fd_ptr) };
|
||||
if result == -1 {
|
||||
debug!("=> os error: {}", Error::last_os_error());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
@ -306,9 +311,17 @@ pub fn ___syscall125(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall132(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall132");
|
||||
-1
|
||||
pub fn ___syscall132(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall132 (getpgid)");
|
||||
|
||||
let pid: pid_t = varargs.get(ctx);
|
||||
|
||||
let ret = unsafe { getpgid(pid) };
|
||||
debug!("=> pid: {} = {}", pid, ret);
|
||||
if ret == -1 {
|
||||
debug!("=> last os error: {}", Error::last_os_error(),);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn ___syscall133(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
@ -408,11 +421,11 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
// -> c_int
|
||||
debug!("emscripten::___syscall140 (lseek) {}", _which);
|
||||
let fd: i32 = varargs.get(ctx);
|
||||
let _offset_high: i32 = varargs.get(ctx); // We don't use the offset high as emscripten skips it
|
||||
let offset_low: i32 = varargs.get(ctx);
|
||||
let _offset_high: u32 = varargs.get(ctx); // We don't use the offset high as emscripten skips it
|
||||
let offset_low: u32 = varargs.get(ctx);
|
||||
let result_ptr_value: WasmPtr<i64> = varargs.get(ctx);
|
||||
let whence: i32 = varargs.get(ctx);
|
||||
let offset = offset_low as off_t;
|
||||
let offset = offset_low as i64;
|
||||
let ret = unsafe { lseek(fd, offset, whence) as i64 };
|
||||
|
||||
let result_ptr = result_ptr_value.deref(ctx.memory(0)).unwrap();
|
||||
@ -484,8 +497,8 @@ pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
|
||||
debug!("=> fd: {}, iov: {}, iovcnt = {}", fd, iov, iovcnt);
|
||||
let mut ret = 0;
|
||||
unsafe {
|
||||
for i in 0..iovcnt {
|
||||
for i in 0..iovcnt {
|
||||
unsafe {
|
||||
let guest_iov_addr =
|
||||
emscripten_memory_pointer!(ctx.memory(0), (iov + i * 8)) as *mut GuestIovec;
|
||||
let iov_base = emscripten_memory_pointer!(ctx.memory(0), (*guest_iov_addr).iov_base)
|
||||
@ -493,14 +506,21 @@ pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
let iov_len = (*guest_iov_addr).iov_len as _;
|
||||
// debug!("=> iov_addr: {:?}, {:?}", iov_base, iov_len);
|
||||
let curr = write(fd, iov_base, iov_len);
|
||||
debug!(
|
||||
"=> iov_base: {}, iov_len: {}, curr = {}",
|
||||
(*guest_iov_addr).iov_base,
|
||||
iov_len,
|
||||
curr
|
||||
);
|
||||
if curr < 0 {
|
||||
debug!("=> os error: {}", Error::last_os_error());
|
||||
return -1;
|
||||
}
|
||||
ret += curr;
|
||||
}
|
||||
// debug!(" => ret: {}", ret);
|
||||
ret as _
|
||||
}
|
||||
debug!(" => ret: {}", ret);
|
||||
ret as _
|
||||
}
|
||||
|
||||
pub fn ___syscall191(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
@ -542,13 +562,13 @@ pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
let mut _stat: stat = std::mem::zeroed();
|
||||
let ret = stat(real_path, &mut _stat);
|
||||
debug!(
|
||||
"=> pathname: {}, buf: {} = {}, last os error: {}",
|
||||
"=> pathname: {}, buf: {} = {}",
|
||||
std::ffi::CStr::from_ptr(real_path).to_str().unwrap(),
|
||||
buf,
|
||||
ret,
|
||||
Error::last_os_error()
|
||||
ret
|
||||
);
|
||||
if ret != 0 {
|
||||
debug!("=> os error: {}", Error::last_os_error());
|
||||
return ret;
|
||||
}
|
||||
copy_stat_into_wasm(ctx, buf, &_stat);
|
||||
@ -559,19 +579,20 @@ pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
// fstat64
|
||||
pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall197 (fstat64) {}", _which);
|
||||
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
let buf: u32 = varargs.get(ctx);
|
||||
|
||||
unsafe {
|
||||
let mut stat = std::mem::zeroed();
|
||||
let ret = fstat(fd, &mut stat);
|
||||
debug!("ret: {}", ret);
|
||||
debug!("=> fd: {}, buf: {} = {}", fd, buf, ret);
|
||||
if ret != 0 {
|
||||
debug!("=> os error: {}", Error::last_os_error());
|
||||
return ret;
|
||||
}
|
||||
copy_stat_into_wasm(ctx, buf, &stat);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
@ -594,18 +615,19 @@ pub fn ___syscall218(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall221 (fcntl64) {}", _which);
|
||||
// fcntl64
|
||||
let _fd: i32 = varargs.get(ctx);
|
||||
let cmd: u32 = varargs.get(ctx);
|
||||
let fd: i32 = varargs.get(ctx);
|
||||
let cmd: i32 = varargs.get(ctx);
|
||||
let arg: i32 = varargs.get(ctx);
|
||||
// (FAPPEND - 0x08
|
||||
// |FASYNC - 0x40
|
||||
// |FFSYNC - 0x80
|
||||
// |FNONBLOCK - 0x04
|
||||
debug!("=> fd: {}, cmd: {}", _fd, cmd);
|
||||
match cmd {
|
||||
1 | 2 => 0,
|
||||
13 | 14 => 0, // pretend file locking worked
|
||||
_ => -1,
|
||||
let ret = unsafe { fcntl(fd, cmd, arg) };
|
||||
debug!("=> fd: {}, cmd: {} = {}", fd, cmd, ret);
|
||||
if ret == -1 {
|
||||
debug!("=> last os error: {}", Error::last_os_error(),);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn ___syscall268(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
|
Reference in New Issue
Block a user