Skip to content

Commit a197a6b

Browse files
authored
Allow raise to work in standalone mode. NFC (#18283)
1 parent 71ee39f commit a197a6b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

system/lib/standalone/standalone.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* found in the LICENSE file.
66
*/
77

8+
#define _GNU_SOURCE
89
#include <assert.h>
910
#include <errno.h>
11+
#include <signal.h>
1012
#include <stdlib.h>
1113
#include <string.h>
1214
#include <sys/mman.h>
@@ -219,3 +221,10 @@ static void wasi_writeln(__wasi_fd_t fd, char* buffer) {
219221
void _emscripten_out(char* text) { wasi_writeln(1, text); }
220222

221223
void _emscripten_err(char* text) { wasi_writeln(2, text); }
224+
225+
// In the non-standalone build we define this helper function in JS to avoid
226+
// signture mismatch issues.
227+
// See: https://github.com/emscripten-core/posixtestsuite/issues/6
228+
void __call_sighandler(sighandler_t handler, int sig) {
229+
handler(sig);
230+
}

test/other/test_standalone_syscalls.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <emscripten.h>
33
#include <emscripten/html5.h>
44
#include <fcntl.h>
5+
#include <signal.h>
56
#include <sys/ioctl.h>
67
#include <sys/stat.h>
78
#include <sys/types.h>
@@ -15,20 +16,30 @@ int main() {
1516
assert(fd_out == 1);
1617
int fd_err = open("/dev/stderr", 0);
1718
assert(fd_err == 2);
19+
1820
// ioctl and fcntl fail
1921
int i = ioctl(1, 0);
2022
assert(i < 0);
2123
int f = fcntl(1, 0);
2224
assert(f < 0);
25+
2326
// write to standard streams works.
2427
write(1, "hello, world!", 5);
2528
write(1, "\n", 1);
29+
2630
// emscripten_log API works
2731
emscripten_console_log("log");
2832
// warnings/errors go to stderr
2933
emscripten_console_warn("warn");
3034
emscripten_console_error("error");
3135
emscripten_console_log("log2");
36+
3237
// check we can call this, but the test doesn't check the output
3338
emscripten_get_now();
39+
40+
// This doesn't do anything because we have not handler registered, but it
41+
// verifies that `raise` can be included in the build without any non-standard
42+
// imports being generated.
43+
raise(SIGUSR1);
44+
return 0;
3445
}

test/test_other.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7850,12 +7850,12 @@ def run(args, expected):
78507850
def test_wasm_target_and_STANDALONE_WASM(self):
78517851
# STANDALONE_WASM means we never minify imports and exports.
78527852
for opts, potentially_expect_minified_exports_and_imports in (
7853-
([], False),
7853+
([], False),
78547854
(['-sSTANDALONE_WASM'], False),
7855-
(['-O2'], False),
7856-
(['-O3'], True),
7855+
(['-O2'], False),
7856+
(['-O3'], True),
78577857
(['-O3', '-sSTANDALONE_WASM'], False),
7858-
(['-Os'], True),
7858+
(['-Os'], True),
78597859
):
78607860
# targeting .wasm (without .js) means we enable STANDALONE_WASM automatically, and don't minify imports/exports
78617861
for target in ('out.js', 'out.wasm'):
@@ -7877,11 +7877,11 @@ def test_wasm_target_and_STANDALONE_WASM(self):
78777877
print(' exports', exports)
78787878
print(' imports', imports)
78797879
if expect_minified_exports_and_imports:
7880-
assert 'a' in exports_and_imports
7880+
self.assertContained('a', exports_and_imports)
78817881
else:
7882-
assert 'a' not in exports_and_imports
7882+
self.assertNotContained('a', exports_and_imports)
78837883
if standalone:
7884-
assert 'fd_write' in exports_and_imports, 'standalone mode preserves import names for WASI APIs'
7884+
self.assertContained('fd_write', exports_and_imports, 'standalone mode preserves import names for WASI APIs')
78857885
# verify the wasm runs with the JS
78867886
if target.endswith('.js'):
78877887
self.assertContained('hello, world!', self.run_js('out.js'))

0 commit comments

Comments
 (0)