upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/cpu_emulation_test.cpp
diff options
context:
space:
mode:
authorIlyassRS <ilyassroussi2000@gmail.com>2026-11-25 19:39:50 +0100
committerIlyassRS <ilyassroussi2000@gmail.com>2026-11-25 19:39:50 +0100
commit7f56e6a50b45ea8d760d93df855b6acc04594f0c (patch)
treebfb0d8e18fec0562839cb44342c0df3982c5652f /runtime/test/cpu_emulation_test.cpp
parentb9320a118d46b24de665e30e577425c131b4a2ee (diff)
runtime: step try_clzero_loop by VirtualQuery regions and guard wraparound in cpu_emulation
Diffstat (limited to 'runtime/test/cpu_emulation_test.cpp')
-rw-r--r--runtime/test/cpu_emulation_test.cpp23
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
92void test_bits() { 97void 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 ----