Skip to content

Commit e1eb85d

Browse files
committed
Add expected output for Windows
1 parent a322ad4 commit e1eb85d

File tree

3 files changed

+456
-0
lines changed

3 files changed

+456
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
void
2+
emit_shim(
3+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
4+
const _PyUOpInstruction *instruction, jit_state *state)
5+
{
6+
// 0000000000000000 <_JIT_ENTRY>:
7+
// 0: 6db63bef stp d15, d14, [sp, #-0xa0]!
8+
// 4: a90857f6 stp x22, x21, [sp, #0x80]
9+
// 8: aa0103f5 mov x21, x1
10+
// c: aa0203f6 mov x22, x2
11+
// 10: a9094ff4 stp x20, x19, [sp, #0x90]
12+
// 14: aa0003f4 mov x20, x0
13+
// 18: 6d0133ed stp d13, d12, [sp, #0x10]
14+
// 1c: 6d022beb stp d11, d10, [sp, #0x20]
15+
// 20: 6d0323e9 stp d9, d8, [sp, #0x30]
16+
// 24: f90023fe str x30, [sp, #0x40]
17+
// 28: a9056ffc stp x28, x27, [sp, #0x50]
18+
// 2c: a90667fa stp x26, x25, [sp, #0x60]
19+
// 30: a9075ff8 stp x24, x23, [sp, #0x70]
20+
// 34: 9400000c bl 0x64 <_JIT_ENTRY+0x64>
21+
// 38: a9494ff4 ldp x20, x19, [sp, #0x90]
22+
// 3c: f94023fe ldr x30, [sp, #0x40]
23+
// 40: a94857f6 ldp x22, x21, [sp, #0x80]
24+
// 44: a9475ff8 ldp x24, x23, [sp, #0x70]
25+
// 48: a94667fa ldp x26, x25, [sp, #0x60]
26+
// 4c: a9456ffc ldp x28, x27, [sp, #0x50]
27+
// 50: 6d4323e9 ldp d9, d8, [sp, #0x30]
28+
// 54: 6d422beb ldp d11, d10, [sp, #0x20]
29+
// 58: 6d4133ed ldp d13, d12, [sp, #0x10]
30+
// 5c: 6cca3bef ldp d15, d14, [sp], #0xa0
31+
// 60: d65f03c0 ret
32+
const unsigned char code_body[100] = {
33+
0xef, 0x3b, 0xb6, 0x6d, 0xf6, 0x57, 0x08, 0xa9,
34+
0xf5, 0x03, 0x01, 0xaa, 0xf6, 0x03, 0x02, 0xaa,
35+
0xf4, 0x4f, 0x09, 0xa9, 0xf4, 0x03, 0x00, 0xaa,
36+
0xed, 0x33, 0x01, 0x6d, 0xeb, 0x2b, 0x02, 0x6d,
37+
0xe9, 0x23, 0x03, 0x6d, 0xfe, 0x23, 0x00, 0xf9,
38+
0xfc, 0x6f, 0x05, 0xa9, 0xfa, 0x67, 0x06, 0xa9,
39+
0xf8, 0x5f, 0x07, 0xa9, 0x0c, 0x00, 0x00, 0x94,
40+
0xf4, 0x4f, 0x49, 0xa9, 0xfe, 0x23, 0x40, 0xf9,
41+
0xf6, 0x57, 0x48, 0xa9, 0xf8, 0x5f, 0x47, 0xa9,
42+
0xfa, 0x67, 0x46, 0xa9, 0xfc, 0x6f, 0x45, 0xa9,
43+
0xe9, 0x23, 0x43, 0x6d, 0xeb, 0x2b, 0x42, 0x6d,
44+
0xed, 0x33, 0x41, 0x6d, 0xef, 0x3b, 0xca, 0x6c,
45+
0xc0, 0x03, 0x5f, 0xd6,
46+
};
47+
memcpy(code, code_body, sizeof(code_body));
48+
}
49+
50+
void
51+
emit_0(
52+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
53+
const _PyUOpInstruction *instruction, jit_state *state)
54+
{
55+
}
56+
57+
void
58+
emit_1(
59+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
60+
const _PyUOpInstruction *instruction, jit_state *state)
61+
{
62+
// 0000000000000000 <_JIT_ENTRY>:
63+
// 0: f81f0ffe str x30, [sp, #-0x10]!
64+
// 4: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
65+
// 0000000000000004: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_sausage
66+
// 8: f9400108 ldr x8, [x8]
67+
// 0000000000000008: IMAGE_REL_ARM64_PAGEOFFSET_12L __imp_sausage
68+
// c: 39400108 ldrb w8, [x8]
69+
// 10: 36000088 tbz w8, #0x0, 0x20 <_JIT_ENTRY+0x20>
70+
// 14: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
71+
// 0000000000000014: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_order_eggs_sausage_and_bacon
72+
// 18: f9400108 ldr x8, [x8]
73+
// 0000000000000018: IMAGE_REL_ARM64_PAGEOFFSET_12L __imp_order_eggs_sausage_and_bacon
74+
// 1c: 14000003 b 0x28 <_JIT_ENTRY+0x28>
75+
// 20: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
76+
// 0000000000000020: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_order_eggs_and_bacon
77+
// 24: f9400108 ldr x8, [x8]
78+
// 0000000000000024: IMAGE_REL_ARM64_PAGEOFFSET_12L __imp_order_eggs_and_bacon
79+
// 28: d63f0100 blr x8
80+
// 2c: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
81+
// 000000000000002c: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_spammed
82+
// 30: f9400108 ldr x8, [x8]
83+
// 0000000000000030: IMAGE_REL_ARM64_PAGEOFFSET_12L __imp_spammed
84+
// 34: 3900011f strb wzr, [x8]
85+
// 38: f84107fe ldr x30, [sp], #0x10
86+
const unsigned char code_body[60] = {
87+
0xfe, 0x0f, 0x1f, 0xf8, 0x08, 0x00, 0x00, 0x90,
88+
0x08, 0x01, 0x40, 0xf9, 0x08, 0x01, 0x40, 0x39,
89+
0x88, 0x00, 0x00, 0x36, 0x08, 0x00, 0x00, 0x90,
90+
0x08, 0x01, 0x40, 0xf9, 0x03, 0x00, 0x00, 0x14,
91+
0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9,
92+
0x00, 0x01, 0x3f, 0xd6, 0x08, 0x00, 0x00, 0x90,
93+
0x08, 0x01, 0x40, 0xf9, 0x1f, 0x01, 0x00, 0x39,
94+
0xfe, 0x07, 0x41, 0xf8,
95+
};
96+
// 0: &sausage+0x0
97+
// 8: &order_eggs_sausage_and_bacon+0x0
98+
// 10: &order_eggs_and_bacon+0x0
99+
// 18: &spammed+0x0
100+
patch_64(data + 0x0, (uintptr_t)&sausage);
101+
patch_64(data + 0x8, (uintptr_t)&order_eggs_sausage_and_bacon);
102+
patch_64(data + 0x10, (uintptr_t)&order_eggs_and_bacon);
103+
patch_64(data + 0x18, (uintptr_t)&spammed);
104+
memcpy(code, code_body, sizeof(code_body));
105+
patch_aarch64_33rx(code + 0x4, (uintptr_t)data);
106+
patch_aarch64_33rx(code + 0x14, (uintptr_t)data + 0x8);
107+
patch_aarch64_33rx(code + 0x20, (uintptr_t)data + 0x10);
108+
patch_aarch64_33rx(code + 0x2c, (uintptr_t)data + 0x18);
109+
}
110+
111+
void
112+
emit_2(
113+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
114+
const _PyUOpInstruction *instruction, jit_state *state)
115+
{
116+
// 0000000000000000 <_JIT_ENTRY>:
117+
// 0: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
118+
// 0000000000000000: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_spam
119+
// 4: f9400108 ldr x8, [x8]
120+
// 0000000000000004: IMAGE_REL_ARM64_PAGEOFFSET_12L __imp_spam
121+
// 8: 39400108 ldrb w8, [x8]
122+
// c: 7100051f cmp w8, #0x1
123+
// 10: 54000041 b.ne 0x18 <_JIT_ENTRY+0x18>
124+
// 14: 14000000 b 0x14 <_JIT_ENTRY+0x14>
125+
// 0000000000000014: IMAGE_REL_ARM64_BRANCH26 _JIT_ERROR_TARGET
126+
const unsigned char code_body[24] = {
127+
0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9,
128+
0x08, 0x01, 0x40, 0x39, 0x1f, 0x05, 0x00, 0x71,
129+
0x41, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x14,
130+
};
131+
// 0: &spam+0x0
132+
patch_64(data + 0x0, (uintptr_t)&spam);
133+
memcpy(code, code_body, sizeof(code_body));
134+
patch_aarch64_33rx(code + 0x0, (uintptr_t)data);
135+
patch_aarch64_26r(code + 0x14, state->instruction_starts[instruction->error_target]);
136+
}
137+
138+
static_assert(SYMBOL_MASK_WORDS >= 1, "SYMBOL_MASK_WORDS too small");
139+
140+
typedef struct {
141+
void (*emit)(
142+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
143+
const _PyUOpInstruction *instruction, jit_state *state);
144+
size_t code_size;
145+
size_t data_size;
146+
symbol_mask trampoline_mask;
147+
} StencilGroup;
148+
149+
static const StencilGroup shim = {emit_shim, 100, 0, {0}};
150+
151+
static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {
152+
[0] = {emit_0, 0, 0, {0}},
153+
[1] = {emit_1, 60, 32, {0}},
154+
[2] = {emit_2, 24, 8, {0}},
155+
};
156+
157+
static const void * const symbols_map[1] = {
158+
0
159+
};
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
void
2+
emit_shim(
3+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
4+
const _PyUOpInstruction *instruction, jit_state *state)
5+
{
6+
}
7+
8+
void
9+
emit_0(
10+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
11+
const _PyUOpInstruction *instruction, jit_state *state)
12+
{
13+
// 00000000 <__JIT_ENTRY>:
14+
// 0: 8b 44 24 0c movl 0xc(%esp), %eax
15+
// 4: 8b 4c 24 08 movl 0x8(%esp), %ecx
16+
// 8: 8b 54 24 04 movl 0x4(%esp), %edx
17+
// c: 89 54 24 04 movl %edx, 0x4(%esp)
18+
// 10: 89 4c 24 08 movl %ecx, 0x8(%esp)
19+
// 14: 89 44 24 0c movl %eax, 0xc(%esp)
20+
const unsigned char code_body[24] = {
21+
0x8b, 0x44, 0x24, 0x0c, 0x8b, 0x4c, 0x24, 0x08,
22+
0x8b, 0x54, 0x24, 0x04, 0x89, 0x54, 0x24, 0x04,
23+
0x89, 0x4c, 0x24, 0x08, 0x89, 0x44, 0x24, 0x0c,
24+
};
25+
memcpy(code, code_body, sizeof(code_body));
26+
}
27+
28+
void
29+
emit_1(
30+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
31+
const _PyUOpInstruction *instruction, jit_state *state)
32+
{
33+
// 00000000 <__JIT_ENTRY>:
34+
// 0: 53 pushl %ebx
35+
// 1: 57 pushl %edi
36+
// 2: 56 pushl %esi
37+
// 3: 8b 74 24 18 movl 0x18(%esp), %esi
38+
// 7: 8b 7c 24 14 movl 0x14(%esp), %edi
39+
// b: 8b 5c 24 10 movl 0x10(%esp), %ebx
40+
// f: 80 3d 00 00 00 00 00 cmpb $0x0, 0x0
41+
// 00000011: IMAGE_REL_I386_DIR32 _sausage
42+
// 16: 74 07 je 0x1f <__JIT_ENTRY+0x1f>
43+
// 18: e8 00 00 00 00 calll 0x1d <__JIT_ENTRY+0x1d>
44+
// 00000019: IMAGE_REL_I386_REL32 _order_eggs_sausage_and_bacon
45+
// 1d: eb 05 jmp 0x24 <__JIT_ENTRY+0x24>
46+
// 1f: e8 00 00 00 00 calll 0x24 <__JIT_ENTRY+0x24>
47+
// 00000020: IMAGE_REL_I386_REL32 _order_eggs_and_bacon
48+
// 24: c6 05 00 00 00 00 00 movb $0x0, 0x0
49+
// 00000026: IMAGE_REL_I386_DIR32 _spammed
50+
// 2b: 89 5c 24 10 movl %ebx, 0x10(%esp)
51+
// 2f: 89 7c 24 14 movl %edi, 0x14(%esp)
52+
// 33: 89 74 24 18 movl %esi, 0x18(%esp)
53+
// 37: 5e popl %esi
54+
// 38: 5f popl %edi
55+
// 39: 5b popl %ebx
56+
const unsigned char code_body[58] = {
57+
0x53, 0x57, 0x56, 0x8b, 0x74, 0x24, 0x18, 0x8b,
58+
0x7c, 0x24, 0x14, 0x8b, 0x5c, 0x24, 0x10, 0x80,
59+
0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x07,
60+
0xe8, 0x00, 0x00, 0x00, 0x00, 0xeb, 0x05, 0xe8,
61+
0x00, 0x00, 0x00, 0x00, 0xc6, 0x05, 0x00, 0x00,
62+
0x00, 0x00, 0x00, 0x89, 0x5c, 0x24, 0x10, 0x89,
63+
0x7c, 0x24, 0x14, 0x89, 0x74, 0x24, 0x18, 0x5e,
64+
0x5f, 0x5b,
65+
};
66+
memcpy(code, code_body, sizeof(code_body));
67+
patch_32(code + 0x11, (uintptr_t)&sausage);
68+
patch_x86_64_32rx(code + 0x19, (uintptr_t)&order_eggs_sausage_and_bacon + -0x4);
69+
patch_x86_64_32rx(code + 0x20, (uintptr_t)&order_eggs_and_bacon + -0x4);
70+
patch_32(code + 0x26, (uintptr_t)&spammed);
71+
}
72+
73+
void
74+
emit_2(
75+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
76+
const _PyUOpInstruction *instruction, jit_state *state)
77+
{
78+
// 00000000 <__JIT_ENTRY>:
79+
// 0: 8b 54 24 0c movl 0xc(%esp), %edx
80+
// 4: 8b 4c 24 08 movl 0x8(%esp), %ecx
81+
// 8: 8b 44 24 04 movl 0x4(%esp), %eax
82+
// c: 80 3d 00 00 00 00 01 cmpb $0x1, 0x0
83+
// 0000000e: IMAGE_REL_I386_DIR32 _spam
84+
// 13: 75 11 jne 0x26 <__JIT_ENTRY+0x26>
85+
// 15: 89 54 24 0c movl %edx, 0xc(%esp)
86+
// 19: 89 4c 24 08 movl %ecx, 0x8(%esp)
87+
// 1d: 89 44 24 04 movl %eax, 0x4(%esp)
88+
// 21: e9 00 00 00 00 jmp 0x26 <__JIT_ENTRY+0x26>
89+
// 00000022: IMAGE_REL_I386_REL32 __JIT_ERROR_TARGET
90+
// 26: 89 54 24 0c movl %edx, 0xc(%esp)
91+
// 2a: 89 4c 24 08 movl %ecx, 0x8(%esp)
92+
// 2e: 89 44 24 04 movl %eax, 0x4(%esp)
93+
const unsigned char code_body[50] = {
94+
0x8b, 0x54, 0x24, 0x0c, 0x8b, 0x4c, 0x24, 0x08,
95+
0x8b, 0x44, 0x24, 0x04, 0x80, 0x3d, 0x00, 0x00,
96+
0x00, 0x00, 0x01, 0x75, 0x11, 0x89, 0x54, 0x24,
97+
0x0c, 0x89, 0x4c, 0x24, 0x08, 0x89, 0x44, 0x24,
98+
0x04, 0xe9, 0x00, 0x00, 0x00, 0x00, 0x89, 0x54,
99+
0x24, 0x0c, 0x89, 0x4c, 0x24, 0x08, 0x89, 0x44,
100+
0x24, 0x04,
101+
};
102+
memcpy(code, code_body, sizeof(code_body));
103+
patch_32(code + 0xe, (uintptr_t)&spam);
104+
patch_x86_64_32rx(code + 0x22, state->instruction_starts[instruction->error_target] + -0x4);
105+
}
106+
107+
static_assert(SYMBOL_MASK_WORDS >= 1, "SYMBOL_MASK_WORDS too small");
108+
109+
typedef struct {
110+
void (*emit)(
111+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
112+
const _PyUOpInstruction *instruction, jit_state *state);
113+
size_t code_size;
114+
size_t data_size;
115+
symbol_mask trampoline_mask;
116+
} StencilGroup;
117+
118+
static const StencilGroup shim = {emit_shim, 0, 0, {0}};
119+
120+
static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {
121+
[0] = {emit_0, 24, 0, {0}},
122+
[1] = {emit_1, 58, 0, {0}},
123+
[2] = {emit_2, 50, 0, {0}},
124+
};
125+
126+
static const void * const symbols_map[1] = {
127+
0
128+
};

0 commit comments

Comments
 (0)