Skip to content

Commit

Permalink
Merge pull request wasmerio#96 from wasmerio/fix/improve-emscripten-p…
Browse files Browse the repository at this point in the history
…ortability

Improve Emscripten Portability
  • Loading branch information
appcypher authored Jan 19, 2019
2 parents e07e5c7 + 946ac80 commit 00d5dd8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.rs.bk
/artifacts
.DS_Store
.idea
1 change: 1 addition & 0 deletions examples/nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*_temp
logs/error.log
2 changes: 1 addition & 1 deletion examples/nginx/logs/nginx.pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
96248
21011
58 changes: 20 additions & 38 deletions src/apis/emscripten/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use libc::{
F_GETFD,
F_SETFD,
SOL_SOCKET,
SO_REUSEADDR,
TIOCGWINSZ,
};

Expand Down Expand Up @@ -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::<T>() 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::<T>() as socklen_t,
);
};

debug!(
Expand All @@ -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 {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 00d5dd8

Please sign in to comment.