Re: use of setjmp/longjmp in x86 emulator.

From: Zachary Amsden
Date: Mon Mar 01 2010 - 14:19:25 EST


On 03/01/2010 09:03 AM, Gleb Natapov wrote:
On Mon, Mar 01, 2010 at 08:39:49AM -1000, Zachary Amsden wrote:


Anything that can generate exceptions is going to need logic to
handle error cases anyway... the depth can not be that bad.
Especially if you structure it so as to optimize for tail calling.

Tail call is not what usually happens. Usually emulation goes like this:
if (check some conditions) {
queue exception A
return exception queued
}
if (check other conditions) {
queue exception B
return exception queued
}
do some emulation
try to read guest memory
if (read failed) {
queue exception C
return exception queued
}
if (read needs exit to userspace for device emulation)
return please go out and retrieve me the data

continue emulation
try to write guest memory
if (write failed) {
queue exception C
return exception queued
}
if (write needs exit to userspace for device emulation)
return please go out and process the data

emulate some more.

return emulation done

It's going to be ugly to emulate segmentation, NX and write protect support without hardware to do this checking for you, but it's just what you have to do in this slow path - tedious, fully specified emulation.

Just because it's tedious doesn't mean we need to use setjmp / longjmp. Throw / catch might be effective, but it's still pretty bizarre to do tricks like that in C.

Zach
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/