From 552d735daf669ed478b46b5e2afac10edcae77d7 Mon Sep 17 00:00:00 2001 From: Steve Akinyemi Date: Wed, 16 Jan 2019 00:32:13 +0100 Subject: [PATCH 1/3] Ignore IntelliJ files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 52c89dacb..056e2c12d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/*.rs.bk /artifacts .DS_Store +.idea From 33f10e09f977a5319876b7222c9685d1854013aa Mon Sep 17 00:00:00 2001 From: Steve Akinyemi Date: Thu, 17 Jan 2019 14:35:56 +0100 Subject: [PATCH 2/3] Make nginx work on Linux --- examples/nginx/.gitignore | 1 + examples/nginx/logs/nginx.pid | 2 +- src/apis/emscripten/syscalls.rs | 58 ++++++++++++--------------------- 3 files changed, 22 insertions(+), 39 deletions(-) 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..538707b5a 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); From 946ac8058bf66e6d8f636c79c9dae509e1323fbb Mon Sep 17 00:00:00 2001 From: Steve Akinyemi Date: Thu, 17 Jan 2019 14:51:57 +0100 Subject: [PATCH 3/3] Fix lint issue --- src/apis/emscripten/syscalls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apis/emscripten/syscalls.rs b/src/apis/emscripten/syscalls.rs index 538707b5a..efd7a17b7 100644 --- a/src/apis/emscripten/syscalls.rs +++ b/src/apis/emscripten/syscalls.rs @@ -336,7 +336,7 @@ pub extern "C" fn ___syscall102( unsafe { ioctl(fd, FIOCLEX); }; - + type T = u32; let payload = 1 as *const T as *const c_void; unsafe {