From 6248bb9e75cb14510c577d5c98b87b07970aa5e7 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 1 Nov 2021 16:33:17 +0800 Subject: [PATCH] =?utf8?q?=E6=8D=A2=E7=A7=8D=E6=96=B9=E5=BC=8F=E5=AE=9E?= =?utf8?q?=E7=8E=B0sysc=20bad=20number?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/syscall.h | 32 +++++++++++++++----------------- kernel/syscall.S | 8 +++----- kernel/syscall.c | 7 +++++-- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/syscall.h b/include/syscall.h index 5e8bd15..59b4a83 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -36,23 +36,21 @@ int _syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigne #define syscall3(nr, a, b, c) _syscall3(nr, (unsigned long)a, (unsigned long)b, (unsigned long)c) #define syscall4(nr, a, b, c, d) _syscall4(nr, (unsigned long)a, (unsigned long)b, (unsigned long)c, (unsigned long)d) -enum -{ - SYSC_WRITE, - SYSC_REBOOT, - SYSC_FORK, - SYSC_CLONE, - SYSC_EXEC, - SYSC_WAIT, - SYSC_OPEN, - SYSC_READ, - SYSC_STAT, - SYSC_EXIT, - SYSC_PAUSE, - SYSC_TEST, - SYSC_DEBUG -}; - #endif // ASM +#define SYSC_WRITE (0) +#define SYSC_REBOOT (1) +#define SYSC_FORK (2) +#define SYSC_CLONE (3) +#define SYSC_EXEC (4) +#define SYSC_WAIT (5) +#define SYSC_OPEN (6) +#define SYSC_READ (7) +#define SYSC_STAT (8) +#define SYSC_EXIT (9) +#define SYSC_PAUSE (10) +#define SYSC_TEST (11) +#define SYSC_DEBUG (12) +#define SYSC_BAD_NR (SYSC_NUM - 1) + #endif //_SYSCALL_H diff --git a/kernel/syscall.S b/kernel/syscall.S index fdd9772..89996b8 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -48,8 +48,10 @@ syscall_entry: popl %eax cmpl $SYSC_NUM, %eax - jae bad_sysc_nr + jb .normal_syscall + mov $SYSC_BAD_NR, %eax + .normal_syscall: call *sysc_handler_table(,%eax,4) normal_syscall_exit: @@ -66,10 +68,6 @@ syscall_exit: sti /* sysenter have cleared IF, and sysexit will not set IF. */ sysexit -bad_sysc_nr: - call sysc_bad_syscnr - jmp syscall_exit - ret_from_fork_user: xorl %eax, %eax jmp normal_syscall_exit diff --git a/kernel/syscall.c b/kernel/syscall.c index ef98edb..3c11103 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -90,14 +90,17 @@ void init_sysc_handler_table() _sysc_(SYSC_PAUSE, sysc_pause); _sysc_(SYSC_TEST, sysc_test); _sysc_(SYSC_DEBUG, sysc_debug); + _sysc_(SYSC_BAD_NR, sysc_bad_nr) } -int sysc_bad_syscnr() +int sysc_bad_nr() { int sysc_nr; + asm("" : "=a"(sysc_nr)); + printk("bad syscall nr:%d\n", sysc_nr); - return 0; + return -1; } -- 2.44.0