diff --git a/.gitignore b/.gitignore index 52c89dacb..056e2c12d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/*.rs.bk /artifacts .DS_Store +.idea diff --git a/examples/nginx/.gitignore b/examples/nginx/.gitignore index e46878d35..8eafb1260 100644 --- a/examples/nginx/.gitignore +++ b/examples/nginx/.gitignore @@ -1 +1,2 @@ *_temp +logs/error.log \ No newline at end of file diff --git a/examples/nginx/logs/nginx.pid b/examples/nginx/logs/nginx.pid index 918d79d8e..79e054800 100644 --- a/examples/nginx/logs/nginx.pid +++ b/examples/nginx/logs/nginx.pid @@ -1 +1 @@ -96248 +21011 diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 17cc91678..efd7a17b7 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -68,6 +68,7 @@ use libc::{ F_GETFD, F_SETFD, SOL_SOCKET, + SO_REUSEADDR, TIOCGWINSZ, }; @@ -335,18 +336,17 @@ pub extern "C" fn ___syscall102( unsafe { ioctl(fd, FIOCLEX); }; - if cfg!(target_os = "darwin") { - type T = u32; - let payload = 1 as *const T as *const c_void; - unsafe { - setsockopt( - fd, - SOL_SOCKET, - SO_NOSIGPIPE, - payload, - mem::size_of::() as socklen_t, - ); - }; + + type T = u32; + let payload = 1 as *const T as *const c_void; + unsafe { + setsockopt( + fd, + SOL_SOCKET, + SO_NOSIGPIPE, + payload, + mem::size_of::() as socklen_t, + ); }; debug!( @@ -363,14 +363,6 @@ pub extern "C" fn ___syscall102( 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 { - // debug!( - // "=> address.sin_family: {:?}, address.sin_port: {:?}, address.sin_addr.s_addr: {:?}", - // (*address).sin_family, (*address).sin_port, (*address).sin_addr.s_addr - // ); - // } - // we convert address as a sockaddr (even if this is incorrect), to bypass the type - // issue with libc bind // Debug received address unsafe { @@ -436,25 +428,14 @@ pub extern "C" fn ___syscall102( (*address_linux).sa_family = (*address).sa_family as u16; (*address_linux).sa_data = (*address).sa_data; }; - // // Debug received address - // unsafe { - // let proper_address = address as *const GuestSockaddrIn; - // debug!( - // "=> address.sin_family: {:?}, address.sin_port: {:?}, address.sin_addr.s_addr: {:?}", - // (*proper_address).sin_family, (*proper_address).sin_port, (*proper_address).sin_addr.s_addr - // ); - // debug!( - // "=> address.sa_family: {:?}", - // (*address).sa_family - // ); - // } + // set_cloexec unsafe { ioctl(fd, FIOCLEX); }; + debug!("fd: {}", fd); - // nix::unistd::write(fd, "Hello, World!".as_bytes()).unwrap(); - // nix::unistd::fsync(fd).unwrap(); + fd } 6 => { @@ -514,12 +495,13 @@ pub extern "C" fn ___syscall102( // name: Em passes SO_ACCEPTCONN, but Nginx complains about REUSEADDR // https://github.com/openbsd/src/blob/master/sys/sys/socket.h#L156 // setsockopt (socket: c_int, level: c_int, name: c_int, value: *const c_void, option_len: socklen_t) -> c_int + let socket: i32 = socket_varargs.get(instance); - // SOL_SOCKET = 0xffff in BSD - let level: i32 = 0xffff; + // SOL_SOCKET = 0xffff (BSD, Linux) + let level: i32 = SOL_SOCKET; let _: u32 = socket_varargs.get(instance); - // SO_ACCEPTCONN = 0x4 - let name: i32 = 0x4; + // SO_REUSEADDR = 0x4 (BSD, Linux) + let name: i32 = SO_REUSEADDR; let _: u32 = socket_varargs.get(instance); let value: u32 = socket_varargs.get(instance); let option_len: u32 = socket_varargs.get(instance);