Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Nirjhar Roy <nirjhar.roy@fortanix.com>
  • Loading branch information
NirjharRoyiitk committed Mar 13, 2023
1 parent 3b8547f commit fffa97f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
9 changes: 2 additions & 7 deletions common/src/arch/x86_64/cpu.c
@@ -1,11 +1,9 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2022 Fortnanix Inc
/* Copyright (C) 2022 Fortanix Inc
* Nirjhar Roy <nirjhar.roy@fortanix.com>
*/

/* This file contains functions that check various features and flags
* specific to x86
*/
/* This file contains functions that check various features and flags specific to x86 */

#include <stddef.h>

Expand All @@ -31,9 +29,6 @@ bool is_x86_instr_legacy_prefix(uint8_t op) {
0x66, /* Operand-size override prefix */
/* Group 3 */
0x67, /* Address-size override prefix */
/* The rest of the prefixes aren't really applicable
* for the instruction(s) we are checking.
*/
};
for (size_t i = 0; i < ARRAY_SIZE(prefix_list); i++) {
if (op == prefix_list[i])
Expand Down
12 changes: 5 additions & 7 deletions libos/src/bookkeep/libos_signal.c
Expand Up @@ -479,13 +479,11 @@ static bool is_in_out(PAL_CONTEXT* context) {
}

static bool maybe_raise_sigsegv(PAL_CONTEXT* context) {
/* Executing I/O instructions (e.g., in/out) inside an SGX enclave
* generates a #UD fault. Gramine's PAL tries to handle this exception and
* propogates it to LibOS/app as a SIGILL signal.
*
* However, I/O instructions result in a #GP fault (which raises a SIGSEGV
* signal) if I/O is not permitted. Let Gramine emulate these instructions
* as if they end up in SIGSEGV. This helps some apps, e.g. `lscpu`.
/* Executing I/O instructions (e.g., in/out) inside an SGX enclave generates a #UD fault.
* Gramine's PAL tries to handle this exception and propogates it to LibOS/app as a SIGILL
* signal. However, I/O instructions result in a #GP fault (which raises a SIGSEGV signal) if
* I/O is not permitted. Let Gramine emulate these instructions as if they end up in SIGSEGV.
* This helps some apps, e.g. `lscpu`.
*/
return is_in_out(context);
}
Expand Down
24 changes: 11 additions & 13 deletions libos/test/regression/in_out_instruction_test.c
@@ -1,6 +1,5 @@
/* Test description: this test verifies that in and out instructions
* correctly generate SIGSEGV. This raises SIGSEGV once for IN and once for OUT
* and then counts if number of SIGSEGVs are 2.
/* Test description: this test verifies that in and out instructions correctly generate SIGSEGV.
* This raises SIGSEGV once for IN and once for OUT and then counts if number of SIGSEGVs is 2.
*/
#define _XOPEN_SOURCE 700
#define _POSIX_C_SOURCE 200809
Expand All @@ -26,21 +25,20 @@ static void fault_handler(int signum) {
int main(void) {
struct sigaction int_handler = {.sa_handler=fault_handler,
.sa_flags = SA_RESTART};
int value = 0;
int port = 0;
sigaction(SIGSEGV, &int_handler, 0);
unsigned char value = 0;
unsigned short port = 0x3F8;
CHECK(sigaction(SIGSEGV, &int_handler, NULL));
if (sigsetjmp(g_point, 1) == 0) {
__asm__ volatile("in %1, %0" : "=a"(value) : "d"(port));
__asm__ volatile("inb %1, %0" : "=a"(value) : "d"(port));
}
puts("handled IN instruction");
if (sigsetjmp(g_point, 1) == 0) {
port = 0;
__asm__ volatile("out %0, %1" : "=a"(value) : "d"(port));
__asm__ volatile("outb %0, %1" : : "a"(value), "d"(port));
}
puts("handled OUT instruction");
if (g_sigsegv_triggered == EXPECTED_NUM_SIGSEGVS)
puts("SIGSEGV TEST OK");
else
puts("SIGSEGV TEST FAILED");
if (g_sigsegv_triggered != EXPECTED_NUM_SIGSEGVS)
errx(1, "Expected %d number of SIGSEGVs, but got only %d", EXPECTED_NUM_SIGSEGVS,
g_sigsegv_triggered);
puts("SIGSEGV TEST OK");
return 0;
}

0 comments on commit fffa97f

Please sign in to comment.