How can I programmatically determine in which cycle (-1, 0, 1, 2, 3) I run?

How can I programmatically determine in which cycle (-1, 0, 1, 2, 3) I start?

+3
source share
3 answers

The easiest way is to simply run the command (x86) and catch the corresponding error.

eg. (SEH, Windows, kernel mode)

bool ring_lower_0 = false;
__try
{
    __asm { <cmd> };
    ring_lower_0 = true;
}
__except( GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION )
{
    ring_lower_0 = false;
}

Notes:

cmd, is an assembler command. See Intel Architecture Reference Guides for a list of commands and their respective call levels.

Linux has a slightly different concept.

But remember that lower level virtual machines can mask the result by emulating a challenge.

(NB: The task of the virtual machine is to translate the incorrect instruction into a meaningful call)


, , , " ".

+7

, Ring 3 ( , "", ).

+3

Source: https://habr.com/ru/post/1711908/


All Articles