Skip to content

Commit 8bdd67d

Browse files
authored
Merge branch 'master' into trace-print
2 parents 3510109 + 8d0727f commit 8bdd67d

File tree

12 files changed

+104
-86
lines changed

12 files changed

+104
-86
lines changed

BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cc_library(
3333
copts = COPTS,
3434
deps = [
3535
":include",
36+
"@boringssl//:crypto",
3637
"@com_google_protobuf//:protobuf_lite",
3738
"@proxy_wasm_cpp_sdk//:api_lib",
3839
],

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @PiotrSikora

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ git_repository(
3838
shallow_since = "1565024848 -0700",
3939
)
4040

41+
http_archive(
42+
name = "boringssl",
43+
sha256 = "bb55b0ed2f0cb548b5dce6a6b8307ce37f7f748eb9f1be6bfe2d266ff2b4d52b",
44+
strip_prefix = "boringssl-2192bbc878822cf6ab5977d4257a1339453d9d39",
45+
urls = ["https://github.com/google/boringssl/archive/2192bbc878822cf6ab5977d4257a1339453d9d39.tar.gz"],
46+
)
47+
4148
http_archive(
4249
name = "com_google_googletest",
4350
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",

include/proxy-wasm/exports.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ Word wasi_unstable_environ_sizes_get(void *raw_context, Word count_ptr, Word buf
144144
Word wasi_unstable_args_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
145145
Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
146146
void wasi_unstable_proc_exit(void *, Word);
147-
void wasi_unstable_proc_exit(void *, Word);
147+
Word wasi_unstable_clock_time_get(void *, Word, uint64_t, Word);
148+
Word wasi_unstable_random_get(void *, Word, Word);
148149
Word pthread_equal(void *, Word left, Word right);
149150

150151
// Support for embedders, not exported to Wasm.

include/proxy-wasm/wasm.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
5959
std::string_view vm_key() const { return vm_key_; }
6060
WasmVm *wasm_vm() const { return wasm_vm_.get(); }
6161
ContextBase *vm_context() const { return vm_context_.get(); }
62-
ContextBase *getRootContext(std::string_view root_id) {
63-
return root_contexts_[std::string(root_id)].get();
64-
}
62+
ContextBase *getRootContext(std::string_view root_id);
6563
ContextBase *getOrCreateRootContext(const std::shared_ptr<PluginBase> &plugin);
6664
ContextBase *getContext(uint32_t id) {
6765
auto it = contexts_.find(id);
@@ -124,20 +122,6 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
124122

125123
AbiVersion abiVersion() { return abi_version_; }
126124

127-
bool getEmscriptenVersion(uint32_t *emscripten_metadata_major_version,
128-
uint32_t *emscripten_metadata_minor_version,
129-
uint32_t *emscripten_abi_major_version,
130-
uint32_t *emscripten_abi_minor_version) {
131-
if (!is_emscripten_) {
132-
return false;
133-
}
134-
*emscripten_metadata_major_version = emscripten_metadata_major_version_;
135-
*emscripten_metadata_minor_version = emscripten_metadata_minor_version_;
136-
*emscripten_abi_major_version = emscripten_abi_major_version_;
137-
*emscripten_abi_minor_version = emscripten_abi_minor_version_;
138-
return true;
139-
}
140-
141125
void addAfterVmCallAction(std::function<void()> f) { after_vm_call_actions_.push_back(f); }
142126
void doAfterVmCallActions() {
143127
// NB: this may be deleted by a delayed function unless prevented.
@@ -186,7 +170,8 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
186170
std::unique_ptr<ShutdownHandle> shutdown_handle_;
187171
std::unordered_set<ContextBase *> pending_done_; // Root contexts not done during shutdown.
188172

189-
WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */
173+
WasmCallVoid<0> _initialize_; /* Emscripten v1.39.17+ */
174+
WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */
190175
WasmCallVoid<0> __wasm_call_ctors_;
191176

192177
WasmCallWord<1> malloc_;
@@ -243,13 +228,6 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
243228
// ABI version.
244229
AbiVersion abi_version_ = AbiVersion::Unknown;
245230

246-
bool is_emscripten_ = false;
247-
uint32_t emscripten_metadata_major_version_ = 0;
248-
uint32_t emscripten_metadata_minor_version_ = 0;
249-
uint32_t emscripten_abi_major_version_ = 0;
250-
uint32_t emscripten_abi_minor_version_ = 0;
251-
uint32_t emscripten_standalone_wasm_ = 0;
252-
253231
// Plugin Stats/Metrics
254232
uint32_t next_counter_metric_id_ = static_cast<uint32_t>(MetricType::Counter);
255233
uint32_t next_gauge_metric_id_ = static_cast<uint32_t>(MetricType::Gauge);

include/proxy-wasm/wasm_vm.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include <functional>
1919
#include <memory>
20-
#include <string>
2120
#include <optional>
21+
#include <string>
2222

2323
#include "include/proxy-wasm/word.h"
2424

@@ -78,6 +78,7 @@ template <size_t N> using WasmCallbackWord = WasmFuncType<N, Word, void *, Word>
7878
using WasmCallback_WWl = Word (*)(void *, Word, int64_t);
7979
using WasmCallback_WWlWW = Word (*)(void *, Word, int64_t, Word, Word);
8080
using WasmCallback_WWm = Word (*)(void *, Word, uint64_t);
81+
using WasmCallback_WWmW = Word (*)(void *, Word, uint64_t, Word);
8182
using WasmCallback_dd = double (*)(void *, double);
8283

8384
#define FOR_ALL_WASM_VM_IMPORTS(_f) \
@@ -94,7 +95,8 @@ using WasmCallback_dd = double (*)(void *, double);
9495
_f(proxy_wasm::WasmCallback_WWl) \
9596
_f(proxy_wasm::WasmCallback_WWlWW) \
9697
_f(proxy_wasm::WasmCallback_WWm) \
97-
_f(proxy_wasm::WasmCallback_dd)
98+
_f(proxy_wasm::WasmCallback_WWmW) \
99+
_f(proxy_wasm::WasmCallback_dd)
98100

99101
enum class Cloneable {
100102
NotCloneable, // VMs can not be cloned and should be created from scratch.

src/context.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,24 @@ bool ContextBase::onStart(std::shared_ptr<PluginBase> plugin) {
331331
}
332332

333333
bool ContextBase::onConfigure(std::shared_ptr<PluginBase> plugin) {
334-
if (isFailed() || !wasm_->on_configure_) {
334+
if (isFailed()) {
335335
return true;
336336
}
337+
338+
// on_context_create is yet to be executed for all the root contexts except the first one
339+
if (!in_vm_context_created_ && wasm_->on_context_create_) {
340+
DeferAfterCallActions actions(this);
341+
wasm_->on_context_create_(this, id_, 0);
342+
}
343+
344+
// NB: If no on_context_create function is registered the in-VM SDK is responsible for
345+
// managing any required in-VM state.
346+
in_vm_context_created_ = true;
347+
348+
if (!wasm_->on_configure_) {
349+
return true;
350+
}
351+
337352
DeferAfterCallActions actions(this);
338353
plugin_ = plugin;
339354
auto result =

src/exports.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//
1616
#include "include/proxy-wasm/wasm.h"
1717

18+
#include <openssl/rand.h>
19+
1820
#define WASM_CONTEXT(_c) \
1921
(ContextOrEffectiveContext(static_cast<ContextBase *>((void)_c, current_context_)))
2022

@@ -798,6 +800,33 @@ Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_bu
798800
return 0; // __WASI_ESUCCESS
799801
}
800802

803+
// __wasi_errno_t __wasi_clock_time_get(uint32_t id, uint64_t precision, uint64_t* time);
804+
Word wasi_unstable_clock_time_get(void *raw_context, Word clock_id, uint64_t precision,
805+
Word result_time_uint64_ptr) {
806+
807+
if (clock_id != 0 /* realtime */) {
808+
return 58; // __WASI_ENOTSUP
809+
}
810+
811+
auto context = WASM_CONTEXT(raw_context);
812+
uint64_t result = context->getCurrentTimeNanoseconds();
813+
if (!context->wasm()->setDatatype(result_time_uint64_ptr, result)) {
814+
return 21; // __WASI_EFAULT
815+
}
816+
return 0; // __WASI_ESUCCESS
817+
}
818+
819+
// __wasi_errno_t __wasi_random_get(uint8_t *buf, size_t buf_len);
820+
Word wasi_unstable_random_get(void *raw_context, Word result_buf_ptr, Word buf_len) {
821+
auto context = WASM_CONTEXT(raw_context);
822+
std::vector<uint8_t> random(buf_len);
823+
RAND_bytes(random.data(), random.size());
824+
if (!context->wasmVm()->setMemory(result_buf_ptr, random.size(), random.data())) {
825+
return 21; // __WASI_EFAULT
826+
}
827+
return 0; // __WASI_ESUCCESS
828+
}
829+
801830
// void __wasi_proc_exit(__wasi_exitcode_t rval);
802831
void wasi_unstable_proc_exit(void *raw_context, Word) {
803832
auto context = WASM_CONTEXT(raw_context);

src/null/null_plugin.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
namespace proxy_wasm {
3434

3535
void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<0> *f) {
36-
if (function_name == "_start") {
36+
if (function_name == "_initialize") {
37+
*f = nullptr;
38+
} else if (function_name == "_start") {
3739
*f = nullptr;
3840
} else if (function_name == "__wasm_call_ctors") {
3941
*f = nullptr;

src/v8/v8.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,15 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
616616
return;
617617
}
618618
const wasm::Func *func = it->second.get();
619-
if (!equalValTypes(func->type()->params(), convertArgsTupleToValTypes<std::tuple<Args...>>()) ||
620-
!equalValTypes(func->type()->results(), convertArgsTupleToValTypes<std::tuple<>>())) {
619+
auto arg_valtypes = convertArgsTupleToValTypes<std::tuple<Args...>>();
620+
auto result_valtypes = convertArgsTupleToValTypes<std::tuple<>>();
621+
if (!equalValTypes(func->type()->params(), arg_valtypes) ||
622+
!equalValTypes(func->type()->results(), result_valtypes)) {
621623
fail(FailState::UnableToInitializeCode,
622-
std::string("Bad function signature for: ") + std::string(function_name));
624+
"Bad function signature for: " + std::string(function_name) +
625+
", want: " + printValTypes(arg_valtypes) + " -> " + printValTypes(result_valtypes) +
626+
", but the module exports: " + printValTypes(func->type()->params()) + " -> " +
627+
printValTypes(result_valtypes));
623628
*function = nullptr;
624629
return;
625630
}
@@ -643,10 +648,15 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
643648
return;
644649
}
645650
const wasm::Func *func = it->second.get();
646-
if (!equalValTypes(func->type()->params(), convertArgsTupleToValTypes<std::tuple<Args...>>()) ||
647-
!equalValTypes(func->type()->results(), convertArgsTupleToValTypes<std::tuple<R>>())) {
651+
auto arg_valtypes = convertArgsTupleToValTypes<std::tuple<Args...>>();
652+
auto result_valtypes = convertArgsTupleToValTypes<std::tuple<R>>();
653+
if (!equalValTypes(func->type()->params(), arg_valtypes) ||
654+
!equalValTypes(func->type()->results(), result_valtypes)) {
648655
fail(FailState::UnableToInitializeCode,
649-
"Bad function signature for: " + std::string(function_name));
656+
"Bad function signature for: " + std::string(function_name) +
657+
", want: " + printValTypes(arg_valtypes) + " -> " + printValTypes(result_valtypes) +
658+
", but the module exports: " + printValTypes(func->type()->params()) + " -> " +
659+
printValTypes(result_valtypes));
650660
*function = nullptr;
651661
return;
652662
}

0 commit comments

Comments
 (0)