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