Update pf_gp_exceptions test
#include <openenclave/internal/tests.h>
#include "pf_gp_exceptions_t.h"
+#define MOV_INSTRUCTION_BYTES 3
+#define LGDT_INSTRUCTION_BYTES 8
+
static uint64_t faulting_address;
static uint32_t error_code;
static uint32_t exception_code;
+static uint64_t bypass_bytes;
uint64_t test_pfgp_handler(oe_exception_record_t* exception_record)
{
if (exception_record->code == OE_EXCEPTION_PAGE_FAULT)
{
- const int MOV_INSTRUCTION_BYTES = 3;
faulting_address = exception_record->faulting_address;
error_code = exception_record->error_code;
- exception_record->context->rip += MOV_INSTRUCTION_BYTES;
+ exception_record->context->rip += bypass_bytes;
exception_code = OE_EXCEPTION_PAGE_FAULT;
}
else if (exception_record->code == OE_EXCEPTION_ACCESS_VIOLATION)
{
- const int LGDT_INSTRUCTION_BYTES = 8;
faulting_address = exception_record->faulting_address;
error_code = exception_record->error_code;
- exception_record->context->rip += LGDT_INSTRUCTION_BYTES;
+ exception_record->context->rip += bypass_bytes;
exception_code = OE_EXCEPTION_ACCESS_VIOLATION;
}
else
- {
- /* Unexpected code */
- oe_abort();
- }
+ return OE_EXCEPTION_ABORT_EXECUTION;
return OE_EXCEPTION_CONTINUE_EXECUTION;
}
@@ -49,13 +48,16 @@ int enc_pf_gp_exceptions()
/* Trigger #PF */
faulting_address = 1;
- asm volatile("xor %rax, %rax\n\t"
- "mov (%rax), %rax");
- OE_TEST(faulting_address == 0);
+ bypass_bytes = MOV_INSTRUCTION_BYTES;
+ asm volatile("mov $8, %%r8\n\t"
+ "mov (%%r8), %%r8" ::
+ : "r8");
+ OE_TEST(faulting_address == 8);
OE_TEST(exception_code == OE_EXCEPTION_PAGE_FAULT);
/* Trigger #GP */
faulting_address = 1;
+ bypass_bytes = LGDT_INSTRUCTION_BYTES;
asm volatile("lgdt 0x00");
/* faulting_address should be cleared */
OE_TEST(faulting_address == 0);
