-
Notifications
You must be signed in to change notification settings - Fork 2
extend wasm abi #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ namespace proxy_wasm { | |||||
|
|
||||||
| using Pairs = std::vector<std::pair<std::string_view, std::string_view>>; | ||||||
| using PairsWithStringValues = std::vector<std::pair<std::string_view, std::string>>; | ||||||
| using StringPairs = std::vector<std::pair<std::string, std::string>>; | ||||||
| using TimerToken = uint32_t; | ||||||
| using HttpCallToken = uint32_t; | ||||||
| using GrpcToken = uint32_t; | ||||||
|
|
@@ -255,6 +256,14 @@ struct HttpInterface { | |||||
|
|
||||||
| // Call just before the Context is deleted. See RootInterface. | ||||||
| virtual void onDelete() = 0; | ||||||
|
|
||||||
| // Inject encoded data to filter chain | ||||||
| virtual WasmResult injectEncodedDataToFilterChain(std::string_view /* body_text */, bool /* end_stream */) = 0; | ||||||
|
|
||||||
| // Get all enpoint metrics of upstream cluster | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注释拼写错误影响可读性
📋 问题详情getUpstreamHosts注释中'enpoint'应为'endpoint',拼写错误影响文档准确性。 💡 解决方案修正拼写: -enpoint
+endpoint🔧 建议代码
Suggested change
|
||||||
| virtual WasmResult getUpstreamHosts(StringPairs * /* result */) = 0; | ||||||
| // Override upstream host and bypass lb policy | ||||||
| virtual WasmResult setUpstreamOverrideHost(std::string_view /* address */) = 0; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -159,6 +159,58 @@ Word send_local_response(Word response_code, Word response_code_details_ptr, | |||||||||||||||||||||||||||||||||||||||||
| return WasmResult::Ok; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Word inject_encoded_data_to_filter_chain(Word body_ptr, Word body_size, Word end_stream) { | ||||||||||||||||||||||||||||||||||||||||||
| auto *context = contextOrEffectiveContext(); | ||||||||||||||||||||||||||||||||||||||||||
| auto body = context->wasmVm()->getMemory(body_ptr, body_size); | ||||||||||||||||||||||||||||||||||||||||||
| if (!body) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| context->injectEncodedDataToFilterChain(body.value(), end_stream != 0U); | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::Ok; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Word get_upstream_hosts(Word ptr_ptr, Word size_ptr) { | ||||||||||||||||||||||||||||||||||||||||||
| auto *context = contextOrEffectiveContext(); | ||||||||||||||||||||||||||||||||||||||||||
| StringPairs pairs; | ||||||||||||||||||||||||||||||||||||||||||
| auto result = context->getUpstreamHosts(&pairs); | ||||||||||||||||||||||||||||||||||||||||||
| if (result != WasmResult::Ok) { | ||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (pairs.empty()) { | ||||||||||||||||||||||||||||||||||||||||||
| if (!context->wasm()->copyToPointerSize("", ptr_ptr, size_ptr)) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::Ok; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+172
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get_upstream_hosts空列表处理逻辑错误
📋 问题详情当pairs为空时,调用copyToPointerSize写入空字符串,但size_ptr应设为0而非写入内容,可能导致内存访问错误。 💡 解决方案修改为空列表处理逻辑: -copyToPointerSize("", ptr_ptr, size_ptr)
+setWord(size_ptr, 0)🔧 建议代码
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| uint64_t size = PairsUtil::pairsSize(pairs); | ||||||||||||||||||||||||||||||||||||||||||
| uint64_t ptr = 0; | ||||||||||||||||||||||||||||||||||||||||||
| char *buffer = static_cast<char *>(context->wasm()->allocMemory(size, &ptr)); | ||||||||||||||||||||||||||||||||||||||||||
| if (buffer == nullptr) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+186
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 内存分配未处理释放逻辑
📋 问题详情allocMemory分配的内存未在异常路径释放,可能导致内存泄漏。需添加错误处理时的释放逻辑。 💡 解决方案添加释放保护: + // 在所有return前确保释放
+ if (!PairsUtil::marshalPairs(pairs, buffer, size)) {
+ context->wasm()->freeMemory(buffer);
+ return WasmResult::InvalidMemoryAccess;
+ }
|
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (!PairsUtil::marshalPairs(pairs, buffer, size)) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (!context->wasmVm()->setWord(ptr_ptr, Word(ptr))) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (!context->wasmVm()->setWord(size_ptr, Word(size))) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::Ok; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Word set_upstream_override_host(Word address_ptr, Word address_size) { | ||||||||||||||||||||||||||||||||||||||||||
| auto *context = contextOrEffectiveContext(); | ||||||||||||||||||||||||||||||||||||||||||
| auto address = context->wasmVm()->getMemory(address_ptr, address_size); | ||||||||||||||||||||||||||||||||||||||||||
| if (!address) { | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::InvalidMemoryAccess; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| context->setUpstreamOverrideHost(address.value()); | ||||||||||||||||||||||||||||||||||||||||||
| return WasmResult::Ok; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Word clear_route_cache() { | ||||||||||||||||||||||||||||||||||||||||||
| auto *context = contextOrEffectiveContext(); | ||||||||||||||||||||||||||||||||||||||||||
| context->clearRouteCache(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新增方法未实现可能导致运行时错误
📋 问题详情
新增的三个方法(injectEncodedDataToFilterChain/getUpstreamHosts/setUpstreamOverrideHost)均直接返回unimplemented(),未提供实际逻辑。这会导致调用这些接口时返回未实现错误,影响功能完整性。
💡 解决方案
应确保所有新增接口提供基础实现逻辑,至少返回WasmResult::Ok或具体业务逻辑。建议:
有用意见👍 | 无用意见👎 | 错误意见❌