Source file
src/syscall/syscall_linux_386.go
1
2
3
4
5 package syscall
6
7 import "unsafe"
8
9 const _SYS_setgroups = SYS_SETGROUPS32
10
11 func setTimespec(sec, nsec int64) Timespec {
12 return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
13 }
14
15 func setTimeval(sec, usec int64) Timeval {
16 return Timeval{Sec: int32(sec), Usec: int32(usec)}
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 func Stat(path string, stat *Stat_t) (err error) {
52 return fstatat(_AT_FDCWD, path, stat, 0)
53 }
54
55 func Lchown(path string, uid int, gid int) (err error) {
56 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
57 }
58
59 func Lstat(path string, stat *Stat_t) (err error) {
60 return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
61 }
62
63 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
64 page := uintptr(offset / 4096)
65 if offset != int64(page)*4096 {
66 return 0, EINVAL
67 }
68 return mmap2(addr, length, prot, flags, fd, page)
69 }
70
71 type rlimit32 struct {
72 Cur uint32
73 Max uint32
74 }
75
76
77
78 const rlimInf32 = ^uint32(0)
79 const rlimInf64 = ^uint64(0)
80
81 func Getrlimit(resource int, rlim *Rlimit) (err error) {
82 err = prlimit(0, resource, nil, rlim)
83 if err != ENOSYS {
84 return err
85 }
86
87 rl := rlimit32{}
88 err = getrlimit(resource, &rl)
89 if err != nil {
90 return
91 }
92
93 if rl.Cur == rlimInf32 {
94 rlim.Cur = rlimInf64
95 } else {
96 rlim.Cur = uint64(rl.Cur)
97 }
98
99 if rl.Max == rlimInf32 {
100 rlim.Max = rlimInf64
101 } else {
102 rlim.Max = uint64(rl.Max)
103 }
104 return
105 }
106
107
108
109 func Setrlimit(resource int, rlim *Rlimit) (err error) {
110 err = prlimit(0, resource, rlim, nil)
111 if err != ENOSYS {
112 return err
113 }
114
115 rl := rlimit32{}
116 if rlim.Cur == rlimInf64 {
117 rl.Cur = rlimInf32
118 } else if rlim.Cur < uint64(rlimInf32) {
119 rl.Cur = uint32(rlim.Cur)
120 } else {
121 return EINVAL
122 }
123 if rlim.Max == rlimInf64 {
124 rl.Max = rlimInf32
125 } else if rlim.Max < uint64(rlimInf32) {
126 rl.Max = uint32(rlim.Max)
127 } else {
128 return EINVAL
129 }
130
131 return setrlimit(resource, &rl)
132 }
133
134
135
136 func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)
137
138 func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
139 newoffset, errno := seek(fd, offset, whence)
140 if errno != 0 {
141 return 0, errno
142 }
143 return newoffset, nil
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 const (
160
161 _SOCKET = 1
162 _BIND = 2
163 _CONNECT = 3
164 _LISTEN = 4
165 _ACCEPT = 5
166 _GETSOCKNAME = 6
167 _GETPEERNAME = 7
168 _SOCKETPAIR = 8
169 _SEND = 9
170 _RECV = 10
171 _SENDTO = 11
172 _RECVFROM = 12
173 _SHUTDOWN = 13
174 _SETSOCKOPT = 14
175 _GETSOCKOPT = 15
176 _SENDMSG = 16
177 _RECVMSG = 17
178 _ACCEPT4 = 18
179 _RECVMMSG = 19
180 _SENDMMSG = 20
181 )
182
183 func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
184 func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err Errno)
185
186 func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
187 fd, e := socketcall(_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
188 if e != 0 {
189 err = e
190 }
191 return
192 }
193
194 func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
195 fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
196 if e != 0 {
197 err = e
198 }
199 return
200 }
201
202 func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
203 _, e := rawsocketcall(_GETSOCKNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
204 if e != 0 {
205 err = e
206 }
207 return
208 }
209
210 func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) {
211 _, e := rawsocketcall(_GETPEERNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
212 if e != 0 {
213 err = e
214 }
215 return
216 }
217
218 func socketpair(domain int, typ int, flags int, fd *[2]int32) (err error) {
219 _, e := rawsocketcall(_SOCKETPAIR, uintptr(domain), uintptr(typ), uintptr(flags), uintptr(unsafe.Pointer(fd)), 0, 0)
220 if e != 0 {
221 err = e
222 }
223 return
224 }
225
226 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
227 _, e := socketcall(_BIND, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
228 if e != 0 {
229 err = e
230 }
231 return
232 }
233
234 func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
235 _, e := socketcall(_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
236 if e != 0 {
237 err = e
238 }
239 return
240 }
241
242 func socket(domain int, typ int, proto int) (fd int, err error) {
243 fd, e := rawsocketcall(_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto), 0, 0, 0)
244 if e != 0 {
245 err = e
246 }
247 return
248 }
249
250 func getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) {
251 _, e := socketcall(_GETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(unsafe.Pointer(vallen)), 0)
252 if e != 0 {
253 err = e
254 }
255 return
256 }
257
258 func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) {
259 _, e := socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), vallen, 0)
260 if e != 0 {
261 err = e
262 }
263 return
264 }
265
266 func recvfrom(s int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) {
267 var base uintptr
268 if len(p) > 0 {
269 base = uintptr(unsafe.Pointer(&p[0]))
270 }
271 n, e := socketcall(_RECVFROM, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)))
272 if e != 0 {
273 err = e
274 }
275 return
276 }
277
278 func sendto(s int, p []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) {
279 var base uintptr
280 if len(p) > 0 {
281 base = uintptr(unsafe.Pointer(&p[0]))
282 }
283 _, e := socketcall(_SENDTO, uintptr(s), base, uintptr(len(p)), uintptr(flags), uintptr(to), uintptr(addrlen))
284 if e != 0 {
285 err = e
286 }
287 return
288 }
289
290 func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) {
291 n, e := socketcall(_RECVMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
292 if e != 0 {
293 err = e
294 }
295 return
296 }
297
298 func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) {
299 n, e := socketcall(_SENDMSG, uintptr(s), uintptr(unsafe.Pointer(msg)), uintptr(flags), 0, 0, 0)
300 if e != 0 {
301 err = e
302 }
303 return
304 }
305
306 func Listen(s int, n int) (err error) {
307 _, e := socketcall(_LISTEN, uintptr(s), uintptr(n), 0, 0, 0, 0)
308 if e != 0 {
309 err = e
310 }
311 return
312 }
313
314 func Shutdown(s, how int) (err error) {
315 _, e := socketcall(_SHUTDOWN, uintptr(s), uintptr(how), 0, 0, 0, 0)
316 if e != 0 {
317 err = e
318 }
319 return
320 }
321
322 func Fstatfs(fd int, buf *Statfs_t) (err error) {
323 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
324 if e != 0 {
325 err = e
326 }
327 return
328 }
329
330 func Statfs(path string, buf *Statfs_t) (err error) {
331 pathp, err := BytePtrFromString(path)
332 if err != nil {
333 return err
334 }
335 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
336 if e != 0 {
337 err = e
338 }
339 return
340 }
341
342 func (r *PtraceRegs) PC() uint64 { return uint64(uint32(r.Eip)) }
343
344 func (r *PtraceRegs) SetPC(pc uint64) { r.Eip = int32(pc) }
345
346 func (iov *Iovec) SetLen(length int) {
347 iov.Len = uint32(length)
348 }
349
350 func (msghdr *Msghdr) SetControllen(length int) {
351 msghdr.Controllen = uint32(length)
352 }
353
354 func (cmsg *Cmsghdr) SetLen(length int) {
355 cmsg.Len = uint32(length)
356 }
357
358 func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno)
359
View as plain text