|
|
|
@ -96,7 +96,7 @@ static void
|
|
|
|
|
wasm_fs_callback(uv_fs_t *req)
|
|
|
|
|
{
|
|
|
|
|
debuglog("[%p]\n", req->data);
|
|
|
|
|
worker_thread__wakeup_sandbox((sandbox_t *)req->data);
|
|
|
|
|
worker_thread_wakeup_sandbox((sandbox_t *)req->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We define our own syscall numbers, because WASM uses x86_64 values even on systems that are not x86_64
|
|
|
|
@ -105,7 +105,7 @@ u32
|
|
|
|
|
wasm_read(i32 filedes, i32 buf_offset, i32 nbyte)
|
|
|
|
|
{
|
|
|
|
|
if (filedes == 0) {
|
|
|
|
|
char * buffer = worker_thread__get_memory_ptr_void(buf_offset, nbyte);
|
|
|
|
|
char * buffer = worker_thread_get_memory_ptr_void(buf_offset, nbyte);
|
|
|
|
|
struct sandbox * s = current_sandbox_get();
|
|
|
|
|
struct http_request *r = &s->http_request;
|
|
|
|
|
if (r->body_length <= 0) return 0;
|
|
|
|
@ -118,12 +118,12 @@ wasm_read(i32 filedes, i32 buf_offset, i32 nbyte)
|
|
|
|
|
int f = current_sandbox_get_file_descriptor(filedes);
|
|
|
|
|
// TODO: read on other file types
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
char * buffer = worker_thread__get_memory_ptr_void(buf_offset, nbyte);
|
|
|
|
|
char * buffer = worker_thread_get_memory_ptr_void(buf_offset, nbyte);
|
|
|
|
|
|
|
|
|
|
debuglog("[%p] start[%d:%d, n%d]\n", uv_fs_get_data(&req), filedes, f, nbyte);
|
|
|
|
|
uv_buf_t bufv = uv_buf_init(buffer, nbyte);
|
|
|
|
|
uv_fs_read(worker_thread__get_thread_libuv_handle(), &req, f, &bufv, 1, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_read(worker_thread_get_libuv_handle(), &req, f, &bufv, 1, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -137,7 +137,7 @@ i32
|
|
|
|
|
wasm_write(i32 file_descriptor, i32 buf_offset, i32 buf_size)
|
|
|
|
|
{
|
|
|
|
|
if (file_descriptor == 1 || file_descriptor == 2) {
|
|
|
|
|
char * buffer = worker_thread__get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
char * buffer = worker_thread_get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
struct sandbox *s = current_sandbox_get();
|
|
|
|
|
int l = s->module->max_response_size - s->request_response_data_length;
|
|
|
|
|
l = l > buf_size ? buf_size : l;
|
|
|
|
@ -150,11 +150,11 @@ wasm_write(i32 file_descriptor, i32 buf_offset, i32 buf_size)
|
|
|
|
|
int f = current_sandbox_get_file_descriptor(file_descriptor);
|
|
|
|
|
// TODO: read on other file types
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
char * buffer = worker_thread__get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
char * buffer = worker_thread_get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
|
|
|
|
|
uv_buf_t bufv = uv_buf_init(buffer, buf_size);
|
|
|
|
|
uv_fs_write(worker_thread__get_thread_libuv_handle(), &req, f, &bufv, 1, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_write(worker_thread_get_libuv_handle(), &req, f, &bufv, 1, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
uv_fs_req_cleanup(&req);
|
|
|
|
@ -183,7 +183,7 @@ i32
|
|
|
|
|
wasm_open(i32 path_off, i32 flags, i32 mode)
|
|
|
|
|
{
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
char * path = worker_thread__get_memory_string(path_off, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
char * path = worker_thread_get_memory_string(path_off, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
|
|
|
|
|
int iofd = current_sandbox_initialize_io_handle();
|
|
|
|
|
if (iofd < 0) return -1;
|
|
|
|
@ -196,8 +196,8 @@ wasm_open(i32 path_off, i32 flags, i32 mode)
|
|
|
|
|
if (flags & WO_EXCL) modified_flags |= O_EXCL;
|
|
|
|
|
debuglog("[%p] start[%s:%d:%d]\n", uv_fs_get_data(&req), path, flags, modified_flags);
|
|
|
|
|
|
|
|
|
|
uv_fs_open(worker_thread__get_thread_libuv_handle(), &req, path, modified_flags, mode, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_open(worker_thread_get_libuv_handle(), &req, path, modified_flags, mode, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -233,8 +233,8 @@ wasm_close(i32 file_descriptor)
|
|
|
|
|
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
debuglog("[%p] file[%d,%d]\n", uv_fs_get_data(&req), file_descriptor, d);
|
|
|
|
|
uv_fs_close(worker_thread__get_thread_libuv_handle(), &req, d, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_close(worker_thread_get_libuv_handle(), &req, d, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -296,8 +296,8 @@ struct wasm_stat {
|
|
|
|
|
i32
|
|
|
|
|
wasm_stat(u32 path_str_offset, i32 stat_offset)
|
|
|
|
|
{
|
|
|
|
|
char * path = worker_thread__get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread__get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
char * path = worker_thread_get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
|
|
|
|
|
struct stat stat;
|
|
|
|
|
i32 res = lstat(path, &stat);
|
|
|
|
@ -342,7 +342,7 @@ wasm_stat(u32 path_str_offset, i32 stat_offset)
|
|
|
|
|
i32
|
|
|
|
|
wasm_fstat(i32 filedes, i32 stat_offset)
|
|
|
|
|
{
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread__get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
|
|
|
|
|
struct stat stat;
|
|
|
|
|
int d = current_sandbox_get_file_descriptor(filedes);
|
|
|
|
@ -388,8 +388,8 @@ wasm_fstat(i32 filedes, i32 stat_offset)
|
|
|
|
|
i32
|
|
|
|
|
wasm_lstat(i32 path_str_offset, i32 stat_offset)
|
|
|
|
|
{
|
|
|
|
|
char * path = worker_thread__get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread__get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
char * path = worker_thread_get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat));
|
|
|
|
|
|
|
|
|
|
struct stat stat;
|
|
|
|
|
i32 res = lstat(path, &stat);
|
|
|
|
@ -498,15 +498,15 @@ wasm_readv(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
if (file_descriptor == 0) {
|
|
|
|
|
// both 1 and 2 go to client.
|
|
|
|
|
int len = 0;
|
|
|
|
|
struct wasm_iovec * iov = worker_thread__get_memory_ptr_void(iov_offset,
|
|
|
|
|
iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
struct wasm_iovec * iov = worker_thread_get_memory_ptr_void(iov_offset,
|
|
|
|
|
iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
struct sandbox * s = current_sandbox_get();
|
|
|
|
|
struct http_request *r = &s->http_request;
|
|
|
|
|
if (r->body_length <= 0) return 0;
|
|
|
|
|
for (int i = 0; i < iovcnt; i++) {
|
|
|
|
|
int l = iov[i].len > r->body_length ? r->body_length : iov[i].len;
|
|
|
|
|
if (l <= 0) break;
|
|
|
|
|
char *b = worker_thread__get_memory_ptr_void(iov[i].base_offset, iov[i].len);
|
|
|
|
|
char *b = worker_thread_get_memory_ptr_void(iov[i].base_offset, iov[i].len);
|
|
|
|
|
// http request body!
|
|
|
|
|
memcpy(b, r->body + r->body_read_length + len, l);
|
|
|
|
|
len += l;
|
|
|
|
@ -519,7 +519,7 @@ wasm_readv(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
// TODO: read on other file types
|
|
|
|
|
int gret = 0;
|
|
|
|
|
int d = current_sandbox_get_file_descriptor(file_descriptor);
|
|
|
|
|
struct wasm_iovec *iov = worker_thread__get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
struct wasm_iovec *iov = worker_thread_get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < iovcnt; i += RUNTIME__READ_WRITE_VECTOR_LENGTH) {
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
@ -527,13 +527,12 @@ wasm_readv(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < RUNTIME__READ_WRITE_VECTOR_LENGTH && i + j < iovcnt; j++) {
|
|
|
|
|
bufs[j] = uv_buf_init(worker_thread__get_memory_ptr_void(iov[i + j].base_offset,
|
|
|
|
|
iov[i + j].len),
|
|
|
|
|
bufs[j] = uv_buf_init(worker_thread_get_memory_ptr_void(iov[i + j].base_offset, iov[i + j].len),
|
|
|
|
|
iov[i + j].len);
|
|
|
|
|
}
|
|
|
|
|
debuglog("[%p] start[%d,%d, n%d:%d]\n", uv_fs_get_data(&req), file_descriptor, d, i, j);
|
|
|
|
|
uv_fs_read(worker_thread__get_thread_libuv_handle(), &req, d, bufs, j, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_read(worker_thread_get_libuv_handle(), &req, d, bufs, j, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -554,10 +553,10 @@ wasm_writev(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
if (file_descriptor == 1 || file_descriptor == 2) {
|
|
|
|
|
// both 1 and 2 go to client.
|
|
|
|
|
int len = 0;
|
|
|
|
|
struct wasm_iovec *iov = worker_thread__get_memory_ptr_void(iov_offset,
|
|
|
|
|
iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
struct wasm_iovec *iov = worker_thread_get_memory_ptr_void(iov_offset,
|
|
|
|
|
iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
for (int i = 0; i < iovcnt; i++) {
|
|
|
|
|
char *b = worker_thread__get_memory_ptr_void(iov[i].base_offset, iov[i].len);
|
|
|
|
|
char *b = worker_thread_get_memory_ptr_void(iov[i].base_offset, iov[i].len);
|
|
|
|
|
memcpy(c->request_response_data + c->request_response_data_length, b, iov[i].len);
|
|
|
|
|
c->request_response_data_length += iov[i].len;
|
|
|
|
|
len += iov[i].len;
|
|
|
|
@ -568,7 +567,7 @@ wasm_writev(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
// TODO: read on other file types
|
|
|
|
|
int d = current_sandbox_get_file_descriptor(file_descriptor);
|
|
|
|
|
int gret = 0;
|
|
|
|
|
struct wasm_iovec *iov = worker_thread__get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
struct wasm_iovec *iov = worker_thread_get_memory_ptr_void(iov_offset, iovcnt * sizeof(struct wasm_iovec));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < iovcnt; i += RUNTIME__READ_WRITE_VECTOR_LENGTH) {
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
@ -576,13 +575,12 @@ wasm_writev(i32 file_descriptor, i32 iov_offset, i32 iovcnt)
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < RUNTIME__READ_WRITE_VECTOR_LENGTH && i + j < iovcnt; j++) {
|
|
|
|
|
bufs[j] = uv_buf_init(worker_thread__get_memory_ptr_void(iov[i + j].base_offset,
|
|
|
|
|
iov[i + j].len),
|
|
|
|
|
bufs[j] = uv_buf_init(worker_thread_get_memory_ptr_void(iov[i + j].base_offset, iov[i + j].len),
|
|
|
|
|
iov[i + j].len);
|
|
|
|
|
}
|
|
|
|
|
debuglog("[%p] start[%d,%d, n%d:%d]\n", uv_fs_get_data(&req), file_descriptor, d, i, j);
|
|
|
|
|
uv_fs_write(worker_thread__get_thread_libuv_handle(), &req, d, bufs, j, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_write(worker_thread_get_libuv_handle(), &req, d, bufs, j, -1, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -643,8 +641,8 @@ wasm_fsync(u32 file_descriptor)
|
|
|
|
|
int d = current_sandbox_get_file_descriptor(file_descriptor);
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
debuglog("[%p] start[%d,%d]\n", uv_fs_get_data(&req), file_descriptor, d);
|
|
|
|
|
uv_fs_fsync(worker_thread__get_thread_libuv_handle(), &req, d, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_fsync(worker_thread_get_libuv_handle(), &req, d, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -657,7 +655,7 @@ wasm_fsync(u32 file_descriptor)
|
|
|
|
|
u32
|
|
|
|
|
wasm_getcwd(u32 buf_offset, u32 buf_size)
|
|
|
|
|
{
|
|
|
|
|
char *buffer = worker_thread__get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
char *buffer = worker_thread_get_memory_ptr_void(buf_offset, buf_size);
|
|
|
|
|
char *res = getcwd(buffer, buf_size);
|
|
|
|
|
|
|
|
|
|
if (!res) return 0;
|
|
|
|
@ -668,11 +666,11 @@ wasm_getcwd(u32 buf_offset, u32 buf_size)
|
|
|
|
|
u32
|
|
|
|
|
wasm_unlink(u32 path_str_offset)
|
|
|
|
|
{
|
|
|
|
|
char * path = worker_thread__get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
char * path = worker_thread_get_memory_string(path_str_offset, MODULE__MAX_PATH_LENGTH);
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
debuglog("[%p] start[%s]\n", uv_fs_get_data(&req), path);
|
|
|
|
|
uv_fs_unlink(worker_thread__get_thread_libuv_handle(), &req, path, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_unlink(worker_thread_get_libuv_handle(), &req, path, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -716,8 +714,8 @@ wasm_get_time(i32 clock_id, i32 timespec_off)
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wasm_time_spec *timespec = worker_thread__get_memory_ptr_void(timespec_off,
|
|
|
|
|
sizeof(struct wasm_time_spec));
|
|
|
|
|
struct wasm_time_spec *timespec = worker_thread_get_memory_ptr_void(timespec_off,
|
|
|
|
|
sizeof(struct wasm_time_spec));
|
|
|
|
|
|
|
|
|
|
struct timespec native_timespec = { 0, 0 };
|
|
|
|
|
int res = clock_gettime(real_clock, &native_timespec);
|
|
|
|
@ -744,8 +742,8 @@ wasm_fchown(i32 file_descriptor, u32 owner, u32 group)
|
|
|
|
|
int d = current_sandbox_get_file_descriptor(file_descriptor);
|
|
|
|
|
uv_fs_t req = UV_FS_REQ_INIT();
|
|
|
|
|
debuglog("[%p] start[%d,%d]\n", uv_fs_get_data(&req), file_descriptor, d);
|
|
|
|
|
uv_fs_fchown(worker_thread__get_thread_libuv_handle(), &req, d, owner, group, wasm_fs_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
uv_fs_fchown(worker_thread_get_libuv_handle(), &req, d, owner, group, wasm_fs_callback);
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
int ret = uv_fs_get_result(&req);
|
|
|
|
|
debuglog("[%p] end[%d]\n", uv_fs_get_data(&req), ret);
|
|
|
|
@ -767,7 +765,7 @@ wasm_connection_callback(uv_stream_t *srv, int status)
|
|
|
|
|
sandbox_t *s = srv->data;
|
|
|
|
|
debuglog(" [%p]\n", s);
|
|
|
|
|
s->return_value = status;
|
|
|
|
|
worker_thread__wakeup_sandbox(s);
|
|
|
|
|
worker_thread_wakeup_sandbox(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -777,7 +775,7 @@ wasm_connect_callback(uv_connect_t *req, int status)
|
|
|
|
|
sandbox_t *s = req->data;
|
|
|
|
|
debuglog(" [%p]\n", s);
|
|
|
|
|
s->return_value = status;
|
|
|
|
|
worker_thread__wakeup_sandbox(s);
|
|
|
|
|
worker_thread_wakeup_sandbox(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i32
|
|
|
|
@ -793,12 +791,12 @@ wasm_socket(i32 domain, i32 type, i32 protocol)
|
|
|
|
|
if (type & SOCK_DGRAM) {
|
|
|
|
|
uv_udp_t *uh = (uv_udp_t *)h;
|
|
|
|
|
uh->data = c;
|
|
|
|
|
uv_udp_init(worker_thread__get_thread_libuv_handle(), uh);
|
|
|
|
|
uv_udp_init(worker_thread_get_libuv_handle(), uh);
|
|
|
|
|
debuglog(" udp init done!\n");
|
|
|
|
|
} else if (type & SOCK_STREAM) {
|
|
|
|
|
uv_tcp_t *uh = (uv_tcp_t *)h;
|
|
|
|
|
uh->data = c;
|
|
|
|
|
uv_tcp_init(worker_thread__get_thread_libuv_handle(), uh);
|
|
|
|
|
uv_tcp_init(worker_thread_get_libuv_handle(), uh);
|
|
|
|
|
debuglog(" tcp init done!\n");
|
|
|
|
|
} else {
|
|
|
|
|
assert(0); // not supported yet!
|
|
|
|
@ -819,17 +817,16 @@ wasm_connect(i32 sockfd, i32 sockaddr_offset, i32 addrlen)
|
|
|
|
|
if (t == UV_TCP) {
|
|
|
|
|
uv_connect_t req = { .data = c };
|
|
|
|
|
debuglog("[%p] connect\n", c);
|
|
|
|
|
int r = uv_tcp_connect(&req, (uv_tcp_t *)h,
|
|
|
|
|
worker_thread__get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
int r = uv_tcp_connect(&req, (uv_tcp_t *)h, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
wasm_connect_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
return c->return_value;
|
|
|
|
|
} else if (t == UV_UDP) {
|
|
|
|
|
debuglog(" UDP connect not implemented!\n");
|
|
|
|
|
// TODO: this api is in the doc online but not in the libuv installed.. perhaps update??
|
|
|
|
|
// return uv_udp_connect((uv_udp_t *)h, worker_thread__get_memory_ptr_void(sockaddr_offset, addrlen));
|
|
|
|
|
// return uv_udp_connect((uv_udp_t *)h, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen));
|
|
|
|
|
}
|
|
|
|
|
debuglog(" unsupported\n");
|
|
|
|
|
assert(0);
|
|
|
|
@ -840,8 +837,8 @@ i32
|
|
|
|
|
wasm_accept(i32 sockfd, i32 sockaddr_offset, i32 addrlen_offset)
|
|
|
|
|
{
|
|
|
|
|
// what do we do with the sockaddr TODO: ????
|
|
|
|
|
socklen_t * addrlen = worker_thread__get_memory_ptr_void(addrlen_offset, sizeof(socklen_t));
|
|
|
|
|
struct sockaddr * socket_address = worker_thread__get_memory_ptr_void(sockaddr_offset, *addrlen);
|
|
|
|
|
socklen_t * addrlen = worker_thread_get_memory_ptr_void(addrlen_offset, sizeof(socklen_t));
|
|
|
|
|
struct sockaddr * socket_address = worker_thread_get_memory_ptr_void(sockaddr_offset, *addrlen);
|
|
|
|
|
union uv_any_handle *s = current_sandbox_get_libuv_handle(sockfd);
|
|
|
|
|
int cfd = current_sandbox_initialize_io_handle();
|
|
|
|
|
if (cfd < 0) return -1;
|
|
|
|
@ -851,7 +848,7 @@ wasm_accept(i32 sockfd, i32 sockaddr_offset, i32 addrlen_offset)
|
|
|
|
|
// assert so we can look into whether we need to implement UDP or others..
|
|
|
|
|
assert(((uv_handle_t *)s)->type == UV_TCP);
|
|
|
|
|
union uv_any_handle *h = current_sandbox_get_libuv_handle(cfd);
|
|
|
|
|
uv_tcp_init(worker_thread__get_thread_libuv_handle(), (uv_tcp_t *)h);
|
|
|
|
|
uv_tcp_init(worker_thread_get_libuv_handle(), (uv_tcp_t *)h);
|
|
|
|
|
debuglog("[%p] tcp init %d\n", c, cfd);
|
|
|
|
|
int r = uv_accept((uv_stream_t *)s, (uv_stream_t *)h);
|
|
|
|
|
if (r < 0) return r;
|
|
|
|
@ -879,7 +876,7 @@ wasm_bind(i32 sockfd, i32 sockaddr_offset, i32 addrlen)
|
|
|
|
|
|
|
|
|
|
if (t == UV_TCP) {
|
|
|
|
|
debuglog("[%p] tcp\n", c);
|
|
|
|
|
int r1 = uv_tcp_bind((uv_tcp_t *)h, worker_thread__get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
int r1 = uv_tcp_bind((uv_tcp_t *)h, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
0 /* TODO: flags */);
|
|
|
|
|
if (file_descriptor == SANDBOX__FILE_DESCRIPTOR_PREOPEN_MAGIC) {
|
|
|
|
|
int r2 = -1, f = -1;
|
|
|
|
@ -890,7 +887,7 @@ wasm_bind(i32 sockfd, i32 sockaddr_offset, i32 addrlen)
|
|
|
|
|
return r1;
|
|
|
|
|
} else if (t == UV_UDP) {
|
|
|
|
|
debuglog("[%p] udp\n", c);
|
|
|
|
|
int r1 = uv_udp_bind((uv_udp_t *)h, worker_thread__get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
int r1 = uv_udp_bind((uv_udp_t *)h, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen),
|
|
|
|
|
0 /* TODO: flags */);
|
|
|
|
|
if (file_descriptor == SANDBOX__FILE_DESCRIPTOR_PREOPEN_MAGIC) {
|
|
|
|
|
int r2 = -1, f = -1;
|
|
|
|
@ -918,7 +915,7 @@ wasm_listen(i32 sockfd, i32 backlog)
|
|
|
|
|
assert(t == UV_TCP);
|
|
|
|
|
|
|
|
|
|
int r = uv_listen((uv_stream_t *)h, backlog, wasm_connection_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
return c->return_value;
|
|
|
|
@ -937,7 +934,7 @@ wasm_read_callback(uv_stream_t *s, ssize_t nread, const uv_buf_t *buffer)
|
|
|
|
|
c->read_length = nread;
|
|
|
|
|
debuglog("[%p] %ld\n", c, c->read_length);
|
|
|
|
|
uv_read_stop(s);
|
|
|
|
|
worker_thread__wakeup_sandbox(c);
|
|
|
|
|
worker_thread_wakeup_sandbox(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -947,7 +944,7 @@ wasm_write_callback(uv_write_t *req, int status)
|
|
|
|
|
c->return_value = status;
|
|
|
|
|
debuglog("[%p] %d\n", c, status);
|
|
|
|
|
|
|
|
|
|
worker_thread__wakeup_sandbox(c);
|
|
|
|
|
worker_thread_wakeup_sandbox(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -961,7 +958,7 @@ wasm_udp_recv_callback(uv_udp_t *h, ssize_t nread, const uv_buf_t *buffer, const
|
|
|
|
|
c->read_length = nread;
|
|
|
|
|
debuglog("[%p] %ld\n", c, c->read_length);
|
|
|
|
|
uv_udp_recv_stop(h);
|
|
|
|
|
worker_thread__wakeup_sandbox(c);
|
|
|
|
|
worker_thread_wakeup_sandbox(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -971,13 +968,13 @@ wasm_udp_send_callback(uv_udp_send_t *req, int status)
|
|
|
|
|
c->return_value = status;
|
|
|
|
|
debuglog("[%p] %d\n", c, status);
|
|
|
|
|
|
|
|
|
|
worker_thread__wakeup_sandbox(c);
|
|
|
|
|
worker_thread_wakeup_sandbox(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i32
|
|
|
|
|
wasm_sendto(i32 file_descriptor, i32 buff_offset, i32 len, i32 flags, i32 sockaddr_offset, i32 sockaddr_len)
|
|
|
|
|
{
|
|
|
|
|
char *buffer = worker_thread__get_memory_ptr_void(buff_offset, len);
|
|
|
|
|
char *buffer = worker_thread_get_memory_ptr_void(buff_offset, len);
|
|
|
|
|
// TODO: only support "send" api for now
|
|
|
|
|
assert(sockaddr_len == 0);
|
|
|
|
|
struct sandbox * c = current_sandbox_get();
|
|
|
|
@ -992,7 +989,7 @@ wasm_sendto(i32 file_descriptor, i32 buff_offset, i32 len, i32 flags, i32 sockad
|
|
|
|
|
uv_buf_t b = uv_buf_init(buffer, len);
|
|
|
|
|
debuglog("[%p] tcp\n", c);
|
|
|
|
|
int ret = uv_write(&req, (uv_stream_t *)h, &b, 1, wasm_write_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
return c->return_value;
|
|
|
|
@ -1004,7 +1001,7 @@ wasm_sendto(i32 file_descriptor, i32 buff_offset, i32 len, i32 flags, i32 sockad
|
|
|
|
|
debuglog("[%p] udp\n", c);
|
|
|
|
|
// TODO: sockaddr!
|
|
|
|
|
int r = uv_udp_send(&req, (uv_udp_t *)h, &b, 1, NULL, wasm_udp_send_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
return c->return_value;
|
|
|
|
@ -1027,8 +1024,8 @@ wasm_alloc_callback(uv_handle_t *h, size_t suggested, uv_buf_t *buffer)
|
|
|
|
|
i32
|
|
|
|
|
wasm_recvfrom(i32 file_descriptor, i32 buff_offset, i32 size, i32 flags, i32 sockaddr_offset, i32 socklen_offset)
|
|
|
|
|
{
|
|
|
|
|
char * buffer = worker_thread__get_memory_ptr_void(buff_offset, size);
|
|
|
|
|
socklen_t *len = worker_thread__get_memory_ptr_void(socklen_offset, sizeof(socklen_t));
|
|
|
|
|
char * buffer = worker_thread_get_memory_ptr_void(buff_offset, size);
|
|
|
|
|
socklen_t *len = worker_thread_get_memory_ptr_void(socklen_offset, sizeof(socklen_t));
|
|
|
|
|
// TODO: only support "recv" api for now
|
|
|
|
|
assert(*len == 0);
|
|
|
|
|
struct sandbox * c = current_sandbox_get();
|
|
|
|
@ -1050,7 +1047,7 @@ wasm_recvfrom(i32 file_descriptor, i32 buff_offset, i32 size, i32 flags, i32 soc
|
|
|
|
|
((uv_stream_t *)h)->data = c;
|
|
|
|
|
debuglog("[%p] tcp\n", c);
|
|
|
|
|
int r = uv_read_start((uv_stream_t *)h, wasm_alloc_callback, wasm_read_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
if (c->return_value == -EIO) {
|
|
|
|
|
// TODO: buffer errors??
|
|
|
|
@ -1061,7 +1058,7 @@ wasm_recvfrom(i32 file_descriptor, i32 buff_offset, i32 size, i32 flags, i32 soc
|
|
|
|
|
((uv_udp_t *)h)->data = c;
|
|
|
|
|
debuglog("[%p] udp\n", c);
|
|
|
|
|
int r = uv_udp_recv_start((uv_udp_t *)h, wasm_alloc_callback, wasm_udp_recv_callback);
|
|
|
|
|
worker_thread__block_current_sandbox();
|
|
|
|
|
worker_thread_block_current_sandbox();
|
|
|
|
|
debuglog("[%p] %d\n", c, c->return_value);
|
|
|
|
|
if (c->return_value == -EIO) {
|
|
|
|
|
// TODO: buffer errors??
|
|
|
|
|