Skip to content
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

Add WASM SEGV handler and test. Create and use a Makefile.base for WASM c++ compiles. #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/wasm/cpp/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
API:=$(shell git rev-parse --show-toplevel)/api/wasm/cpp
jplevyak marked this conversation as resolved.
Show resolved Hide resolved

# Note that optimizations are disabled, because optimized WASM module
# throws wavm.integerDivideByZeroOrOverflow, possibly due to an issue
# with getFunctionWavm() templates and/or their usage. -O3 removed.

ifdef NO_CONTEXT
CONTEXT_LIB =
else
CONTEXT_LIB = ${API}/proxy_wasm_intrinsics.cc
endif

%.wasm %.wat: %.cc ${API}/proxy_wasm_intrinsics.h ${API}/proxy_wasm_intrinsics.js
em++ -s WASM=1 -s LEGALIZE_JS_FFI=0 -s EMIT_EMSCRIPTEN_METADATA=1 --std=c++14 -g3 -I${API} --js-library ${API}/proxy_wasm_intrinsics.js $*.cc ${CONTEXT_LIB} -o $*.js
wavm-disas $*.wasm $*.wat
wavm-compile $*.wasm $*.wasm
rm -f $*.js $*.wast
chmod 644 $*.wat
4 changes: 4 additions & 0 deletions source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ uint32_t httpCallHandler(void* raw_context, uint32_t uri_ptr, uint32_t uri_size,

uint32_t getTotalMemoryHandler(void*) { return 0x7FFFFFFF; }
uint32_t _emscripten_get_heap_sizeHandler(void*) { return 0x7FFFFFFF; }
void _llvm_trapHandler(void*) {
throw WasmException("emscripten llvm_trap");
}

void setTickPeriodMillisecondsHandler(void* raw_context, uint32_t tick_period_milliseconds) {
WASM_CONTEXT(raw_context)->setTickPeriod(std::chrono::milliseconds(tick_period_milliseconds));
Expand Down Expand Up @@ -941,6 +944,7 @@ Wasm::Wasm(absl::string_view vm, absl::string_view id, absl::string_view initial
#define _REGISTER(_fn) registerCallback(wasm_vm_.get(), #_fn, &_fn##Handler);
_REGISTER(getTotalMemory);
_REGISTER(_emscripten_get_heap_size);
_REGISTER(_llvm_trap);
#undef _REGISTER

// Calls with the "_proxy_" prefix.
Expand Down
15 changes: 1 addition & 14 deletions test/extensions/access_loggers/wasm/test_data/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Note that optimizations are disabled, because optimized WASM module
# throws wavm.integerDivideByZeroOrOverflow, possibly due to an issue
# with getFunctionWavm() templates and/or their usage.
#OPT=-O3
OPT=
API=../../../../../api/wasm/cpp
include ../../../../../api/wasm/cpp/Makefile.base

all: logging.wasm

logging.wasm logging.wat: logging.cc ${API}/proxy_wasm_intrinsics.h ${API}/proxy_wasm_intrinsics.cc ${API}/proxy_wasm_intrinsics.js
em++ -s WASM=1 --std=c++14 $(OPT) -g3 -I${API} --js-library ${API}/proxy_wasm_intrinsics.js logging.cc ${API}/proxy_wasm_intrinsics.cc -o logging.js
wasm-gc logging.wasm
wavm-disas logging.wasm logging.wat
rm -f logging.js logging.wast
chmod 644 logging.wat

Binary file modified test/extensions/access_loggers/wasm/test_data/logging.wasm
Binary file not shown.
Loading