From 47c7b4b13a5793a59a052c09561f2bb83c5c2985 Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 26 May 2022 20:49:56 +0000 Subject: [PATCH 1/5] initial Signed-off-by: chaoqin-li1123 --- include/proxy-wasm/exports.h | 3 ++- src/exports.cc | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/proxy-wasm/exports.h b/include/proxy-wasm/exports.h index 2b3d0db74..4ee1a8e15 100644 --- a/include/proxy-wasm/exports.h +++ b/include/proxy-wasm/exports.h @@ -156,6 +156,7 @@ Word set_effective_context(Word context_id); Word done(); Word call_foreign_function(Word function_name, Word function_name_size, Word arguments, Word warguments_size, Word results, Word results_size); +void emscripten_notify_memory_growth(int64_t); // Runtime environment functions exported from envoy to wasm. @@ -196,7 +197,7 @@ Word pthread_equal(Word left, Word right); #define FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_f) \ _f(get_configuration) _f(continue_request) _f(continue_response) _f(clear_route_cache) \ - _f(continue_stream) _f(close_stream) _f(get_log_level) + _f(continue_stream) _f(close_stream) _f(get_log_level) _f(emscripten_notify_memory_growth) #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) \ diff --git a/src/exports.cc b/src/exports.cc index c203946b8..8480c2e16 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -667,6 +667,8 @@ Word grpc_send(Word token, Word message_ptr, Word message_size, Word end_stream) return context->grpcSend(token, message.value(), end_stream != 0U); } +void emscripten_notify_memory_growth(int64_t) {} + // __wasi_errno_t path_open(__wasi_fd_t fd, __wasi_lookupflags_t dirflags, const char *path, // size_t path_len, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, __wasi_rights_t // fs_rights_inheriting, __wasi_fdflags_t fdflags, __wasi_fd_t *retptr0) From 3ec167681185c1730560658bab6bfd194f92db8c Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Tue, 31 May 2022 14:46:03 +0000 Subject: [PATCH 2/5] register callback Signed-off-by: chaoqin-li1123 --- include/proxy-wasm/exports.h | 4 ++-- include/proxy-wasm/wasm_vm.h | 4 +++- src/exports.cc | 4 ++-- src/wasm.cc | 8 ++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/proxy-wasm/exports.h b/include/proxy-wasm/exports.h index 4ee1a8e15..d73d0eb22 100644 --- a/include/proxy-wasm/exports.h +++ b/include/proxy-wasm/exports.h @@ -156,7 +156,6 @@ Word set_effective_context(Word context_id); Word done(); Word call_foreign_function(Word function_name, Word function_name_size, Word arguments, Word warguments_size, Word results, Word results_size); -void emscripten_notify_memory_growth(int64_t); // Runtime environment functions exported from envoy to wasm. @@ -178,6 +177,7 @@ void wasi_unstable_proc_exit(Word); Word wasi_unstable_clock_time_get(Word, uint64_t, Word); Word wasi_unstable_random_get(Word, Word); Word pthread_equal(Word left, Word right); +void emscripten_notify_memory_growth(int64_t); // Support for embedders, not exported to Wasm. @@ -197,7 +197,7 @@ Word pthread_equal(Word left, Word right); #define FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_f) \ _f(get_configuration) _f(continue_request) _f(continue_response) _f(clear_route_cache) \ - _f(continue_stream) _f(close_stream) _f(get_log_level) _f(emscripten_notify_memory_growth) + _f(continue_stream) _f(close_stream) _f(get_log_level) #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) \ diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index 800348ac3..e3352e960 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -106,6 +106,7 @@ template using WasmCallbackWord = WasmCallbackFuncType // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin // Extended with W = Word // Z = void, j = uint32_t, l = int64_t, m = uint64_t +using WasmCallback_Zl = void (*)(int64_t); using WasmCallback_WWl = Word (*)(Word, int64_t); using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word); using WasmCallback_WWm = Word (*)(Word, uint64_t); @@ -130,7 +131,8 @@ using WasmCallback_dd = double (*)(double); _f(proxy_wasm::WasmCallback_WWm) \ _f(proxy_wasm::WasmCallback_WWmW) \ _f(proxy_wasm::WasmCallback_WWWWWWllWW) \ - _f(proxy_wasm::WasmCallback_dd) + _f(proxy_wasm::WasmCallback_dd) \ + _f(proxy_wasm::WasmCallback_Zl) 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 8480c2e16..586f42843 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -667,8 +667,6 @@ Word grpc_send(Word token, Word message_ptr, Word message_size, Word end_stream) return context->grpcSend(token, message.value(), end_stream != 0U); } -void emscripten_notify_memory_growth(int64_t) {} - // __wasi_errno_t path_open(__wasi_fd_t fd, __wasi_lookupflags_t dirflags, const char *path, // size_t path_len, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, __wasi_rights_t // fs_rights_inheriting, __wasi_fdflags_t fdflags, __wasi_fd_t *retptr0) @@ -903,6 +901,8 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) { Word pthread_equal(Word left, Word right) { return static_cast(left == right); } +void emscripten_notify_memory_growth(int64_t) {} + Word set_tick_period_milliseconds(Word period_milliseconds) { TimerToken token = 0; return contextOrEffectiveContext()->setTimerPeriod(std::chrono::milliseconds(period_milliseconds), diff --git a/src/wasm.cc b/src/wasm.cc index 3c0473e87..23030b433 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -91,6 +91,14 @@ void WasmBase::registerCallbacks() { _REGISTER(pthread_equal); #undef _REGISTER +#define _REGISTER(_fn) \ + wasm_vm_->registerCallback( \ + "env", #_fn, &exports::_fn, \ + &ConvertFunctionWordToUint32::convertFunctionWordToUint32) + _REGISTER(emscripten_notify_memory_growth); +#undef _REGISTER + // Register the capability with the VM if it has been allowed, otherwise register a stub. #define _REGISTER(module_name, name_prefix, export_prefix, _fn) \ if (capabilityAllowed(name_prefix #_fn)) { \ From 0e9b3f36e227002c92f9d24570da1c9f700ed96a Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Tue, 31 May 2022 15:08:05 +0000 Subject: [PATCH 3/5] fix clang tidy Signed-off-by: chaoqin-li1123 --- src/exports.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exports.cc b/src/exports.cc index 586f42843..5b778bd55 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -901,7 +901,7 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) { Word pthread_equal(Word left, Word right) { return static_cast(left == right); } -void emscripten_notify_memory_growth(int64_t) {} +void emscripten_notify_memory_growth(int64_t /*memory_index*/) {} Word set_tick_period_milliseconds(Word period_milliseconds) { TimerToken token = 0; From 0d8f177b9f3cdbf698df4fe99b3da2fcd3afcb8a Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Wed, 1 Jun 2022 14:20:28 +0000 Subject: [PATCH 4/5] remove duplicate code Signed-off-by: chaoqin-li1123 --- src/wasm.cc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/wasm.cc b/src/wasm.cc index 23030b433..2295e9880 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -89,13 +89,6 @@ void WasmBase::registerCallbacks() { &ConvertFunctionWordToUint32::convertFunctionWordToUint32) _REGISTER(pthread_equal); -#undef _REGISTER - -#define _REGISTER(_fn) \ - wasm_vm_->registerCallback( \ - "env", #_fn, &exports::_fn, \ - &ConvertFunctionWordToUint32::convertFunctionWordToUint32) _REGISTER(emscripten_notify_memory_growth); #undef _REGISTER From aa649f34cb357f5bbfa46bb5deb82f9296059c69 Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 9 Jun 2022 14:56:26 +0000 Subject: [PATCH 5/5] fix input param type Signed-off-by: chaoqin-li1123 --- include/proxy-wasm/exports.h | 2 +- include/proxy-wasm/wasm_vm.h | 4 +--- src/exports.cc | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/proxy-wasm/exports.h b/include/proxy-wasm/exports.h index d73d0eb22..325d28ff3 100644 --- a/include/proxy-wasm/exports.h +++ b/include/proxy-wasm/exports.h @@ -177,7 +177,7 @@ void wasi_unstable_proc_exit(Word); Word wasi_unstable_clock_time_get(Word, uint64_t, Word); Word wasi_unstable_random_get(Word, Word); Word pthread_equal(Word left, Word right); -void emscripten_notify_memory_growth(int64_t); +void emscripten_notify_memory_growth(Word); // Support for embedders, not exported to Wasm. diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index e3352e960..800348ac3 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -106,7 +106,6 @@ template using WasmCallbackWord = WasmCallbackFuncType // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin // Extended with W = Word // Z = void, j = uint32_t, l = int64_t, m = uint64_t -using WasmCallback_Zl = void (*)(int64_t); using WasmCallback_WWl = Word (*)(Word, int64_t); using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word); using WasmCallback_WWm = Word (*)(Word, uint64_t); @@ -131,8 +130,7 @@ using WasmCallback_dd = double (*)(double); _f(proxy_wasm::WasmCallback_WWm) \ _f(proxy_wasm::WasmCallback_WWmW) \ _f(proxy_wasm::WasmCallback_WWWWWWllWW) \ - _f(proxy_wasm::WasmCallback_dd) \ - _f(proxy_wasm::WasmCallback_Zl) + _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 5b778bd55..6a7b3181c 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -901,7 +901,7 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) { Word pthread_equal(Word left, Word right) { return static_cast(left == right); } -void emscripten_notify_memory_growth(int64_t /*memory_index*/) {} +void emscripten_notify_memory_growth(Word /*memory_index*/) {} Word set_tick_period_milliseconds(Word period_milliseconds) { TimerToken token = 0;