From a092f01491dbd49f28184211aff97d21c88de7d4 Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Wed, 30 May 2018 17:38:29 -0700 Subject: [PATCH] Assert blocks don't get too big --- emu/jit.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/emu/jit.c b/emu/jit.c index 1ac8df70..22c15502 100644 --- a/emu/jit.c +++ b/emu/jit.c @@ -60,13 +60,15 @@ static struct jit_block *jit_block_compile(addr_t ip, struct tlb *tlb) { while (true) { if (!gen_step32(&state, tlb)) break; - // no block should span more than 2 pages, guarantee this by stopping - // as soon as there's less space left than the maximum length of an - // x86 instruction + // no block should span more than 2 pages + // guarantee this by limiting total block size to 1 page + // guarantee that by stopping as soon as there's less space left than + // the maximum length of an x86 instruction // TODO refuse to decode instructions longer than 15 bytes if (state.ip - ip >= PAGE_SIZE - 15) break; } + assert(state.ip - ip <= PAGE_SIZE); return state.block; }