Reafactor varargs macro

This commit is contained in:
Steve Akinyemi 2018-11-22 10:43:38 +01:00
parent 453b7c9f12
commit c7ac71b0e4
2 changed files with 20 additions and 18 deletions

View File

@ -1,49 +1,51 @@
/// NOTE: These syscalls only support wasm_32 for now because they take u32 offset /// NOTE: TODO: These syscalls only support wasm_32 for now because they take u32 offset
/// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html /// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html
use libc::{c_int, c_void, ssize_t, write}; use libc::{c_int, c_void, ssize_t, write};
#[macro_use]
use macros;
use crate::webassembly::Instance; use crate::webassembly::Instance;
use super::varargs::VarArgs;
/// sys_read /// sys_read
pub extern "C" fn ___syscall3(_which: c_int, mut _varargs: VarArgs, _instance: &mut Instance) -> ssize_t { pub extern "C" fn ___syscall3(_which: c_int, mut _varargs: c_int, _instance: &mut Instance) -> ssize_t {
debug!("emscripten::___syscall3"); debug!("emscripten::___syscall3");
0 0
} }
/// sys_write /// sys_write
pub extern "C" fn ___syscall4(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int { pub extern "C" fn ___syscall4(_which: c_int, mut varargs: c_int, instance: &mut Instance) -> c_int {
let fd: i32 = varargs.get(instance); debug!("emscripten::___syscall4");
let buf_ptr: u32 = varargs.get(instance); let fd = vararg!(fd, i32, instance, varargs);
let count: u32 = varargs.get(instance); let buf_ptr = vararg!(buf_ptr, u32, instance, varargs);
let count = vararg!(count, u32, instance, varargs);
debug!("fd: {}, buf_ptr: {}, count: {}", fd, buf_ptr, count); debug!("fd: {}, buf_ptr: {}, count: {}", fd, buf_ptr, count);
let buf = instance.memory_offset_addr(0, buf_ptr as usize) as *const c_void; let buf = instance.memory_offset_addr(0, buf_ptr as usize) as *const c_void;
unsafe { write(fd, buf, count as usize) as i32 } unsafe { write(fd, buf, count as usize) as i32 }
} }
/// sys_open /// sys_open
pub extern "C" fn ___syscall5(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int { pub extern "C" fn ___syscall5(_which: c_int, mut varargs: c_int, instance: &mut Instance) -> c_int {
debug!("emscripten::___syscall5"); debug!("emscripten::___syscall5");
let pathname: u32 = varargs.get(instance); let pathname = vararg!(pathname, u32, instance, varargs);
let flags: u32 = varargs.get(instance); let flags = vararg!(flags, u32, instance, varargs);
let mode: u32 = varargs.get(instance); let mode = vararg!(mode, u32, instance, varargs);
debug!("pathname: {}, flags: {}, mode: {}", pathname, flags, mode); debug!("pathname: {}, flags: {}, mode: {}", pathname, flags, mode);
-2 -2
} }
// sys_ioctl // sys_ioctl
pub extern "C" fn ___syscall54(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int { pub extern "C" fn ___syscall54(_which: c_int, mut varargs: c_int, instance: &mut Instance) -> c_int {
debug!("emscripten::___syscall54"); debug!("emscripten::___syscall54");
let stream: u32 = varargs.get(instance); let stream = vararg!(stream, u32, instance, varargs);
let op: u32 = varargs.get(instance); let op = vararg!(op, u32, instance, varargs);
debug!("stream: {}, op: {}", stream, op); debug!("stream: {}, op: {}", stream, op);
0 0
} }
// sys_newuname // sys_newuname
pub extern "C" fn ___syscall122(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int { pub extern "C" fn ___syscall122(_which: c_int, mut varargs: c_int, instance: &mut Instance) -> c_int {
debug!("emscripten::___syscall122"); debug!("emscripten::___syscall122");
let buf: u32 = varargs.get(instance); let buf = vararg!(buf, u32, instance, varargs);
debug!("buf: {}", buf); debug!("buf: {}", buf);
0 0
} }

View File

@ -28,4 +28,4 @@ macro_rules! include_wast2wasm_bytes {
macro_rules! debug { macro_rules! debug {
($fmt:expr) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt)) }); ($fmt:expr) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt)) });
($fmt:expr, $($arg:tt)*) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt, "\n"), $($arg)*) }); ($fmt:expr, $($arg:tt)*) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt, "\n"), $($arg)*) });
} }