aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-28 14:38:29 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-28 14:38:29 -0700
commit0be34770addebcc0e7b21bf4fca7694cc5e00592 (patch)
tree6141394b2db296a9a04192c4142451072f36dcca
parenta8db0c66afa1a348c2d26b290faaf7b3420d7dbc (diff)
throw on writes to absolute memory addresses; fixes #451
-rw-r--r--src/jsifier.js4
-rwxr-xr-xtests/runner.py10
2 files changed, 14 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index b3c2af1d..1d18f292 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -765,6 +765,10 @@ function JSify(data, functionsOnly, givenFunctions) {
}
switch (impl) {
case VAR_NATIVIZED:
+ if (isNumber(item.ident)) {
+ // Direct write to a memory address; this may be an intentional segfault, if not, it is a bug in the source
+ return 'throw "fault on write to ' + item.ident + '";';
+ }
return item.ident + '=' + value + ';'; // We have the actual value here
break;
case VAR_EMULATED:
diff --git a/tests/runner.py b/tests/runner.py
index d6731ed5..1856016f 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2856,6 +2856,16 @@ def process(filename):
extra_emscripten_args=['-H', 'libc/time.h'])
#extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h'])
+ def test_intentional_fault(self):
+ # Some programs intentionally segfault themselves, we should compile that into a throw
+ src = r'''
+ int main () {
+ *(volatile char *)0 = 0;
+ return 0;
+ }
+ '''
+ self.do_run(src, 'fault on write to 0')
+
def test_statics(self):
# static initializers save i16 but load i8 for some reason
if Settings.SAFE_HEAP: