Skip to content
Merged
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
23 changes: 17 additions & 6 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,22 @@ def create_sending(metadata, library_symbols):

def make_export_wrappers(exports, delay_assignment):
wrappers = []

# The emscripten stack functions are called very early (by writeStackCookie) before
# the runtime is initialized so we can't create these wrappers that check for
# runtimeInitialized.
# Likewise `__trap` can occur before the runtime is initialized since it is used in
# abort.
# pthread_self and _emscripten_proxy_execute_task_queue are currently called in some
# cases after the runtime has exited.
# TODO: Look into removing these, and improving our robustness around thread termination.
def install_wrapper(sym):
if sym.startswith('_asan_') or sym.startswith('emscripten_stack_'):
return False
if sym in ('__trap', 'pthread_self', '_emscripten_proxy_execute_task_queue'):
return False
return True

for name in exports:
# Tags cannot be wrapped in createExportWrapper
if name == '__cpp_exception':
Expand All @@ -730,12 +746,7 @@ def make_export_wrappers(exports, delay_assignment):
exported = ''
wrapper += exported

# The emscripten stack functions are called very early (by writeStackCookie) before
# the runtime is initialized so we can't create these wrappers that check for
# runtimeInitialized.
# Likewise `__trap` can occur before the runtime is initialized since it is used in
# abort.
if settings.ASSERTIONS and not name.startswith('emscripten_stack_') and name != '__trap':
if settings.ASSERTIONS and install_wrapper(name):
# With assertions enabled we create a wrapper that are calls get routed through, for
# the lifetime of the program.
if delay_assignment:
Expand Down
11 changes: 3 additions & 8 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ var LibraryPThread = {
},

$terminateWorker: function(worker) {
#if PTHREADS_DEBUG
dbg('terminateWorker: ' + worker.workerID);
#endif
worker.terminate();
// terminate() can be asynchronous, so in theory the worker can continue
// to run for some amount of time after termination. However from our POV
Expand Down Expand Up @@ -942,15 +945,7 @@ var LibraryPThread = {
#if PROXY_TO_PTHREAD
{{{ runtimeKeepalivePop() }}};
#endif
#if MINIMAL_RUNTIME
_exit(returnCode);
#else
try {
_exit(returnCode);
} catch (e) {
handleException(e);
}
#endif
},

emscripten_proxy_to_main_thread_js__deps: ['$withStackSave', '_emscripten_run_in_main_runtime_thread_js'],
Expand Down
36 changes: 10 additions & 26 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,6 @@ var read_,
readBinary,
setWindowTitle;

#if ENVIRONMENT_MAY_BE_SHELL || ENVIRONMENT_MAY_BE_NODE || ASSERTIONS
// Normally we don't log exceptions but instead let them bubble out the top
// level where the embedding environment (e.g. the browser) can handle
// them.
// However under v8 and node we sometimes exit the process direcly in which case
// its up to use us to log the exception before exiting.
// If we fix https://github.com/emscripten-core/emscripten/issues/15080
// this may no longer be needed under node.
function logExceptionOnExit(e) {
if (e instanceof ExitStatus) return;
let toLog = e;
if (e && typeof e == 'object' && e.stack) {
toLog = [e, e.stack];
}
err('exiting due to exception: ' + toLog);
}
#endif

#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
#if ENVIRONMENT && ASSERTIONS
Expand Down Expand Up @@ -244,7 +226,7 @@ if (ENVIRONMENT_IS_NODE) {
#if RUNTIME_DEBUG
dbg('node: uncaughtException: ' + ex)
#endif
if (!(ex instanceof ExitStatus)) {
if (ex !== 'unwind' && !(ex instanceof ExitStatus) && !(ex.context instanceof ExitStatus)) {
throw ex;
}
});
Expand All @@ -263,12 +245,8 @@ if (ENVIRONMENT_IS_NODE) {
#endif

quit_ = (status, toThrow) => {
if (keepRuntimeAlive()) {
process.exitCode = status;
throw toThrow;
}
logExceptionOnExit(toThrow);
process.exit(status);
process.exitCode = status;
throw toThrow;
};

Module['inspect'] = function () { return '[Emscripten Module object]'; };
Expand Down Expand Up @@ -360,7 +338,13 @@ if (ENVIRONMENT_IS_SHELL) {
throw toThrow;
}
#endif
logExceptionOnExit(toThrow);
if (!(toThrow instanceof ExitStatus)) {
let toLog = toThrow;
if (toThrow && typeof toThrow == 'object' && toThrow.stack) {
toLog = [toThrow, toThrow.stack];
}
err('exiting due to exception: ' + toLog);
}
quit(status);
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/threadprofiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ var emscriptenThreadProfiler = {
document.body.appendChild(div);
this.threadProfilerDiv = document.getElementById('threadprofiler');
}
setInterval(function() { emscriptenThreadProfiler.updateUi() }, this.uiUpdateIntervalMsecs);
var i = setInterval(function() { emscriptenThreadProfiler.updateUi() }, this.uiUpdateIntervalMsecs);
addOnExit(() => clearInterval(i));
},

initializeNode: function initializeNode() {
addOnInit(() => {
emscriptenThreadProfiler.dumpState();
setInterval(function() { emscriptenThreadProfiler.dumpState() }, this.uiUpdateIntervalMsecs);
var i = setInterval(function() { emscriptenThreadProfiler.dumpState() }, this.uiUpdateIntervalMsecs);
addOnExit(() => clearInterval(i));
});
},

Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26171
26046
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26135
26010
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30708
30583
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25850
25725
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30708
30583
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26171
26046
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23266
23199
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8772
8555
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6204
6070
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6030
5896
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6030
5896
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5989
5855
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27883
27757
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4623
4639
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5292
5170
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5365
5238
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6217
6092
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_grow.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6561
6436
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5947
5818
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_mem_O3_standalone.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5870
5741
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5378
5256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5365
5238
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5365
5238
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19529
19563
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4901
4935
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3782
3798
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3671
3666
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3671
3666
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz-ctors.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3652
3647
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3671
3666
4 changes: 3 additions & 1 deletion test/other/test_runtime_keepalive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ int main() {
callUserCallback(() => {
out("in user callback: " + counter);
}, 0);
setTimeout(timerCallback, 0);
if (!runtimeExited) {
setTimeout(timerCallback, 0);
}
}
setTimeout(timerCallback, 0);
});
Expand Down
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
63173
62732
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38450
37786
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62525
62084