-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix comments format and lints Signed-off-by: Protryon <max.bruce12@gmail.com>
- Loading branch information
Showing
13 changed files
with
1,003 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,70 @@ | ||
// 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 { | ||
|
||
class WasmVm; | ||
std::unique_ptr<WasmVm> createDynVm(); | ||
|
||
// 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 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 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 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,22 @@ | ||
// 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_vm.h" | ||
|
||
namespace proxy_wasm { | ||
|
||
std::unique_ptr<WasmVm> createDynVm() { return std::make_unique<DynVm>(); } | ||
|
||
} // namespace proxy_wasm |
Oops, something went wrong.