Skip to content

Commit 12daecc

Browse files
committed
Proxy abort back to main thread
This allows the `Module.onAbort` handler to be called. Fixes: #11345
1 parent f6b6ea0 commit 12daecc

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

src/library.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ LibraryManager.library = {
448448
// TODO: There are currently two abort() functions that get imported to asm module scope: the built-in runtime function abort(),
449449
// and this function _abort(). Remove one of these, importing two functions for the same purpose is wasteful.
450450
abort__sig: 'v',
451+
abort__proxy: 'sync',
451452
abort: function() {
452453
#if MINIMAL_RUNTIME
453454
// In MINIMAL_RUNTIME the module object does not exist, so its behavior to abort is to throw directly.

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ function abort(what) {
595595
#endif
596596

597597
#if USE_PTHREADS
598-
if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack);
598+
assert(!ENVIRONMENT_IS_PTHREAD);
599599
#endif
600600
what += '';
601601
err(what);

tests/pthread/test_pthread_abort.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2021 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
9+
int main() {
10+
abort();
11+
__builtin_unreachable();
12+
}

tests/pthread/test_pthread_abort.out

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

tests/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,12 @@ def test_pthread_setspecific_mainthread(self):
23382338
self.set_setting('EXIT_RUNTIME')
23392339
self.do_run_in_out_file_test('pthread/test_pthread_setspecific_mainthread.c')
23402340

2341+
@node_pthreads
2342+
def test_pthread_abort(self):
2343+
self.set_setting('PROXY_TO_PTHREAD')
2344+
self.add_pre_run("Module.onAbort = function() { console.log('onAbort called'); }")
2345+
self.do_run_in_out_file_test('pthread/test_pthread_abort.c', assert_returncode=NON_ZERO)
2346+
23412347
def test_tcgetattr(self):
23422348
self.do_runf(test_file('termios/test_tcgetattr.c'), 'success')
23432349

0 commit comments

Comments
 (0)