55#include "asmconstants.h"
66
77#ifdef FEATURE_MAP_THUNKS_FROM_IMAGE
8-
98#define POINTER_SIZE 0x08
9+ // Since Arm64 supports 4KB, 16KB and 64KB page sizes, as the templates is only defined for 16KB page size, this cannot be used
10+ // in a general purpose Linux environment. However it CAN be used on Apple platforms, which specify that 16KB is the system standard
11+ // page size.
1012
1113#define THUNKS_MAP_SIZE 0x4000
1214
1315#define PAGE_SIZE 0x4000
1416#define PAGE_SIZE_LOG2 14
1517
1618
17- #define DATA_SLOT(stub, field, thunksPerPage , thunkTemplateName) . - (. - C_FUNC(thunkTemplateName)) + \ THUNKS_MAP_SIZE + stub##Data__##field + IN_PAGE_INDEX * STUB_THUNK_CODESIZE
19+ #define DATA_SLOT(stub, field, thunkSize , thunkTemplateName) C_FUNC(thunkTemplateName) + THUNKS_MAP_SIZE + stub##Data__##field + IN_PAGE_INDEX * thunkSize
1820
1921// ----------
2022// StubPrecode
2123// ----------
2224
2325#define STUB_PRECODE_CODESIZE 0x18 // 3 instructions, 4 bytes each (and we also have 12 bytes of padding)
2426#define STUB_PRECODE_DATASIZE 0x18 // 2 qwords + 1 byte
25- .set STUB_PRECODE_NUM_THUNKS_PER_MAPPING,(THUNKS_MAP_SIZE / STUB_PRECODE_CODESIZE)
27+ .set STUB_PRECODE_NUM_THUNKS_PER_MAPPING, (THUNKS_MAP_SIZE / STUB_PRECODE_CODESIZE)
2628
2729.macro THUNKS_BLOCK_STUB_PRECODE
2830 IN_PAGE_INDEX = 0
29- .rept STUB_PRECODE_NUM_THUNKS_PER_MAP
31+ .rept STUB_PRECODE_NUM_THUNKS_PER_MAPPING
3032
31- ldr x10, DATA_SLOT(StubPrecode, Target, STUB_PRECODE_NUM_THUNKS_PER_MAPPING , StubPrecodeCodeTemplate)
32- ldr x12, DATA_SLOT(StubPrecode, SecretParam, STUB_PRECODE_NUM_THUNKS_PER_MAPPING , StubPrecodeCodeTemplate)
33+ ldr x10, DATA_SLOT(StubPrecode, Target, STUB_PRECODE_CODESIZE , StubPrecodeCodeTemplate)
34+ ldr x12, DATA_SLOT(StubPrecode, SecretParam, STUB_PRECODE_CODESIZE , StubPrecodeCodeTemplate)
3335 br x10
3436
3537 brk 0xf000 // Stubs need to be 24-byte in size to allow for the data to be 2 pointers + 1 byte
@@ -53,18 +55,17 @@ LEAF_END_MARKED StubPrecodeCodeTemplate, _TEXT
5355#define FIXUP_PRECODE_CODESIZE 0x18 // 5 instructions, 4 bytes each (and we also have 4 bytes of padding)
5456#define FIXUP_PRECODE_DATASIZE 0x18 // 3 qwords
5557.set FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING,(THUNKS_MAP_SIZE / FIXUP_PRECODE_CODESIZE)
56- #define FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING (THUNKS_MAP_SIZE / FIXUP_PRECODE_CODESIZE)
5758
5859.macro THUNKS_BLOCK_FIXUP_PRECODE
5960 IN_PAGE_INDEX = 0
6061 .rept FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING
6162
62- ldr x11, DATA_SLOT(FixupPrecode, Target, FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING , FixupPrecodeCodeTemplate)
63+ ldr x11, DATA_SLOT(FixupPrecode, Target, FIXUP_PRECODE_CODESIZE , FixupPrecodeCodeTemplate)
6364 br x11
64- ldr x12, DATA_SLOT(FixupPrecode, MethodDesc, FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING , FixupPrecodeCodeTemplate)
65- ldr x11, DATA_SLOT(FixupPrecode, PrecodeFixupThunk, FIXUP_PRECODE_NUM_THUNKS_PER_MAPPING , FixupPrecodeCodeTemplate)
65+ ldr x12, DATA_SLOT(FixupPrecode, MethodDesc, FIXUP_PRECODE_CODESIZE , FixupPrecodeCodeTemplate)
66+ ldr x11, DATA_SLOT(FixupPrecode, PrecodeFixupThunk, FIXUP_PRECODE_CODESIZE , FixupPrecodeCodeTemplate)
6667 br x11
67- brk 0xf000 // Stubs need to be 24-byte in size to allow for the data to be 2 pointers
68+ brk 0xf000 // Stubs need to be 24-byte in size to allow for the data to be 3 pointers
6869
6970 IN_PAGE_INDEX = IN_PAGE_INDEX + 1
7071 .endr
@@ -82,23 +83,23 @@ LEAF_END_MARKED FixupPrecodeCodeTemplate, _TEXT
8283
8384#define CALLCOUNTING_CODESIZE 0x28 // 5 instructions, 4 bytes each (and we also have 4 bytes of padding)
8485#define CALLCOUNTING_DATASIZE 0x18 // 3 qwords
85- #define CALLCOUNTING_NUM_THUNKS_PER_MAPPING (THUNKS_MAP_SIZE / CALLCOUNTING_CODESIZE)
86+ .set CALLCOUNTING_NUM_THUNKS_PER_MAPPING, (THUNKS_MAP_SIZE / CALLCOUNTING_CODESIZE)
8687
8788.macro THUNKS_BLOCK_CALLCOUNTING
8889 IN_PAGE_INDEX = 0
8990 .rept CALLCOUNTING_NUM_THUNKS_PER_MAPPING
9091
91- ldr x9, DATA_SLOT(CallCountingStub, RemainingCallCountCell)
92+ ldr x9, DATA_SLOT(CallCountingStub, RemainingCallCountCell, CALLCOUNTING_CODESIZE, CallCountingStubCodeTemplate )
9293 ldrh w10, [x9]
9394 subs w10, w10, #1
9495 strh w10, [x9]
95- beq LOCAL_LABEL(CountReachedZero\IN_PAGE_INDEX)
96- ldr x9, DATA_SLOT(CallCountingStub, TargetForMethod)
96+ beq 0f
97+ ldr x9, DATA_SLOT(CallCountingStub, TargetForMethod, CALLCOUNTING_CODESIZE, CallCountingStubCodeTemplate )
9798 br x9
98- LOCAL_LABEL(CountReachedZero\IN_PAGE_INDEX) :
99- ldr x10, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
99+ 0 :
100+ ldr x10, DATA_SLOT(CallCountingStub, TargetForThresholdReached, CALLCOUNTING_CODESIZE, CallCountingStubCodeTemplate )
100101 br x10
101- brk 0xf000 // Stubs need to be 16 -byte in size to allow for the data to be 2 pointers
102+ brk 0xf000 // Stubs need to be 40 -byte in size to allow for the data to be pointer aligned
102103
103104 IN_PAGE_INDEX = IN_PAGE_INDEX + 1
104105 .endr
@@ -109,8 +110,11 @@ LOCAL_LABEL(CountReachedZero\IN_PAGE_INDEX):
109110LEAF_ENTRY CallCountingStubCodeTemplate
110111 THUNKS_BLOCK_CALLCOUNTING
111112LEAF_END_MARKED CallCountingStubCodeTemplate, _TEXT
113+ #endif
112114
113- #else
115+ #ifdef DATA_SLOT
116+ #undef DATA_SLOT
117+ #endif
114118#define DATA_SLOT(stub, field) . - (. - C_FUNC(stub##Code\STUB_PAGE_SIZE)) + \STUB_PAGE_SIZE + stub##Data__##field
115119
116120 .irp STUB_PAGE_SIZE, 16384 , 32768 , 65536
@@ -144,4 +148,3 @@ LOCAL_LABEL(CountReachedZero\STUB_PAGE_SIZE):
144148 LEAF_END_MARKED CallCountingStubCode\STUB_PAGE_SIZE
145149
146150 .endr
147- #endif
0 commit comments