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:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-28 18:53:57 +0100
committerGitHub <noreply@github.com>2026-11-28 18:53:57 +0100
commit3107c8a2a8adbbfe588c6022085bc41c4fe09a81 (patch)
tree4a4a8feb7b3b49d498b4f282cb0e0018601f89a8 /runtime/test/cpu_emulation_test.cpp
parentf139d7690a25f4efedb6a1ea1b2a607008400946 (diff)
parent7f56e6a50b45ea8d760d93df855b6acc04594f0c (diff)
Merge pull request #2035 from IlyassRS3/fix/rt-cpu-emulation-clzero-region-and-bounds
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 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
94void test_bits() { 99void 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 ----