aboutsummaryrefslogtreecommitdiff
path: root/tools/shared.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-09-01 19:45:59 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-03 14:41:31 -0700
commit8f7e8962758803120bd3dcbbf059d88d1c892121 (patch)
treea2523e9031c0830f08d1ec9bf0c9f4f8af84a12d /tools/shared.py
parent976d1636b37206c06f33c7ba3cdce01ae4cd7409 (diff)
assert guards against cross-module stack leaks
Diffstat (limited to 'tools/shared.py')
-rw-r--r--tools/shared.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tools/shared.py b/tools/shared.py
index 774d95fe..aecf0799 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -717,6 +717,10 @@ class Settings2(type):
return ret
@classmethod
+ def copy(self, values):
+ self.attrs = values
+
+ @classmethod
def apply_opt_level(self, opt_level, noisy=False):
if opt_level >= 1:
self.attrs['ASM_JS'] = 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