mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
wip
This commit is contained in:
parent
b7c5f27b37
commit
e75a23602a
@ -97,7 +97,12 @@ impl EmscriptenVfs {
|
||||
|
||||
pub fn get_host_socket_fd(&self, vfd: &VirtualFd) -> Option<Fd> {
|
||||
match self.fd_map.get(&vfd) {
|
||||
Some(FileHandle::Socket(fd)) => Some(*fd),
|
||||
Some(FileHandle::Socket(fd)) => {
|
||||
if *fd < 0 {
|
||||
panic!()
|
||||
}
|
||||
Some(*fd)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -119,6 +124,9 @@ impl EmscriptenVfs {
|
||||
|
||||
pub fn new_socket_fd(&mut self, host_fd: Fd) -> VirtualFd {
|
||||
let vfd = self.next_lowest_fd();
|
||||
if host_fd < 0 {
|
||||
panic!()
|
||||
}
|
||||
self.fd_map.insert(vfd.clone(), FileHandle::Socket(host_fd));
|
||||
vfd
|
||||
}
|
||||
|
@ -194,6 +194,27 @@ pub fn ___syscall142(ctx: &mut Ctx, _which: libc::c_int, mut varargs: VarArgs) -
|
||||
.map(|pair| pair.host_fd)
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
|
||||
unsafe {
|
||||
use libc::FD_ISSET;
|
||||
let s = 3;
|
||||
let x = [
|
||||
FD_ISSET(s, readfds_set_ptr),
|
||||
FD_ISSET(s + 1, readfds_set_ptr),
|
||||
FD_ISSET(s + 2, readfds_set_ptr),
|
||||
FD_ISSET(s + 3, readfds_set_ptr),
|
||||
FD_ISSET(s + 4, readfds_set_ptr),
|
||||
FD_ISSET(s + 5, readfds_set_ptr),
|
||||
FD_ISSET(s + 6, readfds_set_ptr),
|
||||
FD_ISSET(s + 7, readfds_set_ptr),
|
||||
FD_ISSET(s + 8, readfds_set_ptr),
|
||||
FD_ISSET(s + 9, readfds_set_ptr),
|
||||
FD_ISSET(s + 10, readfds_set_ptr),
|
||||
FD_ISSET(s + 11, readfds_set_ptr),
|
||||
];
|
||||
debug!("BEFORE sets start with fd #{}: {:?}", s, x);
|
||||
}
|
||||
|
||||
let fds_slice = unsafe { slice::from_raw_parts(readfds_set_ptr as *const u8, 4) } as &[u8];
|
||||
debug!("host read set before: {:?}", fds_slice);
|
||||
let mut result = unsafe { libc::select(sz, readfds_set_ptr, writefds_set_ptr, 0 as _, 0 as _) };
|
||||
@ -216,7 +237,7 @@ pub fn ___syscall142(ctx: &mut Ctx, _which: libc::c_int, mut varargs: VarArgs) -
|
||||
FD_ISSET(s + 10, readfds_set_ptr),
|
||||
FD_ISSET(s + 11, readfds_set_ptr),
|
||||
];
|
||||
debug!("sets (start with fd #{}: {:?}", s, x);
|
||||
debug!("AFTER sets (start with fd #{}: {:?}", s, x);
|
||||
}
|
||||
|
||||
if result == -1 {
|
||||
|
@ -264,7 +264,7 @@ pub fn ___syscall63(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
|
||||
Some(FileHandle::Socket(src_host_fd)) => unsafe {
|
||||
// get a dst file descriptor, or just use the underlying dup syscall
|
||||
let dst_host_fd = libc::dup(*src_host_fd);
|
||||
if dst_host_fd == -1 {
|
||||
if dst_host_fd < 0 {
|
||||
panic!()
|
||||
}
|
||||
FileHandle::Socket(dst_host_fd)
|
||||
@ -440,6 +440,10 @@ pub fn ___syscall102(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
let new_accept_host_fd =
|
||||
unsafe { libc::accept(host_socket_fd, address, address_len_addr) };
|
||||
|
||||
if new_accept_host_fd < 0 {
|
||||
panic!("accept file descriptor should not be negative.");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let address_linux =
|
||||
emscripten_memory_pointer!(ctx.memory(0), address_addr) as *mut LinuxSockAddr;
|
||||
@ -548,6 +552,9 @@ pub fn ___syscall102(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
"recvfrom: socket: {}, flags: {}, len: {}, result: {}",
|
||||
socket, flags, len, recv_result
|
||||
);
|
||||
if recv_result < 0 {
|
||||
panic!("recvfrom result was less than zero. Errno: {}", errno::errno());
|
||||
}
|
||||
recv_result
|
||||
}
|
||||
14 => {
|
||||
@ -691,7 +698,7 @@ pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
Some(FileHandle::Socket(host_fd)) => unsafe {
|
||||
let count = libc::write(*host_fd, iov_buf_ptr, count);
|
||||
if count < 0 {
|
||||
panic!()
|
||||
panic!("the count from write was less than zero. errno: {}", errno::errno());
|
||||
}
|
||||
count as usize
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user