Skip to content

Commit

Permalink
Add proxy_abi_version_X_Y_Z and mark what we have as v0.1.0. (envoypr…
Browse files Browse the repository at this point in the history
…oxy#438) (envoyproxy#169)

Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored Feb 28, 2020
1 parent 5114da0 commit 55b8c01
Show file tree
Hide file tree
Showing 40 changed files with 52 additions and 6 deletions.
3 changes: 3 additions & 0 deletions api/wasm/cpp/proxy_wasm_intrinsics.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// NOLINT(namespace-envoy)
#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

static std::unordered_map<std::string, RootFactory>* root_factories = nullptr;
static std::unordered_map<std::string, ContextFactory>* context_factories = nullptr;
static std::unordered_map<int32_t, std::unique_ptr<ContextBase>> context_map;
Expand Down
Binary file modified examples/wasm/envoy_filter_http_wasm_example.wasm
Binary file not shown.
4 changes: 3 additions & 1 deletion source/extensions/common/wasm/null/null_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ using Plugin::Context;
using Plugin::WasmData;

void NullPlugin::getFunction(absl::string_view function_name, WasmCallVoid<0>* f) {
if (function_name == "_start") {
if (function_name == "proxy_abi_version_0_1_0") {
*f = [](Common::Wasm::Context*) { /* dummy function */ };
} else if (function_name == "_start") {
*f = nullptr;
} else if (function_name == "__wasm_call_ctors") {
*f = nullptr;
Expand Down
12 changes: 8 additions & 4 deletions source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,17 @@ void Wasm::getFunctions() {
_GET(__wasm_call_ctors);

_GET(malloc);
if (!malloc_) {
throw WasmException("WASM missing malloc");
}
#undef _GET

#define _GET_PROXY(_fn) wasm_vm_->getFunction("proxy_" #_fn, &_fn##_);
_GET_PROXY(abi_version_0_1_0);
if (!abi_version_0_1_0_) {
throw WasmException("WASM missing Proxy-Wasm ABI version or requires an unsupported version.");
}

_GET_PROXY(validate_configuration);
_GET_PROXY(on_vm_start);
_GET_PROXY(on_configure);
Expand Down Expand Up @@ -250,10 +258,6 @@ void Wasm::getFunctions() {
_GET_PROXY(on_log);
_GET_PROXY(on_delete);
#undef _GET_PROXY

if (!malloc_) {
throw WasmException("WASM missing malloc");
}
}

Wasm::Wasm(WasmHandleSharedPtr& base_wasm_handle, Event::Dispatcher& dispatcher)
Expand Down
2 changes: 2 additions & 0 deletions source/extensions/common/wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class Wasm : public Logger::Loggable<Logger::Id::wasm>, public std::enable_share

TimeSource& time_source_;

WasmCallVoid<0> abi_version_0_1_0_;

WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */
WasmCallVoid<0> __wasm_call_ctors_;

Expand Down
Binary file modified test/extensions/access_loggers/wasm/test_data/logging.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/common/wasm/test_data/bad_signature_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#define EMSCRIPTEN_KEEPALIVE __attribute__((used)) __attribute__((visibility("default")))

// Required Proxy-Wasm ABI version.
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_abi_version_0_1_0() {}

extern "C" uint32_t proxy_log(uint32_t level, const char* logMessage, size_t messageSize);

extern "C" EMSCRIPTEN_KEEPALIVE uint32_t proxy_on_configure(uint32_t, int bad, char* configuration,
Expand Down
Binary file modified test/extensions/common/wasm/test_data/bad_signature_cpp.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions test/extensions/common/wasm/test_data/test_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#ifndef NULL_PLUGIN
#include "proxy_wasm_intrinsics.h"
// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}
#else
#include "extensions/common/wasm/null/null_plugin.h"
#endif
Expand Down
Binary file modified test/extensions/common/wasm/test_data/test_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/common/wasm/test_data/test_rust.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/async_call_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/grpc_call_cpp.wasm
Binary file not shown.
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/headers_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/http_callout_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/metadata_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/queue_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/shared_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/network/wasm/test_data/logging_cpp.wasm
Binary file not shown.
5 changes: 4 additions & 1 deletion test/extensions/wasm/test_data/asm2wasm_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

#include "proxy_wasm_intrinsics.h"

// Use global variables so the compiler cannot optimize the operations away.
// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

// Use global variables so the compiler cannot optimize the operations away.
int32_t i32a = 0;
int32_t i32b = 1;
double f64a = 0.0;
Expand Down
Binary file modified test/extensions/wasm/test_data/asm2wasm_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/bad_signature_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#define PROXY_WASM_KEEPALIVE __attribute__((used)) __attribute__((visibility("default")))

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

extern "C" uint32_t proxy_log(uint32_t level, const char* logMessage, size_t messageSize);

extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_configure(uint32_t, int bad, char* configuration,
Expand Down
Binary file modified test/extensions/wasm/test_data/bad_signature_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/emscripten_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

float gNan = std::nan("1");
float gInfinity = INFINITY;

Expand Down
Binary file modified test/extensions/wasm/test_data/emscripten_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/logging_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_configure(uint32_t, uint32_t) {
const char* configuration = nullptr;
size_t size;
Expand Down
Binary file modified test/extensions/wasm/test_data/logging_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/logging_rust.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/extensions/wasm/test_data/logging_rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#[allow(unused_imports)]
use proxy_wasm;

// Required Proxy-Wasm ABI version.
#[no_mangle]
pub fn proxy_abi_version_0_1_0() {}

use log::{debug, error, info, trace, warn};

extern "C" {
Expand Down
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/missing_cpp.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// NOLINT(namespace-envoy)
#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

extern "C" void missing();

extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_vm_start(uint32_t, uint32_t) {
Expand Down
Binary file modified test/extensions/wasm/test_data/missing_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/segv_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

static int* badptr = nullptr;

extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_vm_start(uint32_t, uint32_t) {
Expand Down
Binary file modified test/extensions/wasm/test_data/segv_cpp.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions test/extensions/wasm/test_data/speed_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#ifndef NULL_PLUGIN
#include "proxy_wasm_intrinsics.h"
// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}
#else
#include "extensions/common/wasm/null/null_plugin.h"
#endif
Expand Down
Binary file modified test/extensions/wasm/test_data/speed_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/start_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_vm_start(uint32_t, uint32_t) {
logDebug("onStart");
return 1;
Expand Down
Binary file modified test/extensions/wasm/test_data/start_cpp.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions test/extensions/wasm/test_data/stats_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "proxy_wasm_intrinsics.h"

// Required Proxy-Wasm ABI version.
extern "C" PROXY_WASM_KEEPALIVE void proxy_abi_version_0_1_0() {}

// Test the low level interface.
extern "C" PROXY_WASM_KEEPALIVE uint32_t proxy_on_vm_start(uint32_t, uint32_t) {
uint32_t c, g, h;
Expand Down
Binary file modified test/extensions/wasm/test_data/stats_cpp.wasm
Binary file not shown.

0 comments on commit 55b8c01

Please sign in to comment.