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
|
.globl _sys$syscall
_sys$syscall:
/*
hack: We load 6 args regardless of
how many we actually have. This may
load junk values, but if the syscall
doesn't use them, it's going to be
harmless.
*/
movq %rdi,%rax
/* 8(%rsp): hidden type arg */
movq 16(%rsp),%rdi
movq 24(%rsp),%rsi
movq 32(%rsp),%rdx
movq 40(%rsp),%r10
movq 48(%rsp),%r8
movq 56(%rsp),%r9
syscall
jae .success
negq %rax
.success:
ret
/*
* OSX is strange about fork, and needs an assembly wrapper.
* The fork() syscall, when called directly, returns the pid in both
* processes, which means that both parent and child think they're
* the parent.
*
* checking this involves peeking in %edx, so we need to do this in asm.
*/
.globl _sys$__osx_fork
_sys$__osx_fork:
movq $0x2000002,%rax
syscall
jae .forksuccess
negq %rax
.forksuccess:
testl %edx,%edx
jz .isparent
xorq %rax,%rax
.isparent:
ret
/*
* OSX is strange about pipe, and needs an assembly wrapper.
* The pipe() syscall returns the pipes created in eax:edx, and
* needs to copy them to the destination locations manually.
*/
.globl _sys$__osx_pipe
_sys$__osx_pipe:
movq $0x200002a,%rax
syscall
jae .pipesuccess
negq %rax
.pipesuccess:
movl %eax,(%rdi)
movl %edx,4(%rdi)
xorq %rax,%rax
ret
.globl _sys$__osx_lseek
_sys$__osx_lseek:
movq $0x20000C7,%rax
syscall
jae .lseeksuccess
negq %rax
.lseeksuccess:
shlq $32,%rdx
orq %rdx,%rax
ret
.globl _sys$__osx_gettimeofday
_sys$__osx_gettimeofday:
movq $0x2000074,%rax
syscall
jae .gettimeofdaysuccess
negq %rax
.gettimeofdaysuccess:
movq %rax, (%rdi)
movl %edx,8(%rdi)
xorq %rax,%rax
ret
|