Skip to content

Implement ftCall_<sig> functions with non-legal signatures in emulate… #7533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def define_asmjs_import_names(imports):

function_tables_impls = make_function_tables_impls(function_table_data)
final_function_tables = '\n'.join(function_tables_impls) + '\n' + function_tables_defs

if shared.Settings.EMULATED_FUNCTION_POINTERS:
final_function_tables = (
final_function_tables
Expand Down Expand Up @@ -1332,8 +1333,21 @@ def setup_function_pointers(function_table_sigs):
else:
# otherwise, wasm emulated function pointers *without* emulated casts can just all
# into the table
table_access = "Module['wasmTable']"
table_read = table_access + '.get(x)'
if not shared.Settings.WASM_BACKEND and 'j' in sig:
legal_sig = shared.JS.legalize_sig(sig)
args = ['a%d' % i for i in range(len(legal_sig) - 1)]
full_args = ['x'] + args
call = "Module['asm']['ftCall_helper_%s'](%s)" % (sig, ', '.join (full_args));
asm_setup += '''
function ftCall_%s(%s) {
return %s;
}
''' % (sig, ', '.join(full_args), call);
# and we are done with this signature, continue
continue
else:
table_access = "Module['wasmTable']"
table_read = table_access + '.get(x)'
else:
table_access = 'FUNCTION_TABLE_' + sig
if shared.Settings.SIDE_MODULE:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,35 @@ def test_exceptions_uncaught_2(self):
'''
self.do_run(src, 'OK\n')

def test_exceptions_i64_emulated_function_pointers(self):
self.set_setting('EMULATED_FUNCTION_POINTERS', 1)
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
# needs to flush stdio streams
self.set_setting('EXIT_RUNTIME', 1)
src = r'''
#include <iostream>
#include <exception>

int64_t long_func(int64_t l) {
return l + 1;
}

int main() {
int64_t res;

try {
res = long_func(0x121212123434);
if (res == 0x121212123435)
std::cout << "OK";
} catch(std::exception) {
try {
throw;
} catch(std::exception) {}
}
}
'''
self.do_run(src, 'OK\n')

def test_exceptions_typed(self):
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
# needs to flush stdio streams
Expand Down