Skip to content

Commit

Permalink
#103 ret2kern restores flags correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ahmed <ahmeddan amazon ,com>
  • Loading branch information
82marbag authored and wipawel committed Oct 3, 2020
1 parent 689c2ac commit d0f08ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 4 additions & 5 deletions arch/x86/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,17 @@ END_FUNC(handle_exception)
ENTRY(usermode_call_asm)
/* FIXME: Add 32-bit support */

/* will be restored on entering back in kernel mode */
PUSHF

mov %_ASM_SP, %gs:(%rdx)

/* SS + SP */
push $__USER_DS
push %gs:(%rcx)

/* EFLAGS */
#if defined(__x86_64__)
pushfq
#else
pushf
#endif
PUSHF

orl $X86_EFLAGS_IOPL, (%_ASM_SP)

Expand Down
6 changes: 5 additions & 1 deletion common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ extern int usermode_call_asm(user_func_t fn, void *fn_arg, unsigned long ret2ker
unsigned long user_stack);

void ret2kern_handler(void) {
asm volatile("mov %%gs:(%0), %%" STR(_ASM_SP)::"r"(offsetof(percpu_t, ret2kern_sp)));
/* clang-format off */
asm volatile("mov %%gs:(%0), %%" STR(_ASM_SP) "\n"
"POPF \n"
::"r"(offsetof(percpu_t, ret2kern_sp)));
/* clang-format on */
}

int usermode_call(user_func_t fn, void *fn_arg) {
Expand Down
16 changes: 16 additions & 0 deletions include/arch/x86/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
pop %_ASM_AX
.endm

.macro PUSHF
#if defined(__x86_64__)
pushfq
#else
pushf
#endif
.endm

.macro POPF
#if defined(__x86_64__)
popfq
#else
popf
#endif
.endm

#define GLOBAL(name) \
.global name; \
name:
Expand Down

0 comments on commit d0f08ee

Please sign in to comment.