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