-
Notifications
You must be signed in to change notification settings - Fork 76
DynVm Implementation: Dynamically loaded native modules #379
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/bazel-* | ||
.vscode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2016-2019 Envoy Project Authors | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace proxy_wasm { | ||
|
||
class WasmVm; | ||
std::unique_ptr<WasmVm> createDynVm(); | ||
|
||
} // namespace proxy_wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2016-2019 Envoy Project Authors | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "include/proxy-wasm/dyn_vm_plugin.h" | ||
#include "include/proxy-wasm/wasm_vm.h" | ||
|
||
namespace proxy_wasm { | ||
|
||
// The DynVm wraps a C++ Wasm plugin which has been compiled with the Wasm API | ||
// and dynamically linked into the proxy. | ||
struct DynVm : public WasmVm { | ||
DynVm() : WasmVm() {} | ||
|
||
// WasmVm | ||
std::string_view getEngineName() override { return "dyn"; } | ||
Cloneable cloneable() override { return Cloneable::InstantiatedModule; }; | ||
std::unique_ptr<WasmVm> clone() override; | ||
bool load(std::string_view plugin_name, std::string_view precompiled, | ||
const std::unordered_map<uint32_t, std::string> &function_names) override; | ||
bool link(std::string_view debug_name) override; | ||
uint64_t getMemorySize() override; | ||
std::optional<std::string_view> getMemory(uint64_t pointer, uint64_t size) override; | ||
bool setMemory(uint64_t pointer, uint64_t size, const void *data) override; | ||
bool setWord(uint64_t pointer, Word data) override; | ||
bool getWord(uint64_t pointer, Word *data) override; | ||
size_t getWordSize() override; | ||
std::string_view getPrecompiledSectionName() override; | ||
|
||
#define _FORWARD_GET_FUNCTION(_T) \ | ||
void getFunction(std::string_view function_name, _T *f) override { \ | ||
plugin_->getFunction(function_name, f); \ | ||
} | ||
FOR_ALL_WASM_VM_EXPORTS(_FORWARD_GET_FUNCTION) | ||
#undef _FORWARD_GET_FUNCTION | ||
|
||
// These are not needed for DynVm which invokes the handlers directly. | ||
#define _REGISTER_CALLBACK(_T) \ | ||
void registerCallback(std::string_view, std::string_view, _T, \ | ||
typename ConvertFunctionTypeWordToUint32<_T>::type) override{}; | ||
FOR_ALL_WASM_VM_IMPORTS(_REGISTER_CALLBACK) | ||
#undef _REGISTER_CALLBACK | ||
|
||
void terminate() override {} | ||
bool usesWasmByteOrder() override { return false; } | ||
|
||
std::unique_ptr<DynVmPlugin> plugin_; | ||
}; | ||
|
||
} // namespace proxy_wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2016-2019 Envoy Project Authors | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "include/proxy-wasm/wasm_vm.h" | ||
|
||
namespace proxy_wasm { | ||
|
||
class DynVmPluginSource { | ||
public: | ||
virtual ~DynVmPluginSource(); | ||
void *dl_handle = nullptr; | ||
int memfd = -1; | ||
}; | ||
|
||
// A wrapper for the dynamically linked DynVm plugin which implements the Wasm ABI. | ||
class DynVmPlugin { | ||
public: | ||
DynVmPlugin() = default; | ||
virtual ~DynVmPlugin() = default; | ||
|
||
// NB: These are defined rather than declared PURE because gmock uses __LINE__ internally for | ||
// uniqueness, making it impossible to use FOR_ALL_WASM_VM_EXPORTS with MOCK_METHOD. | ||
#define _DEFINE_GET_FUNCTION(_T) virtual void getFunction(std::string_view, _T *f); | ||
FOR_ALL_WASM_VM_EXPORTS(_DEFINE_GET_FUNCTION) | ||
#undef _DEFINE_GET_FUNCTION | ||
|
||
WasmVm *wasm_vm_ = nullptr; | ||
std::shared_ptr<DynVmPluginSource> source; | ||
}; | ||
|
||
} // namespace proxy_wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2016-2019 Envoy Project Authors | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "include/proxy-wasm/dyn.h" | ||
#include "include/proxy-wasm/dyn_vm.h" | ||
|
||
namespace proxy_wasm { | ||
|
||
std::unique_ptr<WasmVm> createDynVm() { return std::make_unique<DynVm>(); } | ||
|
||
} // namespace proxy_wasm |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.