diff --git a/include/proxy-wasm/exports.h b/include/proxy-wasm/exports.h index 376a4d3b..dc3f9d9f 100644 --- a/include/proxy-wasm/exports.h +++ b/include/proxy-wasm/exports.h @@ -118,6 +118,8 @@ Word grpc_stream(Word service_ptr, Word service_size, Word service_name_ptr, Wor Word grpc_cancel(Word token); Word grpc_close(Word token); Word grpc_send(Word token, Word message_ptr, Word message_size, Word end_stream); +Word secure_getenv(Word name); +Word getpid(); Word set_tick_period_milliseconds(Word tick_period_milliseconds); Word get_current_time_nanoseconds(Word result_uint64_ptr); @@ -146,6 +148,12 @@ Word wasi_unstable_args_sizes_get(Word argc_ptr, Word argv_buf_size_ptr); void wasi_unstable_proc_exit(Word); Word wasi_unstable_clock_time_get(Word, uint64_t, Word); Word wasi_unstable_random_get(Word, Word); +Word wasi_unstable_fd_filestat_get(Word fd, Word statOut); +Word wasi_unstable_fd_readdir(Word fd, Word buf, Word buf_len, int64_t cookie, Word bufused); +Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word statOut); +Word wasi_unstable_fd_fdstat_set_flags(Word fd, Word flags); +Word wasi_unstable_sched_yield(); +Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents); Word pthread_equal(Word left, Word right); void emscripten_notify_memory_growth(Word); @@ -163,7 +171,8 @@ void emscripten_notify_memory_growth(Word); _f(get_current_time_nanoseconds) _f(define_metric) \ _f(increment_metric) _f(record_metric) _f(get_metric) \ _f(set_effective_context) _f(done) \ - _f(call_foreign_function) + _f(call_foreign_function) _f(getpid) \ + _f(secure_getenv) #define FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_f) \ _f(get_configuration) _f(continue_request) _f(continue_response) _f(clear_route_cache) \ @@ -172,7 +181,9 @@ void emscripten_notify_memory_growth(Word); #define FOR_ALL_WASI_FUNCTIONS(_f) \ _f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(environ_get) \ _f(environ_sizes_get) _f(args_get) _f(args_sizes_get) _f(clock_time_get) _f(random_get) \ - _f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name) + _f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name) \ + _f(fd_filestat_get) _f(fd_readdir) _f(path_filestat_get) _f(fd_fdstat_set_flags) \ + _f(sched_yield) _f(poll_oneoff) // Helpers to generate a stub to pass to VM, in place of a restricted proxy-wasm capability. #define _CREATE_PROXY_WASM_STUB(_fn) \ diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index a573212e..0dc5ffdc 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -111,6 +111,7 @@ using WasmCallback_WWl = Word (*)(Word, int64_t); using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word); using WasmCallback_WWm = Word (*)(Word, uint64_t); using WasmCallback_WWmW = Word (*)(Word, uint64_t, Word); +using WasmCallback_WWWWlW = Word (*)(Word, Word, Word, int64_t, Word); using WasmCallback_WWWWWWllWW = Word (*)(Word, Word, Word, Word, Word, int64_t, int64_t, Word, Word); using WasmCallback_dd = double (*)(double); @@ -130,8 +131,9 @@ using WasmCallback_dd = double (*)(double); _f(proxy_wasm::WasmCallback_WWlWW) \ _f(proxy_wasm::WasmCallback_WWm) \ _f(proxy_wasm::WasmCallback_WWmW) \ - _f(proxy_wasm::WasmCallback_WWWWWWllWW) \ - _f(proxy_wasm::WasmCallback_dd) + _f(proxy_wasm::WasmCallback_WWWWlW) \ + _f(proxy_wasm::WasmCallback_WWWWWWllWW)\ + _f(proxy_wasm::WasmCallback_dd) enum class Cloneable { NotCloneable, // VMs can not be cloned and should be created from scratch. diff --git a/src/exports.cc b/src/exports.cc index 0290dcf0..25da8268 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -885,6 +885,10 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) { context->error("wasi_unstable proc_exit"); } +Word wasi_unstable_sched_yield() { return 0; } + +Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents) { return 0; } + Word pthread_equal(Word left, Word right) { return static_cast(left == right); } void emscripten_notify_memory_growth(Word /*memory_index*/) {} @@ -925,5 +929,29 @@ Word get_log_level(Word result_level_uint32_ptr) { return WasmResult::Ok; } +Word wasi_unstable_fd_fdstat_set_flags(Word fd, Word flags) { + // Don't support reading of any files. + return 52; // __WASI_ERRNO_ENOSYS +} + +Word wasi_unstable_fd_filestat_get(Word fd, Word statOut) { + // Don't support reading of any files. + return 52; // __WASI_ERRNO_ENOSYS +} + +Word wasi_unstable_fd_readdir(Word fd, Word buf, Word buf_len, int64_t cookie, Word bufused) { + // Don't support reading of any files. + return 52; // __WASI_ERRNO_ENOSYS +} + +Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word statOut) { + // Don't support reading of any files. + return 52; // __WASI_ERRNO_ENOSYS +} + +Word secure_getenv(Word name) { return 0; } + +Word getpid() { return 4; } + } // namespace exports } // namespace proxy_wasm diff --git a/src/wasm.cc b/src/wasm.cc index cb1dd9b3..3863ccc0 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -109,6 +109,8 @@ void WasmBase::registerCallbacks() { "env", #_fn, &exports::_fn, \ &ConvertFunctionWordToUint32::convertFunctionWordToUint32) + _REGISTER(secure_getenv); + _REGISTER(getpid); _REGISTER(pthread_equal); _REGISTER(emscripten_notify_memory_growth); #undef _REGISTER