Skip to content

Commit e60f9b5

Browse files
committed
just emit a call to abort on host ops instead of aborting
sanitize ':' in names as well
1 parent 183be2f commit e60f9b5

File tree

6 files changed

+288
-2
lines changed

6 files changed

+288
-2
lines changed

src/wasm2asm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ class Wasm2AsmBuilder {
160160
// TODO: more clever name fixing, including checking we do not collide
161161
const char* str = name.str;
162162
// check the various issues, and recurse so we check the others
163-
if (strchr(str, '-')) {
163+
if (strchr(str, '-') || strchr(str, ':')) {
164164
char* mod = strdup(str);
165165
str = mod;
166166
while (*mod) {
167167
if (*mod == '-') *mod = '_';
168+
else if (*mod == ':') *mod = '_';
168169
mod++;
169170
}
170171
IString result = fromName(IString(str, false));
@@ -1557,7 +1558,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
15571558
}
15581559

15591560
Ref visitHost(Host* curr) {
1560-
abort();
1561+
return ValueBuilder::makeCall(ABORT_FUNC);
15611562
}
15621563

15631564
Ref visitNop(Nop* curr) {

test/grow_memory_abort.2asm.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
function asmFunc(global, env, buffer) {
2+
"use asm";
3+
var HEAP8 = new global.Int8Array(buffer);
4+
var HEAP16 = new global.Int16Array(buffer);
5+
var HEAP32 = new global.Int32Array(buffer);
6+
var HEAPU8 = new global.Uint8Array(buffer);
7+
var HEAPU16 = new global.Uint16Array(buffer);
8+
var HEAPU32 = new global.Uint32Array(buffer);
9+
var HEAPF32 = new global.Float32Array(buffer);
10+
var HEAPF64 = new global.Float64Array(buffer);
11+
var Math_imul = global.Math.imul;
12+
var Math_fround = global.Math.fround;
13+
var Math_abs = global.Math.abs;
14+
var Math_clz32 = global.Math.clz32;
15+
function rust__page__alloc__h2bf29ae9b5d0f320E() {
16+
var $$0 = 0, $$1 = 0, $$2 = 0, $$3 = 0, $$4 = 0, $$5 = 0, $$6 = 0, $$7 = 0, $$8 = 0, $$9 = 0, $$10 = 0, $$11 = 0, $$12 = 0, $$13 = 0, wasm2asm_i32$0 = 0;
17+
label$0 : {
18+
$$0 = HEAPU32[(0 + 12 | 0) >> 2] | 0;
19+
if (($$0 | 0) == (0 | 0)) break label$0;
20+
HEAP32[(0 + 12 | 0) >> 2] = HEAPU32[$$0 >> 2] | 0;
21+
return $$0 | 0;
22+
};
23+
$$0 = abort();
24+
abort();
25+
label$1 : {
26+
if (($$0 | 0) == (abort() | 0)) break label$1;
27+
return $$0 << 16 | 0 | 0;
28+
};
29+
wasm2asm_i32$0 = abort();
30+
return wasm2asm_i32$0 | 0;
31+
}
32+
33+
function __wasm_ctz_i32(x) {
34+
x = x | 0;
35+
var $$1 = 0, $$2 = 0, $$3 = 0, $$4 = 0, $$5 = 0, $$6 = 0, $$7 = 0, $$8 = 0, $$9 = 0, $$10 = 0;
36+
if ((x | 0) == (0 | 0)) $$9 = 32; else $$9 = 31 - Math_clz32(x ^ (x - 1 | 0) | 0) | 0;
37+
return $$9 | 0;
38+
}
39+
40+
function __wasm_popcnt_i32(x) {
41+
x = x | 0;
42+
var count = 0, $$2 = 0, $$3 = 0, $$4 = 0, $$5 = 0, $$6 = 0, $$7 = 0, $$8 = 0, $$9 = 0, $$10 = 0, $$11 = 0, $$12 = 0, $$13 = 0, $$14 = 0, $$15 = 0;
43+
count = 0;
44+
b : {
45+
l : do {
46+
$$5 = count;
47+
if ((x | 0) == (0 | 0)) break b;
48+
x = x & (x - 1 | 0) | 0;
49+
count = count + 1 | 0;
50+
continue l;
51+
break l;
52+
} while (1);
53+
};
54+
return $$5 | 0;
55+
}
56+
57+
function __wasm_rotl_i32(x, k) {
58+
x = x | 0;
59+
k = k | 0;
60+
var $$2 = 0, $$3 = 0, $$4 = 0, $$5 = 0, $$6 = 0, $$7 = 0, $$8 = 0, $$9 = 0, $$10 = 0, $$11 = 0, $$12 = 0, $$13 = 0, $$14 = 0, $$15 = 0, $$16 = 0, $$17 = 0, $$18 = 0, $$19 = 0, $$20 = 0, wasm2asm_i32$0 = 0;
61+
return ((4294967295 >>> (k & 31 | 0) | 0) & x | 0) << (k & 31 | 0) | 0 | (((4294967295 << (32 - (k & 31 | 0) | 0) | 0) & x | 0) >>> (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
62+
return wasm2asm_i32$0 | 0;
63+
}
64+
65+
function __wasm_rotr_i32(x, k) {
66+
x = x | 0;
67+
k = k | 0;
68+
var $$2 = 0, $$3 = 0, $$4 = 0, $$5 = 0, $$6 = 0, $$7 = 0, $$8 = 0, $$9 = 0, $$10 = 0, $$11 = 0, $$12 = 0, $$13 = 0, $$14 = 0, $$15 = 0, $$16 = 0, $$17 = 0, $$18 = 0, $$19 = 0, $$20 = 0, wasm2asm_i32$0 = 0;
69+
return ((4294967295 << (k & 31 | 0) | 0) & x | 0) >>> (k & 31 | 0) | 0 | (((4294967295 >>> (32 - (k & 31 | 0) | 0) | 0) & x | 0) << (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
70+
return wasm2asm_i32$0 | 0;
71+
}
72+
73+
return {
74+
rust__page__alloc__h2bf29ae9b5d0f320E: rust__page__alloc__h2bf29ae9b5d0f320E
75+
};
76+
}
77+

test/grow_memory_abort.wast

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(module
2+
(memory 1)
3+
(func $rust::page::alloc::h2bf29ae9b5d0f320E (export "rust::page::alloc::h2bf29ae9b5d0f320E") (result i32)
4+
(local $0 i32)
5+
(block $label$0
6+
(br_if $label$0
7+
(i32.eqz
8+
(tee_local $0
9+
(i32.load offset=12
10+
(i32.const 0)
11+
)
12+
)
13+
)
14+
)
15+
(i32.store offset=12
16+
(i32.const 0)
17+
(i32.load
18+
(get_local $0)
19+
)
20+
)
21+
(return
22+
(get_local $0)
23+
)
24+
)
25+
(set_local $0
26+
(current_memory)
27+
)
28+
(drop
29+
(grow_memory
30+
(i32.const 1)
31+
)
32+
)
33+
(block $label$1
34+
(br_if $label$1
35+
(i32.eq
36+
(get_local $0)
37+
(current_memory)
38+
)
39+
)
40+
(return
41+
(i32.shl
42+
(get_local $0)
43+
(i32.const 16)
44+
)
45+
)
46+
)
47+
;;@ /checkout/src/liballoc/allocator.rs:581:0
48+
(unreachable)
49+
(unreachable)
50+
)
51+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(module
2+
(type $0 (func (result i32)))
3+
(memory $0 1)
4+
(export "rust::page::alloc::h2bf29ae9b5d0f320E" (func $rust::page::alloc::h2bf29ae9b5d0f320E))
5+
(func $rust::page::alloc::h2bf29ae9b5d0f320E (; 0 ;) (type $0) (result i32)
6+
(local $0 i32)
7+
(block $label$0
8+
(br_if $label$0
9+
(i32.eqz
10+
(tee_local $0
11+
(i32.load offset=12
12+
(i32.const 0)
13+
)
14+
)
15+
)
16+
)
17+
(i32.store offset=12
18+
(i32.const 0)
19+
(i32.load
20+
(get_local $0)
21+
)
22+
)
23+
(return
24+
(get_local $0)
25+
)
26+
)
27+
(set_local $0
28+
(current_memory)
29+
)
30+
(drop
31+
(grow_memory
32+
(i32.const 1)
33+
)
34+
)
35+
(block $label$1
36+
(br_if $label$1
37+
(i32.eq
38+
(get_local $0)
39+
(current_memory)
40+
)
41+
)
42+
(return
43+
(i32.shl
44+
(get_local $0)
45+
(i32.const 16)
46+
)
47+
)
48+
)
49+
;;@ /checkout/src/liballoc/allocator.rs:581:0
50+
(unreachable)
51+
(unreachable)
52+
)
53+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(module
2+
(type $0 (func (result i32)))
3+
(memory $0 1)
4+
(export "rust::page::alloc::h2bf29ae9b5d0f320E" (func $rust::page::alloc::h2bf29ae9b5d0f320E))
5+
(func $rust::page::alloc::h2bf29ae9b5d0f320E (; 0 ;) (type $0) (result i32)
6+
(local $var$0 i32)
7+
(block $label$1
8+
(br_if $label$1
9+
(i32.eqz
10+
(tee_local $var$0
11+
(i32.load offset=12
12+
(i32.const 0)
13+
)
14+
)
15+
)
16+
)
17+
(i32.store offset=12
18+
(i32.const 0)
19+
(i32.load
20+
(get_local $var$0)
21+
)
22+
)
23+
(return
24+
(get_local $var$0)
25+
)
26+
)
27+
(set_local $var$0
28+
(current_memory)
29+
)
30+
(drop
31+
(grow_memory
32+
(i32.const 1)
33+
)
34+
)
35+
(block $label$2
36+
(br_if $label$2
37+
(i32.eq
38+
(get_local $var$0)
39+
(current_memory)
40+
)
41+
)
42+
(return
43+
(i32.shl
44+
(get_local $var$0)
45+
(i32.const 16)
46+
)
47+
)
48+
)
49+
(unreachable)
50+
)
51+
)
52+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(module
2+
(type $0 (func (result i32)))
3+
(memory $0 1)
4+
(export "rust::page::alloc::h2bf29ae9b5d0f320E" (func $0))
5+
(func $0 (; 0 ;) (type $0) (result i32)
6+
(local $var$0 i32)
7+
(block $label$1
8+
(br_if $label$1
9+
(i32.eqz
10+
(tee_local $var$0
11+
(i32.load offset=12
12+
(i32.const 0)
13+
)
14+
)
15+
)
16+
)
17+
(i32.store offset=12
18+
(i32.const 0)
19+
(i32.load
20+
(get_local $var$0)
21+
)
22+
)
23+
(return
24+
(get_local $var$0)
25+
)
26+
)
27+
(set_local $var$0
28+
(current_memory)
29+
)
30+
(drop
31+
(grow_memory
32+
(i32.const 1)
33+
)
34+
)
35+
(block $label$2
36+
(br_if $label$2
37+
(i32.eq
38+
(get_local $var$0)
39+
(current_memory)
40+
)
41+
)
42+
(return
43+
(i32.shl
44+
(get_local $var$0)
45+
(i32.const 16)
46+
)
47+
)
48+
)
49+
(unreachable)
50+
)
51+
)
52+

0 commit comments

Comments
 (0)