-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMACROS
57 lines (42 loc) · 1.53 KB
/
MACROS
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
The syscall() macro should be invoked as follows:
syscall(#,arg1,arg2,arg3,arg4,arg5,arg6)
Error checking is built into the macro. You _MUST_ define an error-handler.
If the syscall() macro is invoked without an error handler defined, the
assembler will throw an error.
You define error handlers like this:
ech(label_for_your_error_code)
; do shit
ech(other_label_for_stuff)
The error checking consists of:
or rax,rax
js @ERROR_HANDLER
So, the FLAGS are set based on the error return of the syscall, which is nice.
The arguments are loaded with 32-bit 'mov' by default.
You can change that in the following ways:
+arg : Load arg with a 64-bit 'mov'
^arg : Load arg with a 32-bit 'mov' (redundant in this usage)
^^arg : Load arg with a 16-bit 'mov'
^^^arg : Load arg with an 8-bit 'mov'
[arg] : Load arg with 'lea' (eg, "lea rdi,[arg]")
+[arg] : Dereference arg and load (eg, "mov rdi,[arg]")
^[arg]
^^[arg]
^^^[arg]
[+arg] : Discard brackets and load with 'mov' (eg, "mov rdi,arg")
[^arg] (This functionality is stupid)
[^^arg]
[^^^arg]
NULL : Make the argument NULL (Always 64-bit, eg "xor rdi,rdi")
Note that the syscall number ("#" in the example) is also expanded in this fashion
--
In our thread-based model, each thread calls mmap() to grab it's own memory,
and sets %rbp the base of that memory.
The tmalloc(symbol,$bytes) macro "reserves" space in that memory. It defines
'symbol' to be [rbp+bytes].
So, for example:
tmalloc(crap,8)
tmalloc(shit,16)
tmalloc(moreshit,32)
crap is "rbp"
shit is "rbp+8"
moreshit is "rbp+24"