strengthen SAFE_HEAP in malloc and on the stack

This commit is contained in:
Alon Zakai 2010-11-22 21:10:31 -08:00
Родитель 76c55fb93d
Коммит d3f5cfa7e7
2 изменённых файлов: 9 добавлений и 11 удалений

Просмотреть файл

@ -385,6 +385,10 @@ var Library = {
var now = Date.now();
IHEAP[ptr + indexes[0]] = Math.floor(now/1000); // seconds
IHEAP[ptr + indexes[1]] = Math.floor((now-1000*Math.floor(now/1000))*1000); // microseconds
#if SAFE_HEAP
SAFE_HEAP_ACCESS(ptr + indexes[0], 'i32', true);
SAFE_HEAP_ACCESS(ptr + indexes[1], 'i32', true);
#endif
return 0;
},

Просмотреть файл

@ -5,10 +5,7 @@
RuntimeGenerator = {
alloc: function(size, type) {
var ret = type + 'TOP';
// ret += '; for (var i = 0; i < ' + size + '; i++) HEAP[' + type + 'TOP+i] = 0'; // No need for typed arrays - per the spec, initialized to 0 anyhow
if (SAFE_HEAP) {
ret += '; for (var j = 0; j < ' + size + '; j++) SAFE_HEAP_CLEAR(' + type + 'TOP+j);';
}
//ret += '; for (var i = 0; i < ' + size + '; i++) HEAP[' + type + 'TOP+i] = 0'; // No need for typed arrays - per the spec, initialized to 0 anyhow
if (GUARD_MEMORY) {
ret += '; assert(' + size + ' > 0)';
}
@ -29,14 +26,11 @@ RuntimeGenerator = {
},
stackEnter: function(initial) {
if (!GUARD_MEMORY && initial === 0) return ''; // XXX Note that we don't even push the stack! This is faster, but
// means that we don't clear stack allocations done in this function
// until the parent unwinds its stack. So potentially if we are in
// a loop, we can use a lot of memory.
if (initial === 0) return ''; // XXX Note that we don't even push the stack! This is faster, but
// means that we don't clear stack allocations done in this function
// until the parent unwinds its stack. So potentially if we are in
// a loop, we can use a lot of memory.
var ret = 'var __stackBase__ = STACKTOP; STACKTOP += ' + initial;
if (SAFE_HEAP) {
ret += '; for (var i = __stackBase__; i < STACKTOP; i++) SAFE_HEAP_STORE(i, 0, null);';
}
if (GUARD_MEMORY) {
ret += '; assert(STACKTOP < STACK_MAX)';
}