Skip to content

Commit

Permalink
Merge #514
Browse files Browse the repository at this point in the history
514: improve emscripten sockets and networking r=MarkMcCaskey a=MarkMcCaskey



Co-authored-by: Mark McCaskey <[email protected]>
  • Loading branch information
bors[bot] and Mark McCaskey committed Jul 1, 2019
2 parents 13c5f5e + 6afc2e4 commit fada36a
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 65 deletions.
79 changes: 37 additions & 42 deletions lib/emscripten/src/emscripten_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub fn exit_with_live_runtime(_ctx: &mut Ctx) {
}

pub fn setTempRet0(ctx: &mut Ctx, val: i32) {
debug!("emscripten::setTempRet0: {}", val);
trace!("emscripten::setTempRet0: {}", val);
get_emscripten_data(ctx).temp_ret_0 = val;
}

pub fn getTempRet0(ctx: &mut Ctx) -> i32 {
debug!("emscripten::getTempRet0");
trace!("emscripten::getTempRet0");
get_emscripten_data(ctx).temp_ret_0
}

Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn _dladdr(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
0
}
pub fn _pthread_attr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_attr_destroy");
trace!("emscripten::_pthread_attr_destroy");
0
}
pub fn _pthread_attr_getstack(
Expand All @@ -88,136 +88,136 @@ pub fn _pthread_attr_getstack(
0
}
pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_attr_init({})", _a);
trace!("emscripten::_pthread_attr_init({})", _a);
0
}
pub fn _pthread_attr_setstacksize(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_attr_setstacksize");
trace!("emscripten::_pthread_attr_setstacksize");
0
}
pub fn _pthread_cleanup_pop(_ctx: &mut Ctx, _a: i32) -> () {
debug!("emscripten::_pthread_cleanup_pop");
trace!("emscripten::_pthread_cleanup_pop");
}
pub fn _pthread_cleanup_push(_ctx: &mut Ctx, _a: i32, _b: i32) -> () {
debug!("emscripten::_pthread_cleanup_push");
trace!("emscripten::_pthread_cleanup_push");
}
pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_cond_destroy");
trace!("emscripten::_pthread_cond_destroy");
0
}
pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_cond_init");
trace!("emscripten::_pthread_cond_init");
0
}
pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_cond_signal");
trace!("emscripten::_pthread_cond_signal");
0
}
pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::_pthread_cond_timedwait");
trace!("emscripten::_pthread_cond_timedwait");
0
}
pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_cond_wait");
trace!("emscripten::_pthread_cond_wait");
0
}
pub fn _pthread_condattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_condattr_destroy");
trace!("emscripten::_pthread_condattr_destroy");
0
}
pub fn _pthread_condattr_init(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_condattr_init");
trace!("emscripten::_pthread_condattr_init");
0
}
pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_condattr_setclock");
trace!("emscripten::_pthread_condattr_setclock");
0
}
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
debug!("emscripten::_pthread_create");
trace!("emscripten::_pthread_create");
0
}
pub fn _pthread_detach(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_detach");
trace!("emscripten::_pthread_detach");
0
}
pub fn _pthread_equal(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_equal");
trace!("emscripten::_pthread_equal");
0
}
pub fn _pthread_exit(_ctx: &mut Ctx, _a: i32) -> () {
debug!("emscripten::_pthread_exit");
trace!("emscripten::_pthread_exit");
}
pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr);
trace!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr);
0
}
pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_getspecific");
trace!("emscripten::_pthread_getspecific");
0
}
pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_join");
trace!("emscripten::_pthread_join");
0
}
pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_key_create");
trace!("emscripten::_pthread_key_create");
0
}
pub fn _pthread_mutex_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_mutex_destroy");
trace!("emscripten::_pthread_mutex_destroy");
0
}
pub fn _pthread_mutex_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_mutex_init");
trace!("emscripten::_pthread_mutex_init");
0
}
pub fn _pthread_mutexattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_mutexattr_destroy");
trace!("emscripten::_pthread_mutexattr_destroy");
0
}
pub fn _pthread_mutexattr_init(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_mutexattr_init");
trace!("emscripten::_pthread_mutexattr_init");
0
}
pub fn _pthread_mutexattr_settype(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_mutexattr_settype");
trace!("emscripten::_pthread_mutexattr_settype");
0
}
pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_once");
trace!("emscripten::_pthread_once");
0
}
pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
trace!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
0
}
pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
trace!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
0
}
pub fn _pthread_rwlock_rdlock(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_rdlock");
trace!("emscripten::_pthread_rwlock_rdlock");
0
}
pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_unlock");
trace!("emscripten::_pthread_rwlock_unlock");
0
}
pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
trace!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
0
}
pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_setcancelstate");
trace!("emscripten::_pthread_setcancelstate");
0
}
pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_setspecific");
trace!("emscripten::_pthread_setspecific");
0
}
pub fn _pthread_sigmask(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::_pthread_sigmask");
trace!("emscripten::_pthread_sigmask");
0
}
pub fn ___gxx_personality_v0(
Expand All @@ -233,11 +233,6 @@ pub fn ___gxx_personality_v0(
0
}

pub fn _gai_strerror(_ctx: &mut Ctx, _ecode: i32) -> i32 {
debug!("emscripten::_gai_strerror({})", _ecode);
0
}

#[cfg(target_os = "linux")]
pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::getdtablesize");
Expand Down
50 changes: 44 additions & 6 deletions lib/emscripten/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ pub use self::windows::*;
use libc::c_char;

use crate::{allocate_on_stack, EmscriptenData};
use std::os::raw::c_int;
use wasmer_runtime_core::vm::Ctx;

pub fn _getaddrinfo(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _four: i32) -> i32 {
debug!("emscripten::_getaddrinfo");
-1
}
use std::os::raw::c_int;
use wasmer_runtime_core::{
memory::ptr::{Array, WasmPtr},
types::ValueType,
vm::Ctx,
};

pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 {
get_emscripten_data(ctx).malloc.call(size).unwrap()
}

pub fn call_malloc_with_cast<T: Copy, Ty>(ctx: &mut Ctx, size: u32) -> WasmPtr<T, Ty> {
WasmPtr::new(get_emscripten_data(ctx).malloc.call(size).unwrap())
}

pub fn call_memalign(ctx: &mut Ctx, alignment: u32, size: u32) -> u32 {
if let Some(memalign) = &get_emscripten_data(ctx).memalign {
memalign.call(alignment, size).unwrap()
Expand Down Expand Up @@ -152,3 +156,37 @@ pub fn _fpathconf(_ctx: &mut Ctx, _fildes: c_int, name: c_int) -> c_int {
}
}
}

#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct EmAddrInfo {
// int
pub ai_flags: i32,
// int
pub ai_family: i32,
// int
pub ai_socktype: i32,
// int
pub ai_protocol: i32,
// socklen_t
pub ai_addrlen: u32,
// struct sockaddr*
pub ai_addr: WasmPtr<EmSockAddr>,
// char*
pub ai_canonname: WasmPtr<c_char, Array>,
// struct addrinfo*
pub ai_next: WasmPtr<EmAddrInfo>,
}

unsafe impl ValueType for EmAddrInfo {}

// NOTE: from looking at emscripten JS, this should be a union
// TODO: review this, highly likely to have bugs
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct EmSockAddr {
pub sa_family: i16,
pub sa_data: [c_char; 14],
}

unsafe impl ValueType for EmSockAddr {}
Loading

0 comments on commit fada36a

Please sign in to comment.