50 lines
974 B
NASM
50 lines
974 B
NASM
; TODO: maybe put it near idt.c?
|
|
global sys_exit_handler
|
|
extern printf
|
|
extern handle_syscall
|
|
sys_exit_handler:
|
|
; Сохраняем регистры Ring 3
|
|
pusha
|
|
push ds
|
|
push es
|
|
push fs
|
|
push gs
|
|
|
|
; Переключаемся на сегменты Ring 0
|
|
mov ax, 0x10 ; Селектор данных Ring 0 (gdt_data)
|
|
mov ds, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
mov gs, ax
|
|
|
|
push esp
|
|
call handle_syscall
|
|
add esp, 0x44
|
|
|
|
; Восстанавливаем сегменты Ring 3
|
|
pop gs
|
|
pop fs
|
|
pop es
|
|
pop ds
|
|
popa
|
|
|
|
; Возвращаемся в Ring 3
|
|
iret
|
|
|
|
global test_user_function
|
|
test_user_function:
|
|
nigg:
|
|
mov eax, 0xB00B1E5 ; 0xDEADBEEF
|
|
int 0x80
|
|
jmp nigg
|
|
|
|
global second_user_function
|
|
second_user_function:
|
|
heh:
|
|
mov eax, 0xFACE5EA7
|
|
int 0x80
|
|
jmp heh
|
|
|
|
section .data
|
|
sys_exit_msg: db "Returned from Ring 3", 0
|
|
syscall_debug_fmt: db "Syscall #%x, args: 0x%x 0x%x 0x%x 0x%x 0x%x", 10, 0 |