Skip to content

Commit 123b0e6

Browse files
committed
Merge branch 'main' of github.com:emscripten-core/emscripten
2 parents bb13071 + 02264e0 commit 123b0e6

21 files changed

+248
-120
lines changed

src/lib/libcore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,8 @@ function wrapSyscallFunction(x, library, isWasi) {
25592559
post += "}\n";
25602560
post += "dbg(`syscall return: ${ret}`);\n";
25612561
post += "return ret;\n";
2562+
// Emit dependency to strError() since we added use of it above.
2563+
library[x + '__deps'].push('$strError');
25622564
#endif
25632565
delete library[x + '__nothrow'];
25642566
var handler = '';

src/lib/libpthread.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ var LibraryPThread = {
241241
worker.onmessage = (e) => {
242242
var d = e['data'];
243243
var cmd = d.cmd;
244+
#if PTHREADS_DEBUG
245+
dbg(`main thread: received message '${cmd}' from worker. ${d}`);
246+
#endif
244247

245248
// If this message is intended to a recipient that is not the main
246249
// thread, forward it to the target thread.
@@ -283,6 +286,13 @@ var LibraryPThread = {
283286
// Worker wants to postMessage() to itself to implement setImmediate()
284287
// emulation.
285288
worker.postMessage(d);
289+
#if ENVIRONMENT_MAY_BE_NODE
290+
} else if (cmd === 'uncaughtException') {
291+
// Message handler for Node.js specific out-of-order behavior:
292+
// https://github.com/nodejs/node/issues/59617
293+
// A pthread sent an uncaught exception event. Re-raise it on the main thread.
294+
worker.onerror(d.error);
295+
#endif
286296
} else if (cmd === 'callHandler') {
287297
Module[d.handler](...d.args);
288298
} else if (cmd) {
@@ -308,6 +318,13 @@ var LibraryPThread = {
308318
if (ENVIRONMENT_IS_NODE) {
309319
worker.on('message', (data) => worker.onmessage({ data: data }));
310320
worker.on('error', (e) => worker.onerror(e));
321+
322+
#if PTHREADS_DEBUG
323+
worker.on('exit', (code) => {
324+
if (worker.pthread_ptr) dbg(`Worker hosting pthread ${ptrToString(worker.pthread_ptr)} has terminated with code ${code}.`);
325+
else dbg(`Worker has terminated with code ${code}.`);
326+
});
327+
#endif
311328
}
312329
#endif
313330

src/lib/libsyscall.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ var SyscallsLibrary = {
99
#if FILESYSTEM && SYSCALLS_REQUIRE_FILESYSTEM
1010
'$PATH',
1111
'$FS',
12-
#endif
13-
#if SYSCALL_DEBUG
14-
'$strError',
1512
#endif
1613
],
1714
$SYSCALLS: {

src/runtime_common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ if (ENVIRONMENT_IS_NODE && {{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
4040
self: global,
4141
postMessage: (msg) => parentPort['postMessage'](msg),
4242
});
43+
// Node.js Workers do not pass postMessage()s and uncaught exception events to the parent
44+
// thread necessarily in the same order where they were generated in sequential program order.
45+
// See https://github.com/nodejs/node/issues/59617
46+
// To remedy this, capture all uncaughtExceptions in the Worker, and sequentialize those over
47+
// to the same postMessage pipe that other messages use.
48+
process.on("uncaughtException", (err) => {
49+
#if PTHREADS_DEBUG
50+
dbg(`uncaughtException on worker thread: ${err.message}`);
51+
#endif
52+
postMessage({ cmd: 'uncaughtException', error: err });
53+
// Also shut down the Worker to match the same semantics as if this uncaughtException
54+
// handler was not registered.
55+
// (n.b. this will not shut down the whole Node.js app process, but just the Worker)
56+
process.exit(1);
57+
});
4358
}
4459
#endif // (PTHREADS || WASM_WORKERS) && (ENVIRONMENT_MAY_BE_NODE && !WASM_ESM_INTEGRATION)
4560

system/lib/libc/musl/src/errno/__strerror.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ E(ENOLCK, "No locks available")
7171

7272
E(EDEADLK, "Resource deadlock would occur")
7373
E(ENOTRECOVERABLE, "State not recoverable")
74+
#if defined(__EMSCRIPTEN__)
75+
E(EOWNERDEAD, "Owner died")
76+
#else
7477
E(EOWNERDEAD, "Previous owner died")
78+
#endif
7579
E(ECANCELED, "Operation canceled")
7680
E(ENOSYS, "Function not implemented")
7781
E(ENOMSG, "No message of desired type")

test/clang_native.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414

1515

1616
def get_native_triple():
17+
# On Raspberry Pi 5, the target triple for native compilation must exactly
18+
# match 'aarch64-linux-gnu', or clang will not find the native sysroot.
19+
# Users on a Pi 5 can set environment variable
20+
# EMTEST_NATIVE_COMPILATION_TRIPLE=aarch64-linux-gnu
21+
# to be able to override the native triple for Pi 5 compilation.
22+
native_compilation_triple = os.getenv('EMTEST_NATIVE_COMPILATION_TRIPLE')
23+
if native_compilation_triple:
24+
return native_compilation_triple
25+
1726
arch = {
1827
'aarch64': 'arm64',
1928
'arm64': 'arm64',

test/code_size/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"a.out.js": 246640,
3-
"a.out.nodebug.wasm": 597720,
4-
"total": 844360,
3+
"a.out.nodebug.wasm": 597718,
4+
"total": 844358,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

test/code_size/test_codesize_minimal_pthreads.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 7499,
3-
"a.out.js.gz": 3721,
2+
"a.out.js": 7649,
3+
"a.out.js.gz": 3768,
44
"a.out.nodebug.wasm": 19588,
55
"a.out.nodebug.wasm.gz": 9025,
6-
"total": 27087,
7-
"total_gz": 12746,
6+
"total": 27237,
7+
"total_gz": 12793,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/code_size/test_codesize_minimal_pthreads_memgrowth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 7926,
3-
"a.out.js.gz": 3924,
2+
"a.out.js": 8076,
3+
"a.out.js.gz": 3974,
44
"a.out.nodebug.wasm": 19589,
55
"a.out.nodebug.wasm.gz": 9025,
6-
"total": 27515,
7-
"total_gz": 12949,
6+
"total": 27665,
7+
"total_gz": 12999,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/code_size/test_minimal_runtime_code_size_hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 321,
44
"a.js": 4437,
55
"a.js.gz": 2281,
6-
"a.wasm": 8290,
7-
"a.wasm.gz": 5639,
8-
"total": 13181,
9-
"total_gz": 8241
6+
"a.wasm": 8299,
7+
"a.wasm.gz": 5645,
8+
"total": 13190,
9+
"total_gz": 8247
1010
}

0 commit comments

Comments
 (0)