mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-30 09:01:33 +00:00
Runs up to socket/ioctl/sigaction functions
This commit is contained in:
40
Cargo.lock
generated
40
Cargo.lock
generated
@ -27,7 +27,7 @@ name = "atty"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -50,7 +50,7 @@ version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -211,7 +211,7 @@ version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -221,7 +221,7 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -283,12 +283,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.43"
|
||||
source = "git+https://github.com/rust-lang/libc#5cc006652a242c35b6fe5b615ccd39d9356a2346"
|
||||
version = "0.2.44"
|
||||
source = "git+https://github.com/rust-lang/libc#d4b45f51ea751d9685a956b9c011698359e4cc06"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.43"
|
||||
version = "0.2.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -304,7 +304,7 @@ name = "mach"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -313,7 +313,7 @@ version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -322,7 +322,7 @@ name = "memmap"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -339,7 +339,7 @@ dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -353,7 +353,7 @@ name = "num_cpus"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -378,7 +378,7 @@ version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -409,7 +409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -454,7 +454,7 @@ dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -597,7 +597,7 @@ name = "termion"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -684,7 +684,7 @@ dependencies = [
|
||||
"cranelift-wasm 0.23.0",
|
||||
"docopt 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (git+https://github.com/rust-lang/libc)",
|
||||
"libc 0.2.44 (git+https://github.com/rust-lang/libc)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -756,8 +756,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum libc 0.2.43 (git+https://github.com/rust-lang/libc)" = "<none>"
|
||||
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||
"checksum libc 0.2.44 (git+https://github.com/rust-lang/libc)" = "<none>"
|
||||
"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311"
|
||||
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
|
||||
"checksum mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9"
|
||||
"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
|
||||
|
@ -101,10 +101,5 @@ pub extern fn _localtime_r() -> u32 {
|
||||
|
||||
pub extern fn _getpagesize() -> u32 {
|
||||
debug!("emscripten::_getpagesize");
|
||||
LinearMemory::PAGE_SIZE
|
||||
}
|
||||
|
||||
pub extern fn _prlimit(pid: c_int, resource: c_int, new_limit: c_int, old_limit: c_int, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::_prlimit {} {} {} {}", pid, resource, new_limit, old_limit);
|
||||
0
|
||||
16384
|
||||
}
|
@ -59,7 +59,7 @@ macro_rules! mock_external {
|
||||
($import:ident, $name:ident) => {{
|
||||
extern fn _mocked_fn() -> i32 {
|
||||
debug!("emscripten::{} <mock>", stringify!($name));
|
||||
0
|
||||
-1
|
||||
}
|
||||
$import.set(
|
||||
"env",
|
||||
@ -225,6 +225,52 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
"___syscall202",
|
||||
ImportValue::Func(syscalls::___syscall202 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall340",
|
||||
ImportValue::Func(syscalls::___syscall340 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall197",
|
||||
ImportValue::Func(syscalls::___syscall197 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall180",
|
||||
ImportValue::Func(syscalls::___syscall180 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall39",
|
||||
ImportValue::Func(syscalls::___syscall39 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall195",
|
||||
ImportValue::Func(syscalls::___syscall195 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall212",
|
||||
ImportValue::Func(syscalls::___syscall212 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall221",
|
||||
ImportValue::Func(syscalls::___syscall221 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall102",
|
||||
ImportValue::Func(syscalls::___syscall102 as *const u8),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"___syscall54",
|
||||
ImportValue::Func(syscalls::___syscall54 as *const u8),
|
||||
);
|
||||
|
||||
// Process
|
||||
import_object.set(
|
||||
"env",
|
||||
@ -388,34 +434,34 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
// mock_external!(import_object, ___syscall64);
|
||||
mock_external!(import_object, ___syscall63);
|
||||
mock_external!(import_object, ___syscall60);
|
||||
mock_external!(import_object, ___syscall54);
|
||||
mock_external!(import_object, ___syscall39);
|
||||
// mock_external!(import_object, ___syscall54);
|
||||
// mock_external!(import_object, ___syscall39);
|
||||
mock_external!(import_object, ___syscall38);
|
||||
mock_external!(import_object, ___syscall340);
|
||||
// mock_external!(import_object, ___syscall340);
|
||||
mock_external!(import_object, ___syscall334);
|
||||
mock_external!(import_object, ___syscall300);
|
||||
mock_external!(import_object, ___syscall295);
|
||||
mock_external!(import_object, ___syscall272);
|
||||
mock_external!(import_object, ___syscall268);
|
||||
mock_external!(import_object, ___syscall221);
|
||||
// mock_external!(import_object, ___syscall221);
|
||||
mock_external!(import_object, ___syscall220);
|
||||
mock_external!(import_object, ___syscall212);
|
||||
// mock_external!(import_object, ___syscall212);
|
||||
// mock_external!(import_object, ___syscall201);
|
||||
mock_external!(import_object, ___syscall199);
|
||||
mock_external!(import_object, ___syscall197);
|
||||
// mock_external!(import_object, ___syscall197);
|
||||
mock_external!(import_object, ___syscall196);
|
||||
mock_external!(import_object, ___syscall195);
|
||||
// mock_external!(import_object, ___syscall195);
|
||||
mock_external!(import_object, ___syscall194);
|
||||
mock_external!(import_object, ___syscall191);
|
||||
mock_external!(import_object, ___syscall181);
|
||||
mock_external!(import_object, ___syscall180);
|
||||
// mock_external!(import_object, ___syscall180);
|
||||
mock_external!(import_object, ___syscall168);
|
||||
// mock_external!(import_object, ___syscall146);
|
||||
// mock_external!(import_object, ___syscall145);
|
||||
mock_external!(import_object, ___syscall142);
|
||||
mock_external!(import_object, ___syscall140);
|
||||
// mock_external!(import_object, ___syscall122);
|
||||
mock_external!(import_object, ___syscall102);
|
||||
// mock_external!(import_object, ___syscall102);
|
||||
// mock_external!(import_object, ___syscall20);
|
||||
mock_external!(import_object, ___syscall15);
|
||||
mock_external!(import_object, ___syscall10);
|
||||
|
@ -12,10 +12,13 @@ use libc::{
|
||||
sendto, recvfrom, setsockopt,
|
||||
getsockopt, sendmsg, recvmsg,
|
||||
msghdr, getpid, getppid, pid_t,
|
||||
gid_t, getgid,
|
||||
gid_t, getgid, fstat, stat,
|
||||
pread, mkdir, chown,
|
||||
};
|
||||
use crate::webassembly::Instance;
|
||||
use super::varargs::VarArgs;
|
||||
use std::{slice, mem};
|
||||
use super::utils::copy_stat_into_wasm;
|
||||
|
||||
/// sys_exit
|
||||
pub extern "C" fn ___syscall1(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) {
|
||||
@ -54,12 +57,18 @@ pub extern "C" fn ___syscall5(_which: c_int, mut varargs: VarArgs, instance: &mu
|
||||
let mode: u32 = varargs.get(instance);
|
||||
debug!("pathname: {}, flags: {}, mode: {}", pathname, flags, mode);
|
||||
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
|
||||
unsafe { open(pathname_addr, flags, mode) }
|
||||
unsafe {
|
||||
let s = std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap();
|
||||
debug!("path: {}", s);
|
||||
}
|
||||
let fd = unsafe { open(pathname_addr, flags, mode) };
|
||||
debug!("fd: {}", fd);
|
||||
fd
|
||||
}
|
||||
|
||||
/// sys_close
|
||||
pub extern "C" fn ___syscall6(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall1");
|
||||
debug!("emscripten::___syscall6");
|
||||
let fd: i32 = varargs.get(instance);
|
||||
debug!("fd: {}", fd);
|
||||
unsafe { close(fd) }
|
||||
@ -68,10 +77,11 @@ pub extern "C" fn ___syscall6(_which: c_int, mut varargs: VarArgs, instance: &mu
|
||||
/// sys_ioctl
|
||||
pub extern "C" fn ___syscall54(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall54");
|
||||
let fd: i32 = varargs.get(instance);
|
||||
let request: u64 = varargs.get(instance);
|
||||
debug!("fd: {}, op: {}", fd, request);
|
||||
unsafe { ioctl(fd, request) }
|
||||
// let fd: i32 = varargs.get(instance);
|
||||
// let request: u32 = varargs.get(instance);
|
||||
// debug!("fd: {}, op: {}", fd, request);
|
||||
// unsafe { ioctl(fd, request as _) }
|
||||
0
|
||||
}
|
||||
|
||||
/// sys_uname
|
||||
@ -116,124 +126,139 @@ pub extern "C" fn ___syscall146(_which: c_int, mut varargs: VarArgs, instance: &
|
||||
unsafe { writev(fd, iov_addr, iovcnt) }
|
||||
}
|
||||
|
||||
/// sys_fcntl64
|
||||
pub extern "C" fn ___syscall221(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall221");
|
||||
let fd: i32 = varargs.get(instance);
|
||||
let cmd: i32 = varargs.get(instance);
|
||||
debug!("fd: {}, cmd: {}", fd, cmd);
|
||||
unsafe { fcntl(fd, cmd) }
|
||||
}
|
||||
// /// sys_fcntl64
|
||||
// pub extern "C" fn ___syscall221(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
// debug!("emscripten::___syscall221");
|
||||
// let fd: i32 = varargs.get(instance);
|
||||
// let cmd: i32 = varargs.get(instance);
|
||||
// debug!("fd: {}, cmd: {}", fd, cmd);
|
||||
// unsafe { fcntl(fd, cmd) }
|
||||
// }
|
||||
|
||||
// sys_socketcall
|
||||
pub extern "C" fn ___syscall102(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall102");
|
||||
let call: u32 = varargs.get(instance);
|
||||
let mut socket_varargs: VarArgs = varargs.get(instance);
|
||||
match call {
|
||||
1 => { // socket (domain: c_int, ty: c_int, protocol: c_int) -> c_int
|
||||
let domain: i32 = varargs.get(instance);
|
||||
let ty: i32 = varargs.get(instance);
|
||||
let protocol: i32 = varargs.get(instance);
|
||||
unsafe { socket(domain, ty, protocol) }
|
||||
let domain: i32 = socket_varargs.get(instance);
|
||||
let ty: i32 = socket_varargs.get(instance);
|
||||
let protocol: i32 = socket_varargs.get(instance);
|
||||
let socket = unsafe { socket(domain, ty, protocol) };
|
||||
debug!("socket: {}", socket);
|
||||
socket
|
||||
},
|
||||
2 => { // bind (socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int
|
||||
// TODO: Emscripten has a different signature.
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
unsafe { bind(socket, address, address_len) }
|
||||
},
|
||||
3 => { // connect (socket: c_int, address: *const sockaddr, len: socklen_t) -> c_int
|
||||
// TODO: Emscripten has a different signature.
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
unsafe { connect(socket, address, address_len) }
|
||||
},
|
||||
4 => { // listen (socket: c_int, backlog: c_int) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let backlog: i32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let backlog: i32 = socket_varargs.get(instance);
|
||||
unsafe { listen(socket, backlog) }
|
||||
},
|
||||
5 => { // accept (socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
let address_len_addr = instance.memory_offset_addr(0, address_len as usize) as *mut socklen_t;
|
||||
unsafe { accept(socket, address, address_len_addr) }
|
||||
},
|
||||
6 => { // getsockname (socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
let address_len_addr = instance.memory_offset_addr(0, address_len as usize) as *mut socklen_t;
|
||||
unsafe { getsockname(socket, address, address_len_addr) }
|
||||
},
|
||||
7 => { // getpeername (socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
let address_len_addr = instance.memory_offset_addr(0, address_len as usize) as *mut socklen_t;
|
||||
unsafe { getpeername(socket, address, address_len_addr) }
|
||||
},
|
||||
11 => { // sendto (socket: c_int, buf: *const c_void, len: size_t, flags: c_int, addr: *const sockaddr, addrlen: socklen_t) -> ssize_t
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let buf: u32 = varargs.get(instance);
|
||||
let flags: usize = varargs.get(instance);
|
||||
let len: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let buf: u32 = socket_varargs.get(instance);
|
||||
let flags: usize = socket_varargs.get(instance);
|
||||
let len: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let buf_addr = instance.memory_offset_addr(0, buf as usize) as *mut c_void;
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
unsafe { sendto(socket, buf_addr, flags, len, address, address_len) as i32 }
|
||||
},
|
||||
12 => { // recvfrom (socket: c_int, buf: *const c_void, len: size_t, flags: c_int, addr: *const sockaddr, addrlen: socklen_t) -> ssize_t
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let buf: u32 = varargs.get(instance);
|
||||
let flags: usize = varargs.get(instance);
|
||||
let len: i32 = varargs.get(instance);
|
||||
let address: u32 = varargs.get(instance);
|
||||
let address_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let buf: u32 = socket_varargs.get(instance);
|
||||
let flags: usize = socket_varargs.get(instance);
|
||||
let len: i32 = socket_varargs.get(instance);
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let buf_addr = instance.memory_offset_addr(0, buf as usize) as *mut c_void;
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
let address_len_addr = instance.memory_offset_addr(0, address_len as usize) as *mut socklen_t;
|
||||
unsafe { recvfrom(socket, buf_addr, flags, len, address, address_len_addr) as i32 }
|
||||
},
|
||||
14 => { // setsockopt (socket: c_int, level: c_int, name: c_int, value: *const c_void, option_len: socklen_t) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let level: i32 = varargs.get(instance);
|
||||
let name: i32 = varargs.get(instance);
|
||||
let value: u32 = varargs.get(instance);
|
||||
let option_len: u32 = varargs.get(instance);
|
||||
let value_addr = instance.memory_offset_addr(0, value as usize) as *const c_void;
|
||||
unsafe { setsockopt(socket, level, name, value_addr, option_len) }
|
||||
// let socket: i32 = socket_varargs.get(instance);
|
||||
// debug!("socket: {}", socket);
|
||||
// let level: i32 = socket_varargs.get(instance);
|
||||
// debug!("level: {}", level);
|
||||
// let name: i32 = socket_varargs.get(instance);
|
||||
// debug!("name: {}", name);
|
||||
// let value: u32 = socket_varargs.get(instance);
|
||||
// debug!("value: {:#x}", value);
|
||||
// let option_len: u32 = socket_varargs.get(instance);
|
||||
// debug!("option_len: {}", option_len);
|
||||
// let value_addr = instance.memory_offset_addr(0, value as usize) as *const c_void;
|
||||
|
||||
// let ret = unsafe { setsockopt(socket, level, name, value_addr, option_len) };
|
||||
// debug!("ret: {}", ret);
|
||||
// if ret != 0 {
|
||||
// debug!("errno: {}", nix::errno::errno());
|
||||
// }
|
||||
// ret
|
||||
0
|
||||
},
|
||||
15 => { // getsockopt (sockfd: c_int, level: c_int, optname: c_int, optval: *mut c_void, optlen: *mut socklen_t) -> c_int
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let level: i32 = varargs.get(instance);
|
||||
let name: i32 = varargs.get(instance);
|
||||
let value: u32 = varargs.get(instance);
|
||||
let option_len: u32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let level: i32 = socket_varargs.get(instance);
|
||||
let name: i32 = socket_varargs.get(instance);
|
||||
let value: u32 = socket_varargs.get(instance);
|
||||
let option_len: u32 = socket_varargs.get(instance);
|
||||
let value_addr = instance.memory_offset_addr(0, value as usize) as *mut c_void;
|
||||
let option_len_addr = instance.memory_offset_addr(0, option_len as usize) as *mut socklen_t;
|
||||
unsafe { getsockopt(socket, level, name, value_addr, option_len_addr) }
|
||||
},
|
||||
16 => { // sendmsg (fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let msg: u32 = varargs.get(instance);
|
||||
let flags: i32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let msg: u32 = socket_varargs.get(instance);
|
||||
let flags: i32 = socket_varargs.get(instance);
|
||||
let msg_addr = instance.memory_offset_addr(0, msg as usize) as *const msghdr;
|
||||
unsafe { sendmsg(socket, msg_addr, flags) as i32 }
|
||||
},
|
||||
17 => { // recvmsg (fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t
|
||||
let socket: i32 = varargs.get(instance);
|
||||
let msg: u32 = varargs.get(instance);
|
||||
let flags: i32 = varargs.get(instance);
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
let msg: u32 = socket_varargs.get(instance);
|
||||
let flags: i32 = socket_varargs.get(instance);
|
||||
let msg_addr = instance.memory_offset_addr(0, msg as usize) as *mut msghdr;
|
||||
unsafe { recvmsg(socket, msg_addr, flags) as i32 }
|
||||
},
|
||||
@ -284,3 +309,99 @@ pub extern "C" fn ___syscall340(_which: c_int, mut varargs: VarArgs, instance: &
|
||||
// NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway.
|
||||
0
|
||||
}
|
||||
|
||||
|
||||
// sys_fstat64
|
||||
pub extern "C" fn ___syscall197(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall197");
|
||||
let fd: c_int = varargs.get(instance);
|
||||
let buf: u32 = varargs.get(instance);
|
||||
|
||||
unsafe {
|
||||
let mut stat = std::mem::zeroed();
|
||||
let ret = fstat(fd, &mut stat);
|
||||
debug!("ret: {}", ret);
|
||||
if ret != 0 {
|
||||
return ret;
|
||||
}
|
||||
copy_stat_into_wasm(instance, buf, &stat);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
// sys_pread
|
||||
pub extern "C" fn ___syscall180(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall180");
|
||||
let fd: i32 = varargs.get(instance);
|
||||
let buf: u32 = varargs.get(instance);
|
||||
let count: u32 = varargs.get(instance);
|
||||
{
|
||||
let zero: u32 = varargs.get(instance);
|
||||
assert_eq!(zero, 0);
|
||||
}
|
||||
let offset: i64 = varargs.get(instance);
|
||||
|
||||
let buf_ptr = instance.memory_offset_addr(0, buf as _) as _;
|
||||
|
||||
unsafe {
|
||||
pread(fd, buf_ptr, count as _, offset) as _
|
||||
}
|
||||
}
|
||||
|
||||
// sys_mkdir
|
||||
pub extern "C" fn ___syscall39(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall39");
|
||||
let pathname: u32 = varargs.get(instance);
|
||||
let mode: u32 = varargs.get(instance);
|
||||
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
|
||||
|
||||
unsafe {
|
||||
mkdir(pathname_addr, mode as _)
|
||||
}
|
||||
}
|
||||
|
||||
// sys_stat64
|
||||
pub extern "C" fn ___syscall195(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall195");
|
||||
let pathname: u32 = varargs.get(instance);
|
||||
let buf: u32 = varargs.get(instance);
|
||||
|
||||
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
|
||||
|
||||
unsafe {
|
||||
let mut _stat: stat = std::mem::zeroed();
|
||||
let ret = stat(pathname_addr, &mut _stat);
|
||||
debug!("ret: {}", ret);
|
||||
if ret != 0 {
|
||||
return ret;
|
||||
}
|
||||
copy_stat_into_wasm(instance, buf, &_stat);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
// sys_chown
|
||||
pub extern "C" fn ___syscall212(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::___syscall212");
|
||||
|
||||
let pathname: u32 = varargs.get(instance);
|
||||
let owner: u32 = varargs.get(instance);
|
||||
let group: u32 = varargs.get(instance);
|
||||
|
||||
let pathname_addr = instance.memory_offset_addr(0, pathname as usize) as *const i8;
|
||||
|
||||
unsafe {
|
||||
chown(pathname_addr, owner, group)
|
||||
}
|
||||
}
|
||||
|
||||
// sys_fcntl64
|
||||
pub extern "C" fn ___syscall221(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
|
||||
let fd: i32 = varargs.get(instance);
|
||||
let cmd: u32 = varargs.get(instance);
|
||||
match cmd {
|
||||
2 => 0,
|
||||
_ => -1,
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ use crate::webassembly::Instance;
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
use std::{slice, mem};
|
||||
use libc::stat;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
/// We check if a provided module is an Emscripten generated one
|
||||
pub fn is_emscripten_module(module: &Module) -> bool {
|
||||
@ -40,6 +42,31 @@ pub unsafe fn copy_terminated_array_of_cstrs(instance: &mut Instance, cstrs: *mu
|
||||
0
|
||||
}
|
||||
|
||||
pub unsafe fn copy_stat_into_wasm(instance: &mut Instance, buf: u32, stat: &stat) {
|
||||
let buf_ptr = instance.memory_offset_addr(0, buf as _) as *mut u8;
|
||||
let mut buf = unsafe { slice::from_raw_parts_mut(buf_ptr, 76) };
|
||||
|
||||
LittleEndian::write_u32(&mut buf[..], stat.st_dev as _);
|
||||
LittleEndian::write_u32(&mut buf[4..], 0);
|
||||
LittleEndian::write_u32(&mut buf[8..], stat.st_ino as _);
|
||||
LittleEndian::write_u32(&mut buf[12..], stat.st_mode as _);
|
||||
LittleEndian::write_u32(&mut buf[16..], stat.st_nlink as _);
|
||||
LittleEndian::write_u32(&mut buf[20..], stat.st_uid);
|
||||
LittleEndian::write_u32(&mut buf[24..], stat.st_gid);
|
||||
LittleEndian::write_u32(&mut buf[28..], stat.st_rdev as _);
|
||||
LittleEndian::write_u32(&mut buf[32..], 0);
|
||||
LittleEndian::write_u32(&mut buf[36..], stat.st_size as _);
|
||||
LittleEndian::write_u32(&mut buf[40..], 4096);
|
||||
LittleEndian::write_u32(&mut buf[44..], stat.st_blocks as _);
|
||||
LittleEndian::write_u32(&mut buf[48..], stat.st_atime as _);
|
||||
LittleEndian::write_u32(&mut buf[52..], 0);
|
||||
LittleEndian::write_u32(&mut buf[56..], stat.st_mtime as _);
|
||||
LittleEndian::write_u32(&mut buf[60..], 0);
|
||||
LittleEndian::write_u32(&mut buf[64..], stat.st_ctime as _);
|
||||
LittleEndian::write_u32(&mut buf[68..], 0);
|
||||
LittleEndian::write_u32(&mut buf[72..], stat.st_ino as _);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::generate_emscripten_env;
|
||||
|
@ -7,7 +7,7 @@ pub struct VarArgs {
|
||||
}
|
||||
|
||||
impl VarArgs {
|
||||
pub fn get<T: Copy>(&mut self, instance: &mut Instance) -> T {
|
||||
pub fn get<T: Sized>(&mut self, instance: &mut Instance) -> T {
|
||||
let ptr = instance.memory_offset_addr(0, self.pointer as usize);
|
||||
self.pointer += mem::size_of::<T>() as u32;
|
||||
unsafe { (ptr as *const T).read() }
|
||||
|
Reference in New Issue
Block a user