Browse Source

change(syscall): check syscall_no in syscall.cpp

greatbridf 2 years ago
parent
commit
72448d4099
4 changed files with 7 additions and 6 deletions
  1. 0 3
      src/asm/interrupt.s
  2. 0 2
      src/kernel/interrupt.cpp
  3. 5 1
      src/kernel/syscall.cpp
  4. 2 0
      src/kinit.cpp

+ 0 - 3
src/asm/interrupt.s

@@ -185,8 +185,6 @@ irq15:
 .globl syscall_stub
 .type  syscall_stub @function
 syscall_stub:
-    cmpl $16, %eax
-    jge syscall_stub_end
     pushal
 
     # stack alignment and push *data
@@ -204,7 +202,6 @@ syscall_stub:
 .type  _syscall_stub_fork_return @function
 _syscall_stub_fork_return:
     popal
-syscall_stub_end:
     iret
 
 # parameters

+ 0 - 2
src/kernel/interrupt.cpp

@@ -10,7 +10,6 @@
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>
-#include <kernel/syscall.hpp>
 #include <kernel/vfs.hpp>
 #include <kernel/vga.hpp>
 #include <stdint.h>
@@ -53,7 +52,6 @@ void init_idt()
     SET_IDT_ENTRY_FN(14, int14, 0x08, KERNEL_INTERRUPT_GATE_TYPE);
     // system call
     SET_IDT_ENTRY_FN(0x80, syscall_stub, 0x08, USER_INTERRUPT_GATE_TYPE);
-    init_syscall();
 
     uint16_t idt_descriptor[3];
     idt_descriptor[0] = sizeof(struct IDT_entry) * 256;

+ 5 - 1
src/kernel/syscall.cpp

@@ -315,7 +315,11 @@ int _syscall_dup2(interrupt_stack* data)
 
 extern "C" void syscall_entry(interrupt_stack* data)
 {
-    int ret = syscall_handlers[data->s_regs.eax](data);
+    int syscall_no = data->s_regs.eax;
+    if (syscall_no >= SYSCALL_HANDLERS_SIZE)
+        kill_current(-1);
+
+    int ret = syscall_handlers[syscall_no](data);
 
     data->s_regs.eax = ret;
 

+ 2 - 0
src/kinit.cpp

@@ -9,6 +9,7 @@
 #include <kernel/log.hpp>
 #include <kernel/mem.h>
 #include <kernel/process.hpp>
+#include <kernel/syscall.hpp>
 #include <kernel/task.h>
 #include <kernel/tty.hpp>
 #include <kernel/vga.hpp>
@@ -112,6 +113,7 @@ extern "C" SECTION(".text.kinit") void NORETURN kernel_init(void)
     assert(ret == GB_OK);
 
     init_vfs();
+    init_syscall();
 
     kmsg("switching execution to the scheduler...\n");
     init_scheduler();