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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use core::ffi;
use super::raw;
use super::result::{prepare_arg as arg, prepare_standard_result as mkresult, Result};
use super::types::*;
macro_rules! syscall {
($n:expr) => {
mkresult(raw::syscall0($n))
};
($n:expr, $a0:expr) => {
mkresult(raw::syscall1($n, arg($a0)))
};
($n:expr, $a0:expr, $a1:expr) => {
mkresult(raw::syscall2($n, arg($a0), arg($a1)))
};
($n:expr, $a0:expr, $a1:expr, $a2:expr) => {
mkresult(raw::syscall3($n, arg($a0), arg($a1), arg($a2)))
};
($n:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr) => {
mkresult(raw::syscall4($n, arg($a0), arg($a1), arg($a2), arg($a3)))
};
($n:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
mkresult(raw::syscall5(
$n,
arg($a0),
arg($a1),
arg($a2),
arg($a3),
arg($a4),
))
};
($n:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => {
mkresult(raw::syscall6(
$n,
arg($a0),
arg($a1),
arg($a2),
arg($a3),
arg($a4),
arg($a5),
))
};
}
#[cfg(have_syscall = "close")]
#[inline(always)]
pub unsafe fn close(fd: int) -> Result<int> {
syscall!(raw::CLOSE, fd)
}
#[cfg(have_syscall = "creat")]
#[inline(always)]
pub unsafe fn creat(pathname: *const char, mode: mode_t) -> Result<int> {
syscall!(raw::CREAT, pathname, mode)
}
#[cfg(have_syscall = "exit")]
#[inline(always)]
pub unsafe fn exit(status: int) -> ! {
raw::syscall1(raw::EXIT, arg(status));
unreachable!()
}
#[cfg(have_syscall = "exit_group")]
#[inline(always)]
pub unsafe fn exit_group(status: int) -> ! {
raw::syscall1(raw::EXIT_GROUP, arg(status));
unreachable!()
}
#[cfg(have_syscall = "getpid")]
#[inline(always)]
pub unsafe fn getpid() -> pid_t {
raw::syscall0(raw::GETPID) as pid_t
}
#[cfg(have_syscall = "open")]
#[inline(always)]
pub unsafe fn open(pathname: *const char, flags: int, mode: mode_t) -> Result<int> {
syscall!(raw::OPEN, pathname, flags, mode)
}
#[cfg(have_syscall = "poll")]
#[inline(always)]
pub unsafe fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: int) -> Result<int> {
syscall!(raw::POLL, fds, nfds, timeout)
}
#[cfg(have_syscall = "read")]
#[inline(always)]
pub unsafe fn read(fd: int, buf: *mut void, count: size_t) -> Result<ssize_t> {
syscall!(raw::READ, fd, buf, count)
}
#[cfg(have_syscall = "readv")]
#[inline(always)]
pub unsafe fn readv(fd: int, iov: *mut iovec, iovcount: int) -> Result<size_t> {
syscall!(raw::READV, fd, iov, iovcount)
}
#[cfg(have_syscall = "sync")]
#[inline(always)]
pub unsafe fn sync() {
raw::syscall0(raw::SYNC);
}
#[cfg(have_syscall = "syncfs")]
#[inline(always)]
pub unsafe fn syncfs(fd: int) -> Result<int> {
syscall!(raw::SYNCFS, fd)
}
#[cfg(have_syscall = "lseek")]
#[inline(always)]
pub unsafe fn lseek(fd: int, offset: off_t, whence: int) -> Result<off_t> {
syscall!(raw::LSEEK, fd, offset, whence)
}
#[cfg(have_syscall = "write")]
#[inline(always)]
pub unsafe fn write(fd: int, buf: *const ffi::c_void, count: size_t) -> Result<ssize_t> {
syscall!(raw::WRITE, fd, buf, count)
}
#[cfg(have_syscall = "writev")]
#[inline(always)]
pub unsafe fn writev(fd: int, iov: *const iovec, iovcount: int) -> Result<size_t> {
syscall!(raw::WRITEV, fd, iov, iovcount)
}
#[cfg(have_syscall = "_llseek")]
#[inline(always)]
pub unsafe fn _llseek(
fd: int,
offset_high: ffi::c_ulong,
offset_low: ffi::c_ulong,
result: *mut loff_t,
whence: uint,
) -> Result<int> {
syscall!(raw::_LLSEEK, fd, offset_high, offset_low, result, whence)
}