diff options
Diffstat (limited to 'runtime/test/cpu_emulation_test.cpp')
| -rw-r--r-- | runtime/test/cpu_emulation_test.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/runtime/test/cpu_emulation_test.cpp b/runtime/test/cpu_emulation_test.cpp index f94f08044..cf9e756bf 100644 --- a/runtime/test/cpu_emulation_test.cpp +++ b/runtime/test/cpu_emulation_test.cpp | |||
| @@ -87,6 +87,11 @@ void test_decode() { | |||
| 87 | check(dec({0x66, 0x0F, 0xAE, 0x39}).op == ce::Op::none, "66 0F AE /7 is clflushopt"); | 87 | check(dec({0x66, 0x0F, 0xAE, 0x39}).op == ce::Op::none, "66 0F AE /7 is clflushopt"); |
| 88 | check(dec({0x66, 0x0F, 0xAE, 0x74, 0x01}).op == ce::Op::none, "a cut-off clwb is not decoded"); | 88 | check(dec({0x66, 0x0F, 0xAE, 0x74, 0x01}).op == ce::Op::none, "a cut-off clwb is not decoded"); |
| 89 | check(dec({0x0F, 0x0B}).op == ce::Op::none, "ud2 is not handled"); | 89 | check(dec({0x0F, 0x0B}).op == ce::Op::none, "ud2 is not handled"); |
| 90 | check(ce::decode(nullptr, 15).op == ce::Op::none, "null code buffer is refused"); | ||
| 91 | // 14 prefixes + 3-byte CLZERO = 17 bytes (> 15-byte architectural limit) must not decode. | ||
| 92 | check(dec({0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, | ||
| 93 | 0x0F, 0x01, 0xFC}).op == ce::Op::none, | ||
| 94 | "overlong >15-byte clzero is refused"); | ||
| 90 | } | 95 | } |
| 91 | 96 | ||
| 92 | void test_bits() { | 97 | void test_bits() { |
| @@ -195,6 +200,24 @@ void test_apply() { | |||
| 195 | "clzero loop >64 MiB second batch completes with CF=0, ZF=1, SF=0"); | 200 | "clzero loop >64 MiB second batch completes with CF=0, ZF=1, SF=0"); |
| 196 | VirtualFree(large, 0, MEM_RELEASE); | 201 | VirtualFree(large, 0, MEM_RELEASE); |
| 197 | } | 202 | } |
| 203 | |||
| 204 | // Wraparound guards: start near UINT64_MAX and full-span [0, UINT64_MAX) must not wrap total to 0 or loop. | ||
| 205 | { | ||
| 206 | c = {}; | ||
| 207 | c.Rax = UINT64_MAX - 63; // 0xFFFFFFFFFFFFFFC0 (64-byte aligned); start + 64 would wrap to 0 | ||
| 208 | c.Rdx = UINT64_MAX; | ||
| 209 | c.Rip = rip; | ||
| 210 | check(ce::try_clzero_loop(loop12, sizeof loop12, &c, &fault) == ce::ClzeroLoopResult::no_match, | ||
| 211 | "clzero loop rejects wraparound start near UINT64_MAX"); | ||
| 212 | |||
| 213 | c = {}; | ||
| 214 | c.Rax = 0; | ||
| 215 | c.Rdx = UINT64_MAX; // limit - start + 63 would wrap to 0 without kMaxBatch clamp first | ||
| 216 | c.Rip = rip; | ||
| 217 | check(ce::try_clzero_loop(loop12, sizeof loop12, &c, &fault) == ce::ClzeroLoopResult::faulted && | ||
| 218 | fault.ExceptionCode == STATUS_ACCESS_VIOLATION && fault.ExceptionInformation[1] == 0, | ||
| 219 | "clzero loop with UINT64_MAX limit faults on null page instead of wrapping total to 0"); | ||
| 220 | } | ||
| 198 | } | 221 | } |
| 199 | 222 | ||
| 200 | // ---- Running the real encodings ---- | 223 | // ---- Running the real encodings ---- |