diff --git a/emscripten.py b/emscripten.py index d4e4641c5..3b4597604 100755 --- a/emscripten.py +++ b/emscripten.py @@ -480,6 +480,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, ''' % (sig, i, args, arg_coercions, jsret)) from tools import shared + shared.Settings.copy(settings) asm_setup += '\n' + shared.JS.make_invoke(sig) + '\n' basic_funcs.append('invoke_%s' % sig) @@ -685,7 +686,7 @@ def main(args, compiler_engine, cache, jcache, relooper, temp_files, DEBUG, DEBU for setting in args.settings: name, value = setting.strip().split('=', 1) settings[name] = json.loads(value) - + # libraries libraries = args.libraries[0].split(',') if len(args.libraries) > 0 else [] diff --git a/tools/shared.py b/tools/shared.py index 774d95fe6..aecf07993 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -716,6 +716,10 @@ class Settings2(type): ret += ['-s', key + '=' + jsoned] return ret + @classmethod + def copy(self, values): + self.attrs = values + @classmethod def apply_opt_level(self, opt_level, noisy=False): if opt_level >= 1: @@ -1443,7 +1447,7 @@ class JS: args = ','.join(['a' + str(i) for i in range(1, len(sig))]) args = 'index' + (',' if args else '') + args # C++ exceptions are numbers, and longjmp is a string 'longjmp' - return '''function%s(%s) { + ret = '''function%s(%s) { try { %sModule["dynCall_%s"](%s); } catch(e) { @@ -1452,6 +1456,17 @@ class JS: } }''' % ((' invoke_' + sig) if named else '', args, 'return ' if sig[0] != 'v' else '', sig, args) + if Settings.DLOPEN_SUPPORT and Settings.ASSERTIONS: + # guard against cross-module stack leaks + ret = ret.replace(' try {', ''' var preStack = asm.stackSave(); + try { +''').replace(' }\n}', ''' } finally { + assert(asm.stackSave() == preStack); + } +}''') + + return ret + @staticmethod def align(x, by): while x % by != 0: x += 1