Skip to content

Commit cc09c8b

Browse files
committed
fix: use correct index as shadowstack slot key
1 parent 382aabe commit cc09c8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6622
-2417
lines changed

src/passes/shadowstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class ShadowStackPass extends Pass {
350350
}
351351
let currentFunction = this.currentFunction;
352352
let numLocals = _BinaryenFunctionGetNumLocals(currentFunction);
353-
let slotIndex = this.noteSlot(currentFunction, numLocals + this.callSlotOffset + i);
353+
let slotIndex = this.noteSlot(currentFunction, numLocals + this.callSlotOffset + numSlots);
354354
let temp = this.getSharedTemp(currentFunction, this.ptrType);
355355
let stmts = new Array<ExpressionRef>();
356356
// t = value

tests/compiler/bindings/esm.debug.wat

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@
11471147
if
11481148
i32.const 0
11491149
i32.const 672
1150-
i32.const 378
1150+
i32.const 382
11511151
i32.const 14
11521152
call $~lib/builtins/abort
11531153
unreachable
@@ -1193,7 +1193,7 @@
11931193
if
11941194
i32.const 0
11951195
i32.const 672
1196-
i32.const 385
1196+
i32.const 389
11971197
i32.const 16
11981198
call $~lib/builtins/abort
11991199
unreachable
@@ -1226,7 +1226,7 @@
12261226
if
12271227
i32.const 0
12281228
i32.const 672
1229-
i32.const 398
1229+
i32.const 402
12301230
i32.const 5
12311231
call $~lib/builtins/abort
12321232
unreachable
@@ -1470,7 +1470,7 @@
14701470
if
14711471
i32.const 0
14721472
i32.const 672
1473-
i32.const 560
1473+
i32.const 562
14741474
i32.const 3
14751475
call $~lib/builtins/abort
14761476
unreachable
@@ -1799,7 +1799,7 @@
17991799
if
18001800
i32.const 336
18011801
i32.const 672
1802-
i32.const 459
1802+
i32.const 461
18031803
i32.const 29
18041804
call $~lib/builtins/abort
18051805
unreachable
@@ -1808,6 +1808,26 @@
18081808
call $~lib/rt/tlsf/computeSize
18091809
return
18101810
)
1811+
(func $~lib/rt/tlsf/roundSize (param $size i32) (result i32)
1812+
local.get $size
1813+
i32.const 536870910
1814+
i32.lt_u
1815+
if (result i32)
1816+
local.get $size
1817+
i32.const 1
1818+
i32.const 27
1819+
local.get $size
1820+
i32.clz
1821+
i32.sub
1822+
i32.shl
1823+
i32.add
1824+
i32.const 1
1825+
i32.sub
1826+
else
1827+
local.get $size
1828+
end
1829+
return
1830+
)
18111831
(func $~lib/rt/tlsf/searchBlock (param $root i32) (param $size i32) (result i32)
18121832
(local $fl i32)
18131833
(local $sl i32)
@@ -1837,24 +1857,13 @@
18371857
local.set $sl
18381858
else
18391859
local.get $size
1840-
i32.const 536870910
1841-
i32.lt_u
1842-
if (result i32)
1843-
local.get $size
1844-
i32.const 1
1845-
i32.const 27
1846-
local.get $size
1847-
i32.clz
1848-
i32.sub
1849-
i32.shl
1850-
i32.add
1851-
i32.const 1
1852-
i32.sub
1853-
else
1854-
local.get $size
1855-
end
1860+
call $~lib/rt/tlsf/roundSize
18561861
local.set $requestSize
1857-
i32.const 31
1862+
i32.const 4
1863+
i32.const 8
1864+
i32.mul
1865+
i32.const 1
1866+
i32.sub
18581867
local.get $requestSize
18591868
i32.clz
18601869
i32.sub
@@ -1892,7 +1901,7 @@
18921901
if
18931902
i32.const 0
18941903
i32.const 672
1895-
i32.const 330
1904+
i32.const 334
18961905
i32.const 14
18971906
call $~lib/builtins/abort
18981907
unreachable
@@ -1963,7 +1972,7 @@
19631972
if
19641973
i32.const 0
19651974
i32.const 672
1966-
i32.const 343
1975+
i32.const 347
19671976
i32.const 18
19681977
call $~lib/builtins/abort
19691978
unreachable
@@ -2026,6 +2035,14 @@
20262035
(local $pagesAfter i32)
20272036
i32.const 0
20282037
drop
2038+
local.get $size
2039+
i32.const 256
2040+
i32.ge_u
2041+
if
2042+
local.get $size
2043+
call $~lib/rt/tlsf/roundSize
2044+
local.set $size
2045+
end
20292046
memory.size $0
20302047
local.set $pagesBefore
20312048
local.get $size
@@ -2047,22 +2064,6 @@
20472064
i32.add
20482065
local.set $size
20492066
local.get $size
2050-
i32.const 536870910
2051-
i32.lt_u
2052-
if
2053-
local.get $size
2054-
i32.const 1
2055-
i32.const 27
2056-
local.get $size
2057-
i32.clz
2058-
i32.sub
2059-
i32.shl
2060-
i32.const 1
2061-
i32.sub
2062-
i32.add
2063-
local.set $size
2064-
end
2065-
local.get $size
20662067
i32.const 65535
20672068
i32.add
20682069
i32.const 65535
@@ -2128,7 +2129,7 @@
21282129
if
21292130
i32.const 0
21302131
i32.const 672
2131-
i32.const 357
2132+
i32.const 361
21322133
i32.const 14
21332134
call $~lib/builtins/abort
21342135
unreachable
@@ -2243,7 +2244,7 @@
22432244
if
22442245
i32.const 0
22452246
i32.const 672
2246-
i32.const 497
2247+
i32.const 499
22472248
i32.const 16
22482249
call $~lib/builtins/abort
22492250
unreachable
@@ -2263,7 +2264,7 @@
22632264
if
22642265
i32.const 0
22652266
i32.const 672
2266-
i32.const 499
2267+
i32.const 501
22672268
i32.const 14
22682269
call $~lib/builtins/abort
22692270
unreachable
@@ -4943,16 +4944,16 @@
49434944
(local $i|4 i32)
49444945
(local $5 i32)
49454946
global.get $~lib/memory/__stack_pointer
4946-
i32.const 12
4947+
i32.const 16
49474948
i32.sub
49484949
global.set $~lib/memory/__stack_pointer
49494950
call $~stack_check
49504951
global.get $~lib/memory/__stack_pointer
49514952
i64.const 0
49524953
i64.store $0
49534954
global.get $~lib/memory/__stack_pointer
4954-
i32.const 0
4955-
i32.store $0 offset=8
4955+
i64.const 0
4956+
i64.store $0 offset=8
49564957
global.get $~lib/memory/__stack_pointer
49574958
i32.const 0
49584959
local.get $a
@@ -4997,7 +4998,7 @@
49974998
local.set $5
49984999
global.get $~lib/memory/__stack_pointer
49995000
local.get $5
5000-
i32.store $0 offset=8
5001+
i32.store $0 offset=12
50015002
local.get $5
50025003
local.get $i
50035004
call $~lib/array/Array<~lib/string/String>#__get
@@ -5037,7 +5038,7 @@
50375038
local.set $5
50385039
global.get $~lib/memory/__stack_pointer
50395040
local.get $5
5040-
i32.store $0 offset=8
5041+
i32.store $0 offset=12
50415042
local.get $5
50425043
call $~lib/array/Array<~lib/string/String>#get:length
50435044
local.get $i|4
@@ -5046,7 +5047,7 @@
50465047
local.set $5
50475048
global.get $~lib/memory/__stack_pointer
50485049
local.get $5
5049-
i32.store $0 offset=8
5050+
i32.store $0 offset=12
50505051
local.get $5
50515052
local.get $i|4
50525053
call $~lib/array/Array<~lib/string/String>#__get
@@ -5066,7 +5067,7 @@
50665067
local.get $c
50675068
local.set $5
50685069
global.get $~lib/memory/__stack_pointer
5069-
i32.const 12
5070+
i32.const 16
50705071
i32.add
50715072
global.set $~lib/memory/__stack_pointer
50725073
local.get $5

0 commit comments

Comments
 (0)