2023-02-02 23:24:12 +02:00
|
|
|
# uint32_t read_rip()
|
|
|
|
.global read_rip
|
|
|
|
read_rip:
|
|
|
|
popl %eax
|
|
|
|
jmp *%eax
|
|
|
|
|
|
|
|
exit_thread_trampoline:
|
2023-03-02 01:56:09 +02:00
|
|
|
addl $4, %esp
|
|
|
|
pushl (%esp)
|
2023-02-02 23:24:12 +02:00
|
|
|
ret
|
|
|
|
|
2023-03-09 15:25:39 +02:00
|
|
|
# void start_thread(uint32_t esp, uint32_t eip)
|
2023-02-02 23:24:12 +02:00
|
|
|
.global start_thread
|
|
|
|
start_thread:
|
2023-03-09 15:25:39 +02:00
|
|
|
movl 8(%esp), %ecx
|
|
|
|
movl 4(%esp), %esp
|
2023-02-19 17:53:29 +02:00
|
|
|
movl $0, %ebp
|
2023-03-09 15:25:39 +02:00
|
|
|
pushl $exit_thread_trampoline
|
2023-02-02 23:24:12 +02:00
|
|
|
sti
|
|
|
|
jmp *%ecx
|
|
|
|
|
2023-02-19 17:53:29 +02:00
|
|
|
# void continue_thread(uint32_t rsp, uint32_t rip)
|
2023-02-02 23:24:12 +02:00
|
|
|
.global continue_thread
|
|
|
|
continue_thread:
|
2023-02-19 17:53:29 +02:00
|
|
|
movl 8(%esp), %ecx
|
2023-02-02 23:24:12 +02:00
|
|
|
movl 4(%esp), %esp
|
|
|
|
movl $0, %eax
|
2023-04-12 17:51:36 +03:00
|
|
|
jmp *%ecx
|
|
|
|
|
|
|
|
# void thread_jump_userspace(uint32_t rsp, uint32_t rip)
|
|
|
|
.global thread_jump_userspace
|
|
|
|
thread_jump_userspace:
|
|
|
|
movl $0x23, %eax
|
|
|
|
movw %ax, %ds
|
|
|
|
movw %ax, %es
|
|
|
|
movw %ax, %fs
|
|
|
|
movw %ax, %gs
|
|
|
|
|
|
|
|
movl 8(%esp), %ecx
|
|
|
|
movl 4(%esp), %esp
|
|
|
|
|
|
|
|
pushl $0x23
|
|
|
|
pushl %esp
|
|
|
|
pushfl
|
|
|
|
pushl $0x1B
|
|
|
|
pushl %ecx
|
|
|
|
iret
|