1
+ From d6e7129f1d3f52fd1eca3bdaf91d06bb8a14e70d Mon Sep 17 00:00:00 2001
2
+ From: Matt Leon <
[email protected] >
3
+ Date: Wed, 16 Jul 2025 20:05:48 -0400
4
+ Subject: [PATCH 1/3] chore: Update v8 to use 13.8 interface
5
+
6
+ Signed-off-by: Matt Leon <
[email protected] >
7
+ ---
8
+ src/v8/v8.cc | 84 ++++++++++++++++++++++++++--------------------------
9
+ 1 file changed, 42 insertions(+), 42 deletions(-)
10
+
11
+ diff --git a/src/v8/v8.cc b/src/v8/v8.cc
12
+ index 61779c1..1047f5c 100644
13
+ --- a/src/v8/v8.cc
14
+ +++ b/src/v8/v8.cc
15
+ @@ -140,20 +140,20 @@ private:
16
+
17
+ static std::string printValue(const wasm::Val &value) {
18
+ switch (value.kind()) {
19
+ - case wasm::I32:
20
+ + case wasm::ValKind::I32:
21
+ return std::to_string(value.get<uint32_t>());
22
+ - case wasm::I64:
23
+ + case wasm::ValKind::I64:
24
+ return std::to_string(value.get<uint64_t>());
25
+ - case wasm::F32:
26
+ + case wasm::ValKind::F32:
27
+ return std::to_string(value.get<float>());
28
+ - case wasm::F64:
29
+ + case wasm::ValKind::F64:
30
+ return std::to_string(value.get<double>());
31
+ default:
32
+ return "unknown";
33
+ }
34
+ }
35
+
36
+ - static std::string printValues(const wasm::Val values[], size_t size) {
37
+ + static std::string printValues(const wasm::vec<wasm::Val> &values, size_t size) {
38
+ if (size == 0) {
39
+ return "";
40
+ }
41
+ @@ -170,17 +170,17 @@ static std::string printValues(const wasm::Val values[], size_t size) {
42
+
43
+ static const char *printValKind(wasm::ValKind kind) {
44
+ switch (kind) {
45
+ - case wasm::I32:
46
+ + case wasm::ValKind::I32:
47
+ return "i32";
48
+ - case wasm::I64:
49
+ + case wasm::ValKind::I64:
50
+ return "i64";
51
+ - case wasm::F32:
52
+ + case wasm::ValKind::F32:
53
+ return "f32";
54
+ - case wasm::F64:
55
+ + case wasm::ValKind::F64:
56
+ return "f64";
57
+ - case wasm::ANYREF:
58
+ - return "anyref";
59
+ - case wasm::FUNCREF:
60
+ + case wasm::ValKind::EXTERNREF:
61
+ + return "externref";
62
+ + case wasm::ValKind::FUNCREF:
63
+ return "funcref";
64
+ default:
65
+ return "unknown";
66
+ @@ -229,11 +229,11 @@ template <typename T> wasm::Val makeVal(T t) { return wasm::Val::make(t); }
67
+ template <> wasm::Val makeVal(Word t) { return wasm::Val::make(static_cast<uint32_t>(t.u64_)); }
68
+
69
+ template <typename T> constexpr auto convertArgToValKind();
70
+ - template <> constexpr auto convertArgToValKind<Word>() { return wasm::I32; };
71
+ - template <> constexpr auto convertArgToValKind<uint32_t>() { return wasm::I32; };
72
+ - template <> constexpr auto convertArgToValKind<int64_t>() { return wasm::I64; };
73
+ - template <> constexpr auto convertArgToValKind<uint64_t>() { return wasm::I64; };
74
+ - template <> constexpr auto convertArgToValKind<double>() { return wasm::F64; };
75
+ + template <> constexpr auto convertArgToValKind<Word>() { return wasm::ValKind::I32; };
76
+ + template <> constexpr auto convertArgToValKind<uint32_t>() { return wasm::ValKind::I32; };
77
+ + template <> constexpr auto convertArgToValKind<int64_t>() { return wasm::ValKind::I64; };
78
+ + template <> constexpr auto convertArgToValKind<uint64_t>() { return wasm::ValKind::I64; };
79
+ + template <> constexpr auto convertArgToValKind<double>() { return wasm::ValKind::F64; };
80
+
81
+ template <typename T, std::size_t... I>
82
+ constexpr auto convertArgsTupleToValTypesImpl(std::index_sequence<I...> /*comptime*/) {
83
+ @@ -343,7 +343,8 @@ bool V8::link(std::string_view /*debug_name*/) {
84
+ assert(module_ != nullptr);
85
+
86
+ const auto import_types = module_.get()->imports();
87
+ - std::vector<const wasm::Extern *> imports;
88
+ + wasm::vec<wasm::Extern *> imports =
89
+ + wasm::vec<wasm::Extern *>::make_uninitialized(import_types.size());
90
+
91
+ for (size_t i = 0; i < import_types.size(); i++) {
92
+ std::string_view module(import_types[i]->module().get(), import_types[i]->module().size());
93
+ @@ -352,7 +353,7 @@ bool V8::link(std::string_view /*debug_name*/) {
94
+
95
+ switch (import_type->kind()) {
96
+
97
+ - case wasm::EXTERN_FUNC: {
98
+ + case wasm::ExternKind::FUNC: {
99
+ auto it = host_functions_.find(std::string(module) + "." + std::string(name));
100
+ if (it == host_functions_.end()) {
101
+ fail(FailState::UnableToInitializeCode,
102
+ @@ -372,10 +373,10 @@ bool V8::link(std::string_view /*debug_name*/) {
103
+ printValTypes(func->type()->results()));
104
+ return false;
105
+ }
106
+ - imports.push_back(func);
107
+ + imports[i] = func;
108
+ } break;
109
+
110
+ - case wasm::EXTERN_GLOBAL: {
111
+ + case wasm::ExternKind::GLOBAL: {
112
+ // TODO(PiotrSikora): add support when/if needed.
113
+ fail(FailState::UnableToInitializeCode,
114
+ "Failed to load Wasm module due to a missing import: " + std::string(module) + "." +
115
+ @@ -383,7 +384,7 @@ bool V8::link(std::string_view /*debug_name*/) {
116
+ return false;
117
+ } break;
118
+
119
+ - case wasm::EXTERN_MEMORY: {
120
+ + case wasm::ExternKind::MEMORY: {
121
+ assert(memory_ == nullptr);
122
+ auto type = wasm::MemoryType::make(import_type->memory()->limits());
123
+ if (type == nullptr) {
124
+ @@ -393,10 +394,10 @@ bool V8::link(std::string_view /*debug_name*/) {
125
+ if (memory_ == nullptr) {
126
+ return false;
127
+ }
128
+ - imports.push_back(memory_.get());
129
+ + imports[i] = memory_.get();
130
+ } break;
131
+
132
+ - case wasm::EXTERN_TABLE: {
133
+ + case wasm::ExternKind::TABLE: {
134
+ assert(table_ == nullptr);
135
+ auto type =
136
+ wasm::TableType::make(wasm::ValType::make(import_type->table()->element()->kind()),
137
+ @@ -408,16 +409,12 @@ bool V8::link(std::string_view /*debug_name*/) {
138
+ if (table_ == nullptr) {
139
+ return false;
140
+ }
141
+ - imports.push_back(table_.get());
142
+ + imports[i] = table_.get();
143
+ } break;
144
+ }
145
+ }
146
+
147
+ - if (import_types.size() != imports.size()) {
148
+ - return false;
149
+ - }
150
+ -
151
+ - instance_ = wasm::Instance::make(store_.get(), module_.get(), imports.data());
152
+ + instance_ = wasm::Instance::make(store_.get(), module_.get(), imports);
153
+ if (instance_ == nullptr) {
154
+ fail(FailState::UnableToInitializeCode, "Failed to create new Wasm instance");
155
+ return false;
156
+ @@ -435,16 +432,16 @@ bool V8::link(std::string_view /*debug_name*/) {
157
+
158
+ switch (export_type->kind()) {
159
+
160
+ - case wasm::EXTERN_FUNC: {
161
+ + case wasm::ExternKind::FUNC: {
162
+ assert(export_item->func() != nullptr);
163
+ module_functions_.insert_or_assign(std::string(name), export_item->func()->copy());
164
+ } break;
165
+
166
+ - case wasm::EXTERN_GLOBAL: {
167
+ + case wasm::ExternKind::GLOBAL: {
168
+ // TODO(PiotrSikora): add support when/if needed.
169
+ } break;
170
+
171
+ - case wasm::EXTERN_MEMORY: {
172
+ + case wasm::ExternKind::MEMORY: {
173
+ assert(export_item->memory() != nullptr);
174
+ assert(memory_ == nullptr);
175
+ memory_ = exports[i]->memory()->copy();
176
+ @@ -453,7 +450,7 @@ bool V8::link(std::string_view /*debug_name*/) {
177
+ }
178
+ } break;
179
+
180
+ - case wasm::EXTERN_TABLE: {
181
+ + case wasm::ExternKind::TABLE: {
182
+ // TODO(PiotrSikora): add support when/if needed.
183
+ } break;
184
+ }
185
+ @@ -531,7 +528,8 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
186
+ convertArgsTupleToValTypes<std::tuple<>>());
187
+ auto func = wasm::Func::make(
188
+ store_.get(), type.get(),
189
+ - [](void *data, const wasm::Val params[], wasm::Val /*results*/[]) -> wasm::own<wasm::Trap> {
190
+ + [](void *data, const wasm::vec<wasm::Val> ¶ms,
191
+ + wasm::vec<wasm::Val> & /*results*/) -> wasm::own<wasm::Trap> {
192
+ auto *func_data = reinterpret_cast<FuncData *>(data);
193
+ const bool log = func_data->vm_->cmpLogLevel(LogLevel::trace);
194
+ if (log) {
195
+ @@ -567,7 +565,8 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
196
+ convertArgsTupleToValTypes<std::tuple<R>>());
197
+ auto func = wasm::Func::make(
198
+ store_.get(), type.get(),
199
+ - [](void *data, const wasm::Val params[], wasm::Val results[]) -> wasm::own<wasm::Trap> {
200
+ + [](void *data, const wasm::vec<wasm::Val> ¶ms,
201
+ + wasm::vec<wasm::Val> &results) -> wasm::own<wasm::Trap> {
202
+ auto *func_data = reinterpret_cast<FuncData *>(data);
203
+ const bool log = func_data->vm_->cmpLogLevel(LogLevel::trace);
204
+ if (log) {
205
+ @@ -621,20 +620,21 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
206
+ const bool log = cmpLogLevel(LogLevel::trace);
207
+ SaveRestoreContext saved_context(context);
208
+ wasm::own<wasm::Trap> trap = nullptr;
209
+ + wasm::vec<wasm::Val> results = wasm::vec<wasm::Val>::make_uninitialized();
210
+
211
+ // Workaround for MSVC++ not supporting zero-sized arrays.
212
+ if constexpr (sizeof...(args) > 0) {
213
+ - wasm::Val params[] = {makeVal(args)...};
214
+ + wasm::vec<wasm::Val> params = wasm::vec<wasm::Val>::make(makeVal(args)...);
215
+ if (log) {
216
+ integration()->trace("[host->vm] " + std::string(function_name) + "(" +
217
+ printValues(params, sizeof...(Args)) + ")");
218
+ }
219
+ - trap = func->call(params, nullptr);
220
+ + trap = func->call(params, results);
221
+ } else {
222
+ if (log) {
223
+ integration()->trace("[host->vm] " + std::string(function_name) + "()");
224
+ }
225
+ - trap = func->call(nullptr, nullptr);
226
+ + trap = func->call(wasm::vec<wasm::Val>::make_uninitialized(), results);
227
+ }
228
+
229
+ if (trap) {
230
+ @@ -671,12 +671,12 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
231
+ *function = [func, function_name, this](ContextBase *context, Args... args) -> R {
232
+ const bool log = cmpLogLevel(LogLevel::trace);
233
+ SaveRestoreContext saved_context(context);
234
+ - wasm::Val results[1];
235
+ + wasm::vec<wasm::Val> results = wasm::vec<wasm::Val>::make_uninitialized(1);
236
+ wasm::own<wasm::Trap> trap = nullptr;
237
+
238
+ // Workaround for MSVC++ not supporting zero-sized arrays.
239
+ if constexpr (sizeof...(args) > 0) {
240
+ - wasm::Val params[] = {makeVal(args)...};
241
+ + wasm::vec<wasm::Val> params = wasm::vec<wasm::Val>::make(makeVal(args)...);
242
+ if (log) {
243
+ integration()->trace("[host->vm] " + std::string(function_name) + "(" +
244
+ printValues(params, sizeof...(Args)) + ")");
245
+ @@ -686,7 +686,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
246
+ if (log) {
247
+ integration()->trace("[host->vm] " + std::string(function_name) + "()");
248
+ }
249
+ - trap = func->call(nullptr, results);
250
+ + trap = func->call(wasm::vec<wasm::Val>::make_uninitialized(), results);
251
+ }
252
+
253
+ if (trap) {
254
+ - -
255
+ 2.50.0.727.gbf7dc18ff4-goog
256
+
257
+
258
+ From 6c2ffcb9d797d86e817dc29e0dea53e8bd53bdcf Mon Sep 17 00:00:00 2001
259
+ From: Matt Leon <
[email protected] >
260
+ Date: Fri, 18 Jul 2025 09:29:26 -0400
261
+ Subject: [PATCH 2/3] fix: remove racy call to
262
+ isolate->IsExecutionTerminating()
263
+
264
+ Signed-off-by: Matt Leon <
[email protected] >
265
+ ---
266
+ src/v8/v8.cc | 3 ---
267
+ 1 file changed, 3 deletions(-)
268
+
269
+ diff --git a/src/v8/v8.cc b/src/v8/v8.cc
270
+ index 1047f5c..bc5b828 100644
271
+ --- a/src/v8/v8.cc
272
+ +++ b/src/v8/v8.cc
273
+ @@ -706,9 +706,6 @@ void V8::terminate() {
274
+ auto *store_impl = reinterpret_cast<wasm::StoreImpl *>(store_.get());
275
+ auto *isolate = store_impl->isolate();
276
+ isolate->TerminateExecution();
277
+ - while (isolate->IsExecutionTerminating()) {
278
+ - std::this_thread::yield();
279
+ - }
280
+ }
281
+
282
+ std::string V8::getFailMessage(std::string_view function_name, wasm::own<wasm::Trap> trap) {
283
+ - -
284
+ 2.50.0.727.gbf7dc18ff4-goog
285
+
286
+
287
+ From 23327ea30f714a6ac25f197e47764d1f8960986e Mon Sep 17 00:00:00 2001
288
+ From: Matt Leon <
[email protected] >
289
+ Date: Tue, 22 Jul 2025 10:45:41 -0400
290
+ Subject: [PATCH 3/3] Use Envoy boringssl
291
+
292
+ Signed-off-by: Matt Leon <
[email protected] >
293
+ ---
294
+ BUILD | 2 +-
295
+ 1 file changed, 1 insertion(+), 1 deletion(-)
296
+
1
297
diff --git a/BUILD b/BUILD
2
- index 69c9bda..d293092 100644
298
+ index 6db5fd9..aaf7bd2 100644
3
299
--- a/BUILD
4
300
+++ b/BUILD
5
- @@ -88 ,7 +88 ,7 @@ cc_library(
301
+ @@ -91 ,7 +91 ,7 @@ cc_library(
6
302
":headers",
7
303
] + select({
8
304
"//bazel:crypto_system": [],
@@ -11,3 +307,6 @@ index 69c9bda..d293092 100644
11
307
}),
12
308
alwayslink = 1,
13
309
)
310
+ - -
311
+ 2.50.0.727.gbf7dc18ff4-goog
312
+
0 commit comments