Skip to content

Commit 9108c9b

Browse files
committed
allow combined options to work
1 parent fbe881c commit 9108c9b

10 files changed

+180
-147
lines changed

src/runtime_asan.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,5 @@ function _asan_js_check_index(arr, index, asanFn) {
2121
const elemSize = arr.BYTES_PER_ELEMENT;
2222
asanFn(index * elemSize, elemSize);
2323
}
24-
}
25-
26-
function _asan_js_load(arr, index) {
27-
_asan_js_check_index(arr, index, ___asan_loadN);
28-
return arr[index];
29-
}
30-
31-
function _asan_js_store(arr, index, value) {
32-
_asan_js_check_index(arr, index, ___asan_storeN);
33-
return arr[index] = value;
24+
return index;
3425
}

src/runtime_safe_heap.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ function SAFE_HEAP_INDEX(arr, idx, action) {
3535
return idx;
3636
}
3737

38-
function SAFE_HEAP_LOAD(arr, idx) {
39-
return arr[SAFE_HEAP_INDEX(arr, idx, 'loading')];
40-
}
41-
42-
function SAFE_HEAP_STORE(arr, idx, value) {
43-
return arr[SAFE_HEAP_INDEX(arr, idx, 'storing')] = value;
44-
}
45-
4638
function segfault() {
4739
abort('segmentation fault');
4840
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
a = (growMemViews(), HEAP8)[SAFE_HEAP_INDEX((growMemViews(), HEAP8), x, "loading")];
2+
3+
(growMemViews(), HEAP8)[SAFE_HEAP_INDEX((growMemViews(), HEAP8), x, "storing")] = a;
4+
5+
a = (growMemViews(), HEAPU8)[SAFE_HEAP_INDEX((growMemViews(), HEAPU8), x, "loading")];
6+
7+
(growMemViews(), HEAPU8)[SAFE_HEAP_INDEX((growMemViews(), HEAPU8), x, "storing")] = a;
8+
9+
a = LE_HEAP_LOAD_I16((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAP16), x, "loading") * 2));
10+
11+
LE_HEAP_STORE_I16((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAP16), x, "storing") * 2), a);
12+
13+
a = LE_HEAP_LOAD_U16((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPU16), x, "loading") * 2));
14+
15+
LE_HEAP_STORE_U16((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPU16), x, "storing") * 2), a);
16+
17+
a = LE_HEAP_LOAD_I32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAP32), x, "loading") * 4));
18+
19+
LE_HEAP_STORE_I32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAP32), x, "storing") * 4), a);
20+
21+
a = LE_HEAP_LOAD_U32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPU32), x, "loading") * 4));
22+
23+
LE_HEAP_STORE_U32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPU32), x, "storing") * 4), a);
24+
25+
a = LE_HEAP_LOAD_F32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPF32), x, "loading") * 4));
26+
27+
LE_HEAP_STORE_F32((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPF32), x, "storing") * 4), a);
28+
29+
a = LE_HEAP_LOAD_F64((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPF64), x, "loading") * 8));
30+
31+
LE_HEAP_STORE_F64((growMemViews(), SAFE_HEAP_INDEX((growMemViews(), HEAPF64), x, "storing") * 8), a);
32+
33+
HEAP[x];
34+
35+
HeAp[x];
36+
37+
LE_ATOMICS_ADD(heap, offset, value);
38+
39+
LE_ATOMICS_AND(heap, offset, value);
40+
41+
LE_ATOMICS_COMPAREEXCHANGE(heap, offset, expected, replacement);
42+
43+
LE_ATOMICS_EXCHANGE(heap, offset, value);
44+
45+
LE_ATOMICS_LOAD(heap, offset);
46+
47+
LE_ATOMICS_OR(heap, offset, value);
48+
49+
LE_ATOMICS_SUB(heap, offset, value);
50+
51+
LE_ATOMICS_WAIT(heap, offset, value, timeout);
52+
53+
LE_ATOMICS_WAITASYNC(heap, offset, value, timeout);
54+
55+
LE_ATOMICS_XOR(heap, offset, value);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
a = HEAP8[x]; // HEAP8
2+
HEAP8[x] = a;
3+
a = HEAPU8[x]; // HEAPU8
4+
HEAPU8[x] = a;
5+
a = HEAP16[x]; // HEAP16
6+
HEAP16[x] = a;
7+
a = HEAPU16[x]; // HEAPU16
8+
HEAPU16[x] = a;
9+
a = HEAP32[x]; // HEAPI32
10+
HEAP32[x] = a;
11+
a = HEAPU32[x]; // HEAPU32
12+
HEAPU32[x] = a;
13+
a = HEAPF32[x]; // HEAPF32
14+
HEAPF32[x] = a;
15+
a = HEAPF64[x]; // HEAPF64
16+
HEAPF64[x] = a;
17+
HEAP[x]; // should not be changed
18+
HeAp[x];
19+
Atomics.add(heap, offset, value);
20+
Atomics.and(heap, offset, value);
21+
Atomics.compareExchange(heap, offset, expected, replacement);
22+
Atomics.exchange(heap, offset, value);
23+
Atomics.load(heap, offset);
24+
Atomics.or(heap, offset, value);
25+
Atomics.sub(heap, offset, value);
26+
Atomics.wait(heap, offset, value, timeout);
27+
Atomics.waitAsync(heap, offset, value, timeout);
28+
Atomics.xor(heap, offset, value);

test/js_optimizer/asanify-output.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
1-
_asan_js_store(HEAP8, x, 1);
1+
HEAP8[_asan_js_check_index(HEAP8, x, ___asan_storeN)] = 1;
22

3-
_asan_js_store(HEAP16, x, 2);
3+
HEAP16[_asan_js_check_index(HEAP16, x, ___asan_storeN)] = 2;
44

5-
_asan_js_store(HEAP32, x, 3);
5+
HEAP32[_asan_js_check_index(HEAP32, x, ___asan_storeN)] = 3;
66

7-
_asan_js_store(HEAPU8, x, 4);
7+
HEAPU8[_asan_js_check_index(HEAPU8, x, ___asan_storeN)] = 4;
88

9-
_asan_js_store(HEAPU16, x, 5);
9+
HEAPU16[_asan_js_check_index(HEAPU16, x, ___asan_storeN)] = 5;
1010

11-
_asan_js_store(HEAPU32, x, 6);
11+
HEAPU32[_asan_js_check_index(HEAPU32, x, ___asan_storeN)] = 6;
1212

13-
_asan_js_store(HEAPF32, x, 7);
13+
HEAPF32[_asan_js_check_index(HEAPF32, x, ___asan_storeN)] = 7;
1414

15-
_asan_js_store(HEAPF64, x, 8);
15+
HEAPF64[_asan_js_check_index(HEAPF64, x, ___asan_storeN)] = 8;
1616

17-
_asan_js_store(HEAP64, x, 9n);
17+
HEAP64[_asan_js_check_index(HEAP64, x, ___asan_storeN)] = 9n;
1818

19-
_asan_js_store(HEAPU64, x, 10n);
19+
HEAPU64[_asan_js_check_index(HEAPU64, x, ___asan_storeN)] = 10n;
2020

21-
a1 = _asan_js_load(HEAP8, x);
21+
a1 = HEAP8[_asan_js_check_index(HEAP8, x, ___asan_loadN)];
2222

23-
a2 = _asan_js_load(HEAP16, x);
23+
a2 = HEAP16[_asan_js_check_index(HEAP16, x, ___asan_loadN)];
2424

25-
a3 = _asan_js_load(HEAP32, x);
25+
a3 = HEAP32[_asan_js_check_index(HEAP32, x, ___asan_loadN)];
2626

27-
a4 = _asan_js_load(HEAPU8, x);
27+
a4 = HEAPU8[_asan_js_check_index(HEAPU8, x, ___asan_loadN)];
2828

29-
a5 = _asan_js_load(HEAPU16, x);
29+
a5 = HEAPU16[_asan_js_check_index(HEAPU16, x, ___asan_loadN)];
3030

31-
a6 = _asan_js_load(HEAPU32, x);
31+
a6 = HEAPU32[_asan_js_check_index(HEAPU32, x, ___asan_loadN)];
3232

33-
a7 = _asan_js_load(HEAPF32, x);
33+
a7 = HEAPF32[_asan_js_check_index(HEAPF32, x, ___asan_loadN)];
3434

35-
a8 = _asan_js_load(HEAPF64, x);
35+
a8 = HEAPF64[_asan_js_check_index(HEAPF64, x, ___asan_loadN)];
3636

37-
a9 = _asan_js_load(HEAP64, x);
37+
a9 = HEAP64[_asan_js_check_index(HEAP64, x, ___asan_loadN)];
3838

39-
a10 = _asan_js_load(HEAPU64, x);
39+
a10 = HEAPU64[_asan_js_check_index(HEAPU64, x, ___asan_loadN)];
4040

41-
foo = _asan_js_store(HEAPU8, 1337, 42);
41+
foo = HEAPU8[_asan_js_check_index(HEAPU8, 1337, ___asan_storeN)] = 42;
4242

43-
_asan_js_load(HEAP16, bar(_asan_js_load(HEAPF64, 5)));
43+
HEAP16[_asan_js_check_index(HEAP16, bar(HEAPF64[_asan_js_check_index(HEAPF64, 5, ___asan_loadN)]), ___asan_loadN)];
4444

45-
_asan_js_store(HEAPF32, x, _asan_js_load(HEAP32, y));
46-
47-
function _asan_js_load(ptr) {
48-
return HEAP8[ptr];
49-
}
45+
HEAPF32[_asan_js_check_index(HEAPF32, x, ___asan_storeN)] = HEAP32[_asan_js_check_index(HEAP32, y, ___asan_loadN)];
5046

5147
function somethingElse() {
52-
return _asan_js_load(HEAP8, ptr);
48+
return HEAP8[_asan_js_check_index(HEAP8, ptr, ___asan_loadN)];
5349
}
5450

5551
HEAP8.length;
5652

57-
_asan_js_load(HEAP8, length);
53+
HEAP8[_asan_js_check_index(HEAP8, length, ___asan_loadN)];

test/js_optimizer/asanify.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ foo = HEAPU8[1337] = 42;
2929
HEAP16[bar(HEAPF64[5])];
3030
HEAPF32[x] = HEAP32[y];
3131

32-
// Ignore the special asan functions themselves. that is, any JS memory access
33-
// will turn into a function call to _asan_js_load_1 etc., which then does
34-
// the memory access for it. It either calls into wasm to get the proper
35-
// asan-instrumented operation, or before the wasm is ready to be called into,
36-
// we must do the access in JS, unsafely. We should not instrument a heap
37-
// access in these functions, as then we'd get infinite recursion - this is
38-
// where we do actually need to still do a HEAP8[..] etc. operation without
39-
// any ASan instrumentation.
40-
function _asan_js_load(ptr) {
41-
return HEAP8[ptr];
42-
}
43-
4432
// but do handle everything else
4533
function somethingElse() {
4634
return HEAP8[ptr];

test/js_optimizer/safeHeap-output.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
1-
SAFE_HEAP_STORE(HEAP8, x, 1);
1+
HEAP8[SAFE_HEAP_INDEX(HEAP8, x, "storing")] = 1;
22

3-
SAFE_HEAP_STORE(HEAP16, x, 2);
3+
HEAP16[SAFE_HEAP_INDEX(HEAP16, x, "storing")] = 2;
44

5-
SAFE_HEAP_STORE(HEAP32, x, 3);
5+
HEAP32[SAFE_HEAP_INDEX(HEAP32, x, "storing")] = 3;
66

7-
SAFE_HEAP_STORE(HEAPU8, x, 4);
7+
HEAPU8[SAFE_HEAP_INDEX(HEAPU8, x, "storing")] = 4;
88

9-
SAFE_HEAP_STORE(HEAPU16, x, 5);
9+
HEAPU16[SAFE_HEAP_INDEX(HEAPU16, x, "storing")] = 5;
1010

11-
SAFE_HEAP_STORE(HEAPU32, x, 6);
11+
HEAPU32[SAFE_HEAP_INDEX(HEAPU32, x, "storing")] = 6;
1212

13-
SAFE_HEAP_STORE(HEAPF32, x, 7);
13+
HEAPF32[SAFE_HEAP_INDEX(HEAPF32, x, "storing")] = 7;
1414

15-
SAFE_HEAP_STORE(HEAPF64, x, 8);
15+
HEAPF64[SAFE_HEAP_INDEX(HEAPF64, x, "storing")] = 8;
1616

17-
SAFE_HEAP_STORE(HEAP64, x, 9n);
17+
HEAP64[SAFE_HEAP_INDEX(HEAP64, x, "storing")] = 9n;
1818

19-
SAFE_HEAP_STORE(HEAPU64, x, 10n);
19+
HEAPU64[SAFE_HEAP_INDEX(HEAPU64, x, "storing")] = 10n;
2020

21-
a1 = SAFE_HEAP_LOAD(HEAP8, x);
21+
a1 = HEAP8[SAFE_HEAP_INDEX(HEAP8, x, "loading")];
2222

23-
a2 = SAFE_HEAP_LOAD(HEAP16, x);
23+
a2 = HEAP16[SAFE_HEAP_INDEX(HEAP16, x, "loading")];
2424

25-
a3 = SAFE_HEAP_LOAD(HEAP32, x);
25+
a3 = HEAP32[SAFE_HEAP_INDEX(HEAP32, x, "loading")];
2626

27-
a4 = SAFE_HEAP_LOAD(HEAPU8, x);
27+
a4 = HEAPU8[SAFE_HEAP_INDEX(HEAPU8, x, "loading")];
2828

29-
a5 = SAFE_HEAP_LOAD(HEAPU16, x);
29+
a5 = HEAPU16[SAFE_HEAP_INDEX(HEAPU16, x, "loading")];
3030

31-
a6 = SAFE_HEAP_LOAD(HEAPU32, x);
31+
a6 = HEAPU32[SAFE_HEAP_INDEX(HEAPU32, x, "loading")];
3232

33-
a7 = SAFE_HEAP_LOAD(HEAPF32, x);
33+
a7 = HEAPF32[SAFE_HEAP_INDEX(HEAPF32, x, "loading")];
3434

35-
a8 = SAFE_HEAP_LOAD(HEAPF64, x);
35+
a8 = HEAPF64[SAFE_HEAP_INDEX(HEAPF64, x, "loading")];
3636

37-
a9 = SAFE_HEAP_LOAD(HEAP64, x);
37+
a9 = HEAP64[SAFE_HEAP_INDEX(HEAP64, x, "loading")];
3838

39-
a10 = SAFE_HEAP_LOAD(HEAPU64, x);
39+
a10 = HEAPU64[SAFE_HEAP_INDEX(HEAPU64, x, "loading")];
4040

41-
foo = SAFE_HEAP_STORE(HEAPU8, 1337, 42);
41+
foo = HEAPU8[SAFE_HEAP_INDEX(HEAPU8, 1337, "storing")] = 42;
4242

43-
SAFE_HEAP_LOAD(HEAP16, bar(SAFE_HEAP_LOAD(HEAPF64, 5)));
43+
HEAP16[SAFE_HEAP_INDEX(HEAP16, bar(HEAPF64[SAFE_HEAP_INDEX(HEAPF64, 5, "loading")]), "loading")];
4444

45-
SAFE_HEAP_STORE(HEAPF32, x, SAFE_HEAP_LOAD(HEAP32, y));
46-
47-
function SAFE_HEAP_FOO(ptr) {
48-
return HEAP8[ptr];
49-
}
45+
HEAPF32[SAFE_HEAP_INDEX(HEAPF32, x, "storing")] = HEAP32[SAFE_HEAP_INDEX(HEAP32, y, "loading")];
5046

5147
function somethingElse() {
52-
return SAFE_HEAP_LOAD(HEAP8, ptr);
48+
return HEAP8[SAFE_HEAP_INDEX(HEAP8, ptr, "loading")];
5349
}
5450

5551
HEAP8.length;
5652

57-
SAFE_HEAP_LOAD(HEAP8, length);
53+
HEAP8[SAFE_HEAP_INDEX(HEAP8, length, "loading")];

test/js_optimizer/safeHeap.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ foo = HEAPU8[1337] = 42;
2929
HEAP16[bar(HEAPF64[5])];
3030
HEAPF32[x] = HEAP32[y];
3131

32-
// Ignore the special functions themselves. that is, any JS memory access
33-
// will turn into a function call to _asan_js_load_1 etc., which then does
34-
// the memory access for it. It either calls into wasm to get the proper
35-
// asan-instrumented operation, or before the wasm is ready to be called into,
36-
// we must do the access in JS, unsafely. We should not instrument a heap
37-
// access in these functions, as then we'd get infinite recursion - this is
38-
// where we do actually need to still do a HEAP8[..] etc. operation without
39-
// any ASan instrumentation.
40-
function SAFE_HEAP_FOO(ptr) {
41-
return HEAP8[ptr];
42-
}
43-
4432
// but do handle everything else
4533
function somethingElse() {
4634
return HEAP8[ptr];

test/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,7 @@ def test_extern_prepost(self):
29702970
'object-literals': ([],),
29712971
'LittleEndianHeap': (['littleEndianHeap'],),
29722972
'LittleEndianGrowableHeap': (['growableHeap','littleEndianHeap'],),
2973+
'LittleEndianGrowableSafeHeap': (['safeHeap','growableHeap','littleEndianHeap'],),
29732974
})
29742975
@crossplatform
29752976
def test_js_optimizer(self, passes, filename=None):

0 commit comments

Comments
 (0)