Source file src/syscall/syscall_nacl.go
1
2
3
4
5 package syscall
6
7 import (
8 "internal/oserror"
9 "sync"
10 "unsafe"
11 )
12
13
14
15
16
17
18
19 const direntSize = 8 + 8 + 2 + 256
20
21
22 type Dirent struct {
23 Ino int64
24 Off int64
25 Reclen uint16
26 Name [256]byte
27 }
28
29 func direntIno(buf []byte) (uint64, bool) {
30 return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
31 }
32
33 func direntReclen(buf []byte) (uint64, bool) {
34 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
35 }
36
37 func direntNamlen(buf []byte) (uint64, bool) {
38 reclen, ok := direntReclen(buf)
39 if !ok {
40 return 0, false
41 }
42 return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
43 }
44
45 const PathMax = 256
46
47
48
49
50
51
52
53
54 type Errno uintptr
55
56 func (e Errno) Error() string {
57 if 0 <= int(e) && int(e) < len(errorstr) {
58 s := errorstr[e]
59 if s != "" {
60 return s
61 }
62 }
63 return "errno " + itoa(int(e))
64 }
65
66 func (e Errno) Is(target error) bool {
67 switch target {
68 case oserror.ErrPermission:
69 return e == EACCES || e == EPERM
70 case oserror.ErrExist:
71 return e == EEXIST || e == ENOTEMPTY
72 case oserror.ErrNotExist:
73 return e == ENOENT
74 }
75 return false
76 }
77
78 func (e Errno) Temporary() bool {
79 return e == EINTR || e == EMFILE || e.Timeout()
80 }
81
82 func (e Errno) Timeout() bool {
83 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
84 }
85
86
87
88 type Signal int
89
90 const (
91 _ Signal = iota
92 SIGCHLD
93 SIGINT
94 SIGKILL
95 SIGTRAP
96 SIGQUIT
97 )
98
99 func (s Signal) Signal() {}
100
101 func (s Signal) String() string {
102 if 0 <= s && int(s) < len(signals) {
103 str := signals[s]
104 if str != "" {
105 return str
106 }
107 }
108 return "signal " + itoa(int(s))
109 }
110
111 var signals = [...]string{}
112
113
114
115 const (
116 Stdin = 0
117 Stdout = 1
118 Stderr = 2
119 )
120
121
122 const (
123 O_RDONLY = 0
124 O_WRONLY = 1
125 O_RDWR = 2
126 O_ACCMODE = 3
127
128 O_CREAT = 0100
129 O_CREATE = O_CREAT
130 O_TRUNC = 01000
131 O_APPEND = 02000
132 O_EXCL = 0200
133 O_NONBLOCK = 04000
134 O_NDELAY = O_NONBLOCK
135 O_SYNC = 010000
136 O_FSYNC = O_SYNC
137 O_ASYNC = 020000
138
139 O_CLOEXEC = 0
140
141 FD_CLOEXEC = 1
142 )
143
144
145 const (
146 F_DUPFD = 0
147 F_GETFD = 1
148 F_SETFD = 2
149 F_GETFL = 3
150 F_SETFL = 4
151 F_GETOWN = 5
152 F_SETOWN = 6
153 F_GETLK = 7
154 F_SETLK = 8
155 F_SETLKW = 9
156 F_RGETLK = 10
157 F_RSETLK = 11
158 F_CNVT = 12
159 F_RSETLKW = 13
160
161 F_RDLCK = 1
162 F_WRLCK = 2
163 F_UNLCK = 3
164 F_UNLKSYS = 4
165 )
166
167
168 const (
169 S_IFMT = 0000370000
170 S_IFSHM_SYSV = 0000300000
171 S_IFSEMA = 0000270000
172 S_IFCOND = 0000260000
173 S_IFMUTEX = 0000250000
174 S_IFSHM = 0000240000
175 S_IFBOUNDSOCK = 0000230000
176 S_IFSOCKADDR = 0000220000
177 S_IFDSOCK = 0000210000
178
179 S_IFSOCK = 0000140000
180 S_IFLNK = 0000120000
181 S_IFREG = 0000100000
182 S_IFBLK = 0000060000
183 S_IFDIR = 0000040000
184 S_IFCHR = 0000020000
185 S_IFIFO = 0000010000
186
187 S_UNSUP = 0000370000
188
189 S_ISUID = 0004000
190 S_ISGID = 0002000
191 S_ISVTX = 0001000
192
193 S_IREAD = 0400
194 S_IWRITE = 0200
195 S_IEXEC = 0100
196
197 S_IRWXU = 0700
198 S_IRUSR = 0400
199 S_IWUSR = 0200
200 S_IXUSR = 0100
201
202 S_IRWXG = 070
203 S_IRGRP = 040
204 S_IWGRP = 020
205 S_IXGRP = 010
206
207 S_IRWXO = 07
208 S_IROTH = 04
209 S_IWOTH = 02
210 S_IXOTH = 01
211 )
212
213
214
215 type Stat_t struct {
216 Dev int64
217 Ino uint64
218 Mode uint32
219 Nlink uint32
220 Uid uint32
221 Gid uint32
222 Rdev int64
223 Size int64
224 Blksize int32
225 Blocks int32
226 Atime int64
227 AtimeNsec int64
228 Mtime int64
229 MtimeNsec int64
230 Ctime int64
231 CtimeNsec int64
232 }
233
234
235
236
237 var ForkLock sync.RWMutex
238
239 type WaitStatus uint32
240
241 func (w WaitStatus) Exited() bool { return false }
242 func (w WaitStatus) ExitStatus() int { return 0 }
243 func (w WaitStatus) Signaled() bool { return false }
244 func (w WaitStatus) Signal() Signal { return 0 }
245 func (w WaitStatus) CoreDump() bool { return false }
246 func (w WaitStatus) Stopped() bool { return false }
247 func (w WaitStatus) Continued() bool { return false }
248 func (w WaitStatus) StopSignal() Signal { return 0 }
249 func (w WaitStatus) TrapCause() int { return 0 }
250
251
252 type Rusage struct {
253 Utime Timeval
254 Stime Timeval
255 }
256
257
258 type ProcAttr struct {
259 Dir string
260 Env []string
261 Files []uintptr
262 Sys *SysProcAttr
263 }
264
265 type SysProcAttr struct {
266 }
267
268
269
270 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
271 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { return 0, 0, ENOSYS }
272 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { return 0, 0, ENOSYS }
273 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
274 return 0, 0, ENOSYS
275 }
276
277 func Sysctl(key string) (string, error) {
278 if key == "kern.hostname" {
279 return "naclbox", nil
280 }
281 return "", ENOSYS
282 }
283
284
285
286 const ImplementsGetwd = false
287
288 func Getwd() (wd string, err error) { return "", ENOSYS }
289 func Getegid() int { return 1 }
290 func Geteuid() int { return 1 }
291 func Getgid() int { return 1 }
292 func Getgroups() ([]int, error) { return []int{1}, nil }
293 func Getppid() int { return 2 }
294 func Getpid() int { return 3 }
295 func Gettimeofday(tv *Timeval) error { return ENOSYS }
296 func Getuid() int { return 1 }
297 func Kill(pid int, signum Signal) error { return ENOSYS }
298 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
299 return 0, ENOSYS
300 }
301 func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
302 return 0, 0, ENOSYS
303 }
304 func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
305 return 0, ENOSYS
306 }
307 func RouteRIB(facility, param int) ([]byte, error) { return nil, ENOSYS }
308 func ParseRoutingMessage(b []byte) ([]RoutingMessage, error) { return nil, ENOSYS }
309 func ParseRoutingSockaddr(msg RoutingMessage) ([]Sockaddr, error) { return nil, ENOSYS }
310 func SysctlUint32(name string) (value uint32, err error) { return 0, ENOSYS }
311
312 type Iovec struct{}
313
View as plain text