diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index 498be032e..9a81eea65 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -265,6 +265,11 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "___syscall63", ImportValue::Func(syscalls::___syscall63 as _), ); + import_object.set( + "env", + "___syscall142", + ImportValue::Func(syscalls::___syscall142 as _), + ); // Process import_object.set("env", "abort", ImportValue::Func(process::em_abort as _)); @@ -458,7 +463,7 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { mock_external!(import_object, ___syscall168); // mock_external!(import_object, ___syscall146); // mock_external!(import_object, ___syscall145); - mock_external!(import_object, ___syscall142); + // mock_external!(import_object, ___syscall142); mock_external!(import_object, ___syscall140); // mock_external!(import_object, ___syscall122); // mock_external!(import_object, ___syscall102); diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 795ab3297..07e1ee299 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -50,6 +50,7 @@ use libc::{ utsname, write, writev, + select, FIONBIO, }; @@ -183,7 +184,9 @@ pub extern "C" fn ___syscall54( 21537 => { // FIONBIO let argp: u32 = varargs.get(instance); let argp_ptr = instance.memory_offset_addr(0, argp as _); - unsafe { ioctl(fd, FIONBIO, argp_ptr) } + let ret = unsafe { ioctl(fd, FIONBIO, argp_ptr) }; + debug!("ret: {}", ret); + ret }, _ => unimplemented!(), } @@ -276,7 +279,11 @@ pub extern "C" fn ___syscall102( 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) } + let fd = unsafe { accept(socket, address, address_len_addr) }; + debug!("fd: {}", fd); + // nix::unistd::write(fd, "Hello, World!".as_bytes()).unwrap(); + // nix::unistd::fsync(fd).unwrap(); + fd } 6 => { debug!("socket: getsockname"); @@ -676,3 +683,26 @@ pub extern "C" fn ___syscall63( unsafe { dup2(src, dst) } } + +// newselect +pub extern "C" fn ___syscall142( + _which: c_int, + mut varargs: VarArgs, + instance: &mut Instance, +) -> c_int { + debug!("emscripten::___syscall142"); + + let nfds: i32 = varargs.get(instance); + let readfds: u32 = varargs.get(instance); + let writefds: u32 = varargs.get(instance); + let exceptfds: u32 = varargs.get(instance); + let _timeout: i32 = varargs.get(instance); + + assert!(nfds <= 64, "`nfds` must be less than or equal to 64"); + assert!(exceptfds == 0, "`exceptfds` is not supporrted"); + + let readfds_ptr = instance.memory_offset_addr(0, readfds as _) as _; + let writefds_ptr = instance.memory_offset_addr(0, writefds as _) as _; + + unsafe { select(nfds, readfds_ptr, writefds_ptr, 0 as _, 0 as _) } +} \ No newline at end of file diff --git a/src/webassembly/memory.rs b/src/webassembly/memory.rs index c06000819..e0a75b70a 100644 --- a/src/webassembly/memory.rs +++ b/src/webassembly/memory.rs @@ -60,15 +60,18 @@ impl LinearMemory { unsafe { mprotect( base, - (initial * Self::PAGE_SIZE) as _, + // (initial * Self::PAGE_SIZE) as _, + Self::DEFAULT_HEAP_SIZE, PROT_READ | PROT_WRITE, ) }, 0 ); } - + debug!("LinearMemory instantiated"); + debug!(" - usable: {:#x}..{:#x}", base as usize, (base as usize) + LinearMemory::DEFAULT_HEAP_SIZE); + debug!(" - guard: {:#x}..{:#x}", (base as usize) + LinearMemory::DEFAULT_HEAP_SIZE, (base as usize) + LinearMemory::DEFAULT_SIZE); Self { base, current: initial,