libgo: update to Go 1.11
[official-gcc.git] / libgo / go / syscall / syscall_js.go
blob6822eec8359cabdaefc26c96dbf1f8b8ad3c856d
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build js,wasm
7 package syscall
9 import (
10 "sync"
11 "unsafe"
14 const direntSize = 8 + 8 + 2 + 256
16 type Dirent struct {
17 Reclen uint16
18 Name [256]byte
21 func direntIno(buf []byte) (uint64, bool) {
22 return 1, true
25 func direntReclen(buf []byte) (uint64, bool) {
26 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
29 func direntNamlen(buf []byte) (uint64, bool) {
30 reclen, ok := direntReclen(buf)
31 if !ok {
32 return 0, false
34 return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
37 const PathMax = 256
39 // An Errno is an unsigned number describing an error condition.
40 // It implements the error interface. The zero Errno is by convention
41 // a non-error, so code to convert from Errno to error should use:
42 // err = nil
43 // if errno != 0 {
44 // err = errno
45 // }
46 type Errno uintptr
48 func (e Errno) Error() string {
49 if 0 <= int(e) && int(e) < len(errorstr) {
50 s := errorstr[e]
51 if s != "" {
52 return s
55 return "errno " + itoa(int(e))
58 func (e Errno) Temporary() bool {
59 return e == EINTR || e == EMFILE || e.Timeout()
62 func (e Errno) Timeout() bool {
63 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
66 // A Signal is a number describing a process signal.
67 // It implements the os.Signal interface.
68 type Signal int
70 const (
71 _ Signal = iota
72 SIGCHLD
73 SIGINT
74 SIGKILL
75 SIGTRAP
76 SIGQUIT
79 func (s Signal) Signal() {}
81 func (s Signal) String() string {
82 if 0 <= s && int(s) < len(signals) {
83 str := signals[s]
84 if str != "" {
85 return str
88 return "signal " + itoa(int(s))
91 var signals = [...]string{}
93 // File system
95 const (
96 Stdin = 0
97 Stdout = 1
98 Stderr = 2
101 const (
102 O_RDONLY = 0
103 O_WRONLY = 1
104 O_RDWR = 2
106 O_CREAT = 0100
107 O_CREATE = O_CREAT
108 O_TRUNC = 01000
109 O_APPEND = 02000
110 O_EXCL = 0200
111 O_SYNC = 010000
113 O_CLOEXEC = 0
116 const (
117 F_DUPFD = 0
118 F_GETFD = 1
119 F_SETFD = 2
120 F_GETFL = 3
121 F_SETFL = 4
122 F_GETOWN = 5
123 F_SETOWN = 6
124 F_GETLK = 7
125 F_SETLK = 8
126 F_SETLKW = 9
127 F_RGETLK = 10
128 F_RSETLK = 11
129 F_CNVT = 12
130 F_RSETLKW = 13
132 F_RDLCK = 1
133 F_WRLCK = 2
134 F_UNLCK = 3
135 F_UNLKSYS = 4
138 const (
139 S_IFMT = 0000370000
140 S_IFSHM_SYSV = 0000300000
141 S_IFSEMA = 0000270000
142 S_IFCOND = 0000260000
143 S_IFMUTEX = 0000250000
144 S_IFSHM = 0000240000
145 S_IFBOUNDSOCK = 0000230000
146 S_IFSOCKADDR = 0000220000
147 S_IFDSOCK = 0000210000
149 S_IFSOCK = 0000140000
150 S_IFLNK = 0000120000
151 S_IFREG = 0000100000
152 S_IFBLK = 0000060000
153 S_IFDIR = 0000040000
154 S_IFCHR = 0000020000
155 S_IFIFO = 0000010000
157 S_UNSUP = 0000370000
159 S_ISUID = 0004000
160 S_ISGID = 0002000
161 S_ISVTX = 0001000
163 S_IREAD = 0400
164 S_IWRITE = 0200
165 S_IEXEC = 0100
167 S_IRWXU = 0700
168 S_IRUSR = 0400
169 S_IWUSR = 0200
170 S_IXUSR = 0100
172 S_IRWXG = 070
173 S_IRGRP = 040
174 S_IWGRP = 020
175 S_IXGRP = 010
177 S_IRWXO = 07
178 S_IROTH = 04
179 S_IWOTH = 02
180 S_IXOTH = 01
183 type Stat_t struct {
184 Dev int64
185 Ino uint64
186 Mode uint32
187 Nlink uint32
188 Uid uint32
189 Gid uint32
190 Rdev int64
191 Size int64
192 Blksize int32
193 Blocks int32
194 Atime int64
195 AtimeNsec int64
196 Mtime int64
197 MtimeNsec int64
198 Ctime int64
199 CtimeNsec int64
202 // Processes
203 // Not supported - just enough for package os.
205 var ForkLock sync.RWMutex
207 type WaitStatus uint32
209 func (w WaitStatus) Exited() bool { return false }
210 func (w WaitStatus) ExitStatus() int { return 0 }
211 func (w WaitStatus) Signaled() bool { return false }
212 func (w WaitStatus) Signal() Signal { return 0 }
213 func (w WaitStatus) CoreDump() bool { return false }
214 func (w WaitStatus) Stopped() bool { return false }
215 func (w WaitStatus) Continued() bool { return false }
216 func (w WaitStatus) StopSignal() Signal { return 0 }
217 func (w WaitStatus) TrapCause() int { return 0 }
219 // XXX made up
220 type Rusage struct {
221 Utime Timeval
222 Stime Timeval
225 // XXX made up
226 type ProcAttr struct {
227 Dir string
228 Env []string
229 Files []uintptr
230 Sys *SysProcAttr
233 type SysProcAttr struct {
236 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
237 return 0, 0, ENOSYS
240 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
241 return 0, 0, ENOSYS
244 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
245 return 0, 0, ENOSYS
248 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
249 return 0, 0, ENOSYS
252 func Sysctl(key string) (string, error) {
253 if key == "kern.hostname" {
254 return "js", nil
256 return "", ENOSYS
259 const ImplementsGetwd = true
261 func Getwd() (wd string, err error) {
262 var buf [PathMax]byte
263 n, err := Getcwd(buf[0:])
264 if err != nil {
265 return "", err
267 return string(buf[:n]), nil
270 func Getegid() int { return 1 }
271 func Geteuid() int { return 1 }
272 func Getgid() int { return 1 }
273 func Getgroups() ([]int, error) { return []int{1}, nil }
274 func Getppid() int { return 2 }
275 func Getpid() int { return 3 }
276 func Gettimeofday(tv *Timeval) error { return ENOSYS }
277 func Getuid() int { return 1 }
278 func Kill(pid int, signum Signal) error { return ENOSYS }
279 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
280 return 0, ENOSYS
282 func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
283 return 0, 0, ENOSYS
285 func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
286 return 0, ENOSYS
289 type Iovec struct{} // dummy
291 type Timespec struct {
292 Sec int64
293 Nsec int64
296 type Timeval struct {
297 Sec int64
298 Usec int64
301 func setTimespec(sec, nsec int64) Timespec {
302 return Timespec{Sec: sec, Nsec: nsec}
305 func setTimeval(sec, usec int64) Timeval {
306 return Timeval{Sec: sec, Usec: usec}