Source file
src/syscall/syscall_linux_mipsx.go
1
2
3
4
5
6
7 package syscall
8
9 import "unsafe"
10
11 const (
12 _SYS_setgroups = SYS_SETGROUPS
13 _SYS_clone3 = 4435
14 _SYS_faccessat2 = 4439
15 )
16
17 func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
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 func Fstatfs(fd int, buf *Statfs_t) (err error) {
74 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
75 if e != 0 {
76 err = errnoErr(e)
77 }
78 return
79 }
80
81 func Statfs(path string, buf *Statfs_t) (err error) {
82 p, err := BytePtrFromString(path)
83 if err != nil {
84 return err
85 }
86 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
87 if e != 0 {
88 err = errnoErr(e)
89 }
90 return
91 }
92
93 func Seek(fd int, offset int64, whence int) (off int64, err error) {
94 _, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0)
95 if e != 0 {
96 err = errnoErr(e)
97 }
98 return
99 }
100
101 func setTimespec(sec, nsec int64) Timespec {
102 return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
103 }
104
105 func setTimeval(sec, usec int64) Timeval {
106 return Timeval{Sec: int32(sec), Usec: int32(usec)}
107 }
108
109
110
111 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
112 page := uintptr(offset / 4096)
113 if offset != int64(page)*4096 {
114 return 0, EINVAL
115 }
116 return mmap2(addr, length, prot, flags, fd, page)
117 }
118
119 const rlimInf32 = ^uint32(0)
120 const rlimInf64 = ^uint64(0)
121
122 type rlimit32 struct {
123 Cur uint32
124 Max uint32
125 }
126
127
128
129 func Getrlimit(resource int, rlim *Rlimit) (err error) {
130 err = prlimit(0, resource, nil, rlim)
131 if err != ENOSYS {
132 return err
133 }
134
135 rl := rlimit32{}
136 err = getrlimit(resource, &rl)
137 if err != nil {
138 return
139 }
140
141 if rl.Cur == rlimInf32 {
142 rlim.Cur = rlimInf64
143 } else {
144 rlim.Cur = uint64(rl.Cur)
145 }
146
147 if rl.Max == rlimInf32 {
148 rlim.Max = rlimInf64
149 } else {
150 rlim.Max = uint64(rl.Max)
151 }
152 return
153 }
154
155
156
157 func setrlimit(resource int, rlim *Rlimit) (err error) {
158 err = prlimit(0, resource, rlim, nil)
159 if err != ENOSYS {
160 return err
161 }
162
163 rl := rlimit32{}
164 if rlim.Cur == rlimInf64 {
165 rl.Cur = rlimInf32
166 } else if rlim.Cur < uint64(rlimInf32) {
167 rl.Cur = uint32(rlim.Cur)
168 } else {
169 return EINVAL
170 }
171 if rlim.Max == rlimInf64 {
172 rl.Max = rlimInf32
173 } else if rlim.Max < uint64(rlimInf32) {
174 rl.Max = uint32(rlim.Max)
175 } else {
176 return EINVAL
177 }
178
179 return setrlimit1(resource, &rl)
180 }
181
182
183 func rawSetrlimit(resource int, rlim *Rlimit) Errno {
184 _, _, errno := RawSyscall6(SYS_PRLIMIT64, 0, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0, 0, 0)
185 if errno != ENOSYS {
186 return errno
187 }
188
189 rl := rlimit32{}
190 if rlim.Cur == rlimInf64 {
191 rl.Cur = rlimInf32
192 } else if rlim.Cur < uint64(rlimInf32) {
193 rl.Cur = uint32(rlim.Cur)
194 } else {
195 return EINVAL
196 }
197 if rlim.Max == rlimInf64 {
198 rl.Max = rlimInf32
199 } else if rlim.Max < uint64(rlimInf32) {
200 rl.Max = uint32(rlim.Max)
201 } else {
202 return EINVAL
203 }
204
205 _, _, errno = RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0)
206 return errno
207 }
208
209 func (r *PtraceRegs) PC() uint64 { return uint64(r.Regs[64]) }
210
211 func (r *PtraceRegs) SetPC(pc uint64) { r.Regs[64] = uint32(pc) }
212
213 func (iov *Iovec) SetLen(length int) {
214 iov.Len = uint32(length)
215 }
216
217 func (msghdr *Msghdr) SetControllen(length int) {
218 msghdr.Controllen = uint32(length)
219 }
220
221 func (cmsg *Cmsghdr) SetLen(length int) {
222 cmsg.Len = uint32(length)
223 }
224
View as plain text