1
2
3
4
5
6
7
8 package unix
9
10 import (
11 "unsafe"
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 func Time(t *Time_t) (tt Time_t, err error) {
55 var tv Timeval
56 err = Gettimeofday(&tv)
57 if err != nil {
58 return 0, err
59 }
60 if t != nil {
61 *t = Time_t(tv.Sec)
62 }
63 return Time_t(tv.Sec), nil
64 }
65
66
67
68
69 func setTimespec(sec, nsec int64) Timespec {
70 return Timespec{Sec: sec, Nsec: nsec}
71 }
72
73 func setTimeval(sec, usec int64) Timeval {
74 return Timeval{Sec: sec, Usec: usec}
75 }
76
77 func Ioperm(from int, num int, on int) (err error) {
78 return ENOSYS
79 }
80
81 func Iopl(level int) (err error) {
82 return ENOSYS
83 }
84
85 func (r *PtraceRegs) PC() uint64 { return r.Psw.Addr }
86
87 func (r *PtraceRegs) SetPC(pc uint64) { r.Psw.Addr = pc }
88
89 func (iov *Iovec) SetLen(length int) {
90 iov.Len = uint64(length)
91 }
92
93 func (msghdr *Msghdr) SetControllen(length int) {
94 msghdr.Controllen = uint64(length)
95 }
96
97 func (msghdr *Msghdr) SetIovlen(length int) {
98 msghdr.Iovlen = uint64(length)
99 }
100
101 func (cmsg *Cmsghdr) SetLen(length int) {
102 cmsg.Len = uint64(length)
103 }
104
105 func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
106 rsa.Service_name_len = uint64(length)
107 }
108
109
110
111 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
112 mmap_args := [6]uintptr{addr, length, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset)}
113 r0, _, e1 := Syscall(SYS_MMAP, uintptr(unsafe.Pointer(&mmap_args[0])), 0, 0)
114 xaddr = uintptr(r0)
115 if e1 != 0 {
116 err = errnoErr(e1)
117 }
118 return
119 }
120
121
122
123
124 const (
125
126 netSocket = 1
127 netBind = 2
128 netConnect = 3
129 netListen = 4
130 netAccept = 5
131 netGetSockName = 6
132 netGetPeerName = 7
133 netSocketPair = 8
134 netSend = 9
135 netRecv = 10
136 netSendTo = 11
137 netRecvFrom = 12
138 netShutdown = 13
139 netSetSockOpt = 14
140 netGetSockOpt = 15
141 netSendMsg = 16
142 netRecvMsg = 17
143 netAccept4 = 18
144 netRecvMMsg = 19
145 netSendMMsg = 20
146 )
147
148 func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) {
149 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
150 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0)
151 if err != 0 {
152 return 0, err
153 }
154 return int(fd), nil
155 }
156
157 func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) {
158 args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)}
159 fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0)
160 if err != 0 {
161 return 0, err
162 }
163 return int(fd), nil
164 }
165
166 func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
167 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
168 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetSockName, uintptr(unsafe.Pointer(&args)), 0)
169 if err != 0 {
170 return err
171 }
172 return nil
173 }
174
175 func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) error {
176 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
177 _, _, err := RawSyscall(SYS_SOCKETCALL, netGetPeerName, uintptr(unsafe.Pointer(&args)), 0)
178 if err != 0 {
179 return err
180 }
181 return nil
182 }
183
184 func socketpair(domain int, typ int, flags int, fd *[2]int32) error {
185 args := [4]uintptr{uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd))}
186 _, _, err := RawSyscall(SYS_SOCKETCALL, netSocketPair, uintptr(unsafe.Pointer(&args)), 0)
187 if err != 0 {
188 return err
189 }
190 return nil
191 }
192
193 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) error {
194 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
195 _, _, err := Syscall(SYS_SOCKETCALL, netBind, uintptr(unsafe.Pointer(&args)), 0)
196 if err != 0 {
197 return err
198 }
199 return nil
200 }
201
202 func connect(s int, addr unsafe.Pointer, addrlen _Socklen) error {
203 args := [3]uintptr{uintptr(s), uintptr(addr), uintptr(addrlen)}
204 _, _, err := Syscall(SYS_SOCKETCALL, netConnect, uintptr(unsafe.Pointer(&args)), 0)
205 if err != 0 {
206 return err
207 }
208 return nil
209 }
210
211 func socket(domain int, typ int, proto int) (int, error) {
212 args := [3]uintptr{uintptr(domain), uintptr(typ), uintptr(proto)}
213 fd, _, err := RawSyscall(SYS_SOCKETCALL, netSocket, uintptr(unsafe.Pointer(&args)), 0)
214 if err != 0 {
215 return 0, err
216 }
217 return int(fd), nil
218 }
219
220 func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) error {
221 args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen))}
222 _, _, err := Syscall(SYS_SOCKETCALL, netGetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
223 if err != 0 {
224 return err
225 }
226 return nil
227 }
228
229 func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) error {
230 args := [5]uintptr{uintptr(s), uintptr(level), uintptr(name), uintptr(val), vallen}
231 _, _, err := Syscall(SYS_SOCKETCALL, netSetSockOpt, uintptr(unsafe.Pointer(&args)), 0)
232 if err != 0 {
233 return err
234 }
235 return nil
236 }
237
238 func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (int, error) {
239 var base uintptr
240 if len(p) > 0 {
241 base = uintptr(unsafe.Pointer(&p[0]))
242 }
243 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))}
244 n, _, err := Syscall(SYS_SOCKETCALL, netRecvFrom, uintptr(unsafe.Pointer(&args)), 0)
245 if err != 0 {
246 return 0, err
247 }
248 return int(n), nil
249 }
250
251 func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) error {
252 var base uintptr
253 if len(p) > 0 {
254 base = uintptr(unsafe.Pointer(&p[0]))
255 }
256 args := [6]uintptr{uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen)}
257 _, _, err := Syscall(SYS_SOCKETCALL, netSendTo, uintptr(unsafe.Pointer(&args)), 0)
258 if err != 0 {
259 return err
260 }
261 return nil
262 }
263
264 func recvmsg(s int, msg *Msghdr, flags int) (int, error) {
265 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
266 n, _, err := Syscall(SYS_SOCKETCALL, netRecvMsg, uintptr(unsafe.Pointer(&args)), 0)
267 if err != 0 {
268 return 0, err
269 }
270 return int(n), nil
271 }
272
273 func sendmsg(s int, msg *Msghdr, flags int) (int, error) {
274 args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags)}
275 n, _, err := Syscall(SYS_SOCKETCALL, netSendMsg, uintptr(unsafe.Pointer(&args)), 0)
276 if err != 0 {
277 return 0, err
278 }
279 return int(n), nil
280 }
281
282 func Listen(s int, n int) error {
283 args := [2]uintptr{uintptr(s), uintptr(n)}
284 _, _, err := Syscall(SYS_SOCKETCALL, netListen, uintptr(unsafe.Pointer(&args)), 0)
285 if err != 0 {
286 return err
287 }
288 return nil
289 }
290
291 func Shutdown(s, how int) error {
292 args := [2]uintptr{uintptr(s), uintptr(how)}
293 _, _, err := Syscall(SYS_SOCKETCALL, netShutdown, uintptr(unsafe.Pointer(&args)), 0)
294 if err != 0 {
295 return err
296 }
297 return nil
298 }
299
300
301
302 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
303 cmdlineLen := len(cmdline)
304 if cmdlineLen > 0 {
305
306
307
308 cmdlineLen++
309 }
310 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
311 }
312
View as plain text