Skip to content

Commit

Permalink
修复sysenter的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Dec 20, 2024
1 parent e8a04c9 commit bbcc203
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 1 addition & 3 deletions include/define/config/plos.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

#if __GNUC__ && !__clang__
# define SYSCALL_USE_INTERRPUT 1
#endif
#define SYSCALL_USE_INTERRPUT 0
8 changes: 4 additions & 4 deletions include/libc-base/asm/syscall-x86-sysenter
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"1:\n\t" \
: "=a"(rets) \
: "0"(id) \
: "memory", "cc", "ecx", "edx"); \
: "memory", "cc", "cx", "dx"); \
rets; \
})

Expand All @@ -23,7 +23,7 @@
"1:\n\t" \
: "=a"(rets) \
: "0"(id), "r"(_a1) \
: "memory", "cc", "ecx", "edx"); \
: "memory", "cc", "cx", "dx"); \
rets; \
})

Expand All @@ -40,7 +40,7 @@
"1:\n\t" \
: "=a"(rets) \
: "0"(id), "r"(_a1), "r"(_a2) \
: "memory", "cc", "ecx", "edx"); \
: "memory", "cc", "cx", "dx"); \
rets; \
})

Expand All @@ -59,7 +59,7 @@
"1:\n\t" \
: "=a"(rets) \
: "0"(id), "r"(_a1), "r"(_a2), "r"(_a3) \
: "memory", "cc", "ecx", "edx"); \
: "memory", "cc", "cx", "dx"); \
rets; \
})

Expand Down
18 changes: 14 additions & 4 deletions src/kernel/cpu/handler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ asm_inthandler: ; DON'T EDIT THE CODE BELOW!
dd 0xfffff91a, 0x13e9fc6a, 0x6afffff9, 0xf90ce9fd, 0xfe6affff, 0xfff905e9, 0xe9ff6aff, 0xfffff8fe
asm_inthandler_end: ; DON'T EDIT THE CODE ABOVE!
extern check_memory_permission, task_abort
asm_sysenter_handler:
push RING3_DS ; push ss
push ecx ; push esp
Expand All @@ -108,16 +109,25 @@ asm_sysenter_handler:
push gs
mov ecx, esi ; in sysenter, arg2 ecx replaced with esi
mov edx, edi ; in sysenter, arg3 edx replaced with edi
pusha
mov eax, dword [esp + 17 * 4]; eax <== ring3 esp
mov esi, dword [eax] ; ecx <== syscall arg4
mov edi, dword [eax + 4] ; edx <== syscall arg5
pusha ; | and arg4, arg5 replaced with ring3 [esp] [esp + 4]
mov ebx, dword [esp + 17 * 4]; ebx <== ring3 esp
push 0 ; ==================================================
push 8 ;
push ebx ;
call check_memory_permission ; If ring3 esp is not accessible, we should abort the task.
cmp eax, 0 ;
je task_abort ;
add esp, 12 ; ==================================================
mov esi, dword [ebx] ; esi <== syscall arg4 ring3 [esp]
mov edi, dword [ebx + 4] ; edi <== syscall arg5 ring3 [esp + 4]
mov dword [esp + 4], esi ; set syscall arg4 esi
mov dword [esp], edi ; set syscall arg5 edi
mov ecx, 0x36 ; arg1 <== id
mov edx, esp ; arg2 <== regs
call inthandler ; void inthandler(i32 id, regs32 * regs) __attribute__((fastcall));
popa
mov esi, ecx ; restore esi
mov edi, edx ; restore edi
pop gs
pop fs
pop es
Expand Down

0 comments on commit bbcc203

Please sign in to comment.