remake the syscall logger

This commit is contained in:
Matheus
2023-01-02 16:19:03 -03:00
parent a5c2f96ce1
commit 41a1921e2d
2 changed files with 63 additions and 25 deletions
+41 -13
View File
@@ -100,6 +100,30 @@ func_table:
section .text
global asm_syscall_entry
%macro abi_save 0
push rax
push rdi
push rsi
push rdx
push rcx
push r8
push r9
push r10
push r11
%endmacro
%macro abi_restore 0
pop r11
pop r10
pop r9
pop r8
pop rcx
pop rdx
pop rsi
pop rdi
pop rax
%endmacro
; the registers for the system call are:
; RETURN:
; rax -> ret value
@@ -173,28 +197,32 @@ asm_syscall_entry:
.do_syscall:
; DEBUG STUFF
;mov r15,rax
; END DEBUG STUFF
abi_save
push rax
extern syscalllogger
call syscalllogger
add rsp,8
abi_restore
call [func_table + rax * 8]
push rax
push rdx
; DEBUG STUFF
;mov rsi,rdx
;mov rdi,r15
;extern syscalllogger
;call syscalllogger
mov rdi, rax
mov rsi, rdx
extern syscalllogger_return
call syscalllogger_return
extern postsyscall
call postsyscall
; DEBUG STUFF END
pop rdx
pop rax
+22 -12
View File
@@ -2,6 +2,8 @@
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include <arch/cls.h>
#include <kernel/sched.h>
static char* syscalls[] = {
"syscall_libc_log",
@@ -53,18 +55,26 @@ static char* syscalls[] = {
};
void syscalllogger(uint64_t num, uint64_t error){
void syscalllogger(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t num){
thread_t* thread = arch_getcls()->thread;
proc_t* proc = thread->proc;
char tmp[100];
sprintf(tmp, "PID %d TID %d: %s (%d): %p %p %p %p %p %p\n", proc->pid, thread->tid, syscalls[num], num, arg1, arg2, arg3, arg4, arg5, arg6);
e9_puts("syscall: ");
e9_puts(syscalls[num]);
e9_putc(':');
char err[] = {'0', '0', '0', NULL};
err[2] += error % 10;
error /= 10;
err[1] += error % 10;
error /= 10;
err[0] += error % 10;
e9_puts(err);
e9_putc('\n');
e9_puts(tmp);
}
void syscalllogger_return(uint64_t value, uint64_t errno){
char tmp[100];
thread_t* thread = arch_getcls()->thread;
proc_t* proc = thread->proc;
sprintf(tmp, "PID %d TID %d: returned %p %d\n", proc->pid, thread->tid, value, errno);
e9_puts(tmp);
}