Wrap eip#1561
Conversation
|
Went over pretty much the entire codebase to make sure there's nothing left "untreated", the only thing that bugs me is this: v86/src/rust/cpu/instructions.rs Lines 2038 to 2052 in fc6ffc1 I mean, yes, a 32-bit jump would wrap in 16-bit mode but perhaps it's safe to assume that any sane program won't deliberately encode it, maybe we can add debug info here or something... |
|
There's two problems with this change (both sort-of pre-existing, but they need to be discussed):
And for later PRs or documentation: As we're emulating read hardware more precisely, how does should edge-cases be handled, for example:
|
The problem is that I don't think it's possible, I mean, what's stopping someone from doing mov ax, cs
dec ax
mov cs, axthus making I mean, you could theoretically check explicitly for
Wont just using Just to make sure I'm not missing something more structural... 😅
I don't know how much we can trust it as a metric (as it might fluctuate) but if you look at the running time for the CI tests in, for example #1411 (which I intentionally chose because it's not merged - so the CI logs aren't deleted, and because the changes there aren't perf related) yoy can see both PR have roughly the same run-time, so I don't think it'll impact anything. However, I'll try to remember checking it next week.
Edit: managed to do it today, ran
|
All instructions that can change cs (far jumps/calls/returns, interrupts) already bail out to interpreted mode
v86 already detects self-modifying code. It currently only logs, and it's not really used by OSes we run, but it could be implemented properly: Line 3583 in e37189a
The code we're talking about (cpu_context.rs) reads the instructions that are going to be compiled once, and then code is generated for them. Later changes to the CS offset can't affect the already generated code. |
What about pop cs
mov cs, ax ; for example
loadall? EDIT: Actually, it doesn't matter, Line 114 in e37189a
It only detects self-modifying in the same page, should ideally mark any written block and if it's being jumped into (or just "entered") bail to interpreted mode. self-modifying code is not the only problem, you also need to deal with misaligned jumps , etc Can solve this by adding something like Edit: Actually, if jumps and calls bail to interpreted mode we don't need to handle it, just need to handle self-modifying the block or entering a modified block (without jumping). But okay, when I'll have time I'll make a naive block escaping mechanism P.S. There's no need to check for 32-bit jumps in 16-bit: Lines 3086 to 3089 in e37189a v86/src/rust/cpu/instructions.rs Lines 571 to 582 in e37189a |
|
Since the self-modifying code problem is separate from the Edit: #1575 |
solves #1253
TODO:
@copy hope this is good :)