assert guards against cross-module stack leaks
This commit is contained in:
Родитель
976d1636b3
Коммит
8f7e896275
|
@ -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 []
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче