-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathamd64_syscalls.s
More file actions
executable file
·80 lines (71 loc) · 1.71 KB
/
amd64_syscalls.s
File metadata and controls
executable file
·80 lines (71 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;amd64_syscalls v2
;
;This is assembly glue to allow C programs to call syscalls without
;needing a C library to help
;
;v2 resolves the issue of needing to call 6 argument syscalls like mmap
;using an array of longs, instead, syscall6 can be called
;please note that __syscall can not be used with 6 argument syscalls
section .text
global __syscall, syscall0, syscall1, syscall2, syscall3, syscall4, syscall5, syscall6, syscall_list
syscall_list:
mov rax,rdi ;syscall number
mov rdi,[rsi] ;arg1
mov rdx,[rsi+16] ;arg3
mov r10,[rsi+24] ;arg4
mov r8,[rsi+32] ;arg5
mov r9,[rsi+40] ;arg6
mov rsi,[rsi+8] ;arg2
syscall ;
ret ;
syscall0:
mov rax,rdi ;syscall number
syscall ;
ret ;
syscall1:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
syscall ;
ret ;
syscall2:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
syscall ;
ret ;
syscall3:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
mov rdx,rcx ;arg3
syscall ;
ret ;
syscall4:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
mov rdx,rcx ;arg3
mov r10,r8 ;arg4
syscall ;
ret ;
syscall5:
__syscall:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
mov rdx,rcx ;arg3
mov r10,r8 ;arg4
mov r8,r9 ;arg5
syscall ;
ret ;
syscall6:
mov rax,rdi ;syscall number
mov rdi,rsi ;arg1
mov rsi,rdx ;arg2
mov rdx,rcx ;arg3
mov r10,r8 ;arg4
mov r8,r9 ;arg5
mov r9,[rsp+8] ;arg6
syscall ;
ret ;