-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscalls.asm
135 lines (113 loc) · 2.04 KB
/
syscalls.asm
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;; https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/
SYS_read equ 0
SYS_write equ 1
SYS_close equ 3
SYS_socket equ 41
SYS_accept equ 43
SYS_bind equ 49
SYS_listen equ 50
SYS_setsockopt equ 54
SYS_exit equ 60
SYS_time equ 201
SOCK_STREAM equ 1
AF_INET equ 2
STDIN equ 0
STDOUT equ 1
STDERR equ 2
EXIT_SUCCESS equ 0
EXIT_FAILURE equ 1
MAX_BACKLOG equ 16
SOL_SOCKET equ 1
SO_REUSEADDR equ 2
SO_REUSEPORT equ 15
macro syscall1 nr, arg0
{
mov rax, nr
mov rdi, arg0
syscall
}
macro syscall2 nr, arg0, arg1
{
mov rax, nr
mov rdi, arg0
mov rsi, arg1
syscall
}
macro syscall3 nr, arg0, arg1, arg2
{
mov rax, nr
mov rdi, arg0
mov rsi, arg1
mov rdx, arg2
syscall
}
macro syscall4 nr, arg0, arg1, arg2, arg3
{
mov rax, nr
mov rdi, arg0
mov rsi, arg1
mov rdx, arg2
mov r10, arg3
syscall
}
macro syscall5 nr, arg0, arg1, arg2, arg3, arg4
{
mov rax, nr
mov rdi, arg0
mov rsi, arg1
mov rdx, arg2
mov r10, arg3
mov r8, arg4
syscall
}
macro syscall6 nr, arg0, arg1, arg2, arg3, arg4, arg5
{
mov rax, nr
mov rdi, arg0
mov rsi, arg1
mov rdx, arg2
mov r10, arg3
mov r8, arg4
mov r9, arg5
syscall
}
macro exit code
{
syscall1 SYS_exit, code
}
macro close fd
{
syscall1 SYS_close, fd
}
macro time tloc
{
syscall1 SYS_time, tloc
}
macro listen sockfd, backlog
{
syscall2 SYS_listen, sockfd, backlog
}
macro read fd, buf, count
{
syscall3 SYS_read, fd, buf, count
}
macro write fd, buf, count
{
syscall3 SYS_write, fd, buf, count
}
macro socket socket_family, socket_type, protocol
{
syscall3 SYS_socket, socket_family, socket_type, protocol
}
macro bind socket, address, address_len
{
syscall3 SYS_bind, socket, address, address_len
}
macro accept socket, address, address_len
{
syscall3 SYS_accept, socket, address, address_len
}
macro setsockopt fd, level, optname, optval, optlen
{
syscall5 SYS_setsockopt, fd, level, optname, optval, optlen
}