Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / syscall / syscall_js.go
blobdfb4a275e30fd807ad3422bc7d4cedee6f73e796
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 "internal/oserror"
11 "sync"
12 "unsafe"
15 const direntSize = 8 + 8 + 2 + 256
17 type Dirent struct {
18 Reclen uint16
19 Name [256]byte
22 func direntIno(buf []byte) (uint64, bool) {
23 return 1, true
26 func direntReclen(buf []byte) (uint64, bool) {
27 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
30 func direntNamlen(buf []byte) (uint64, bool) {
31 reclen, ok := direntReclen(buf)
32 if !ok {
33 return 0, false
35 return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
38 const PathMax = 256
40 // An Errno is an unsigned number describing an error condition.
41 // It implements the error interface. The zero Errno is by convention
42 // a non-error, so code to convert from Errno to error should use:
43 // err = nil
44 // if errno != 0 {
45 // err = errno
46 // }
48 // Errno values can be tested against error values from the os package
49 // using errors.Is. For example:
51 // _, _, err := syscall.Syscall(...)
52 // if errors.Is(err, os.ErrNotExist) ...
53 type Errno uintptr
55 func (e Errno) Error() string {
56 if 0 <= int(e) && int(e) < len(errorstr) {
57 s := errorstr[e]
58 if s != "" {
59 return s
62 return "errno " + itoa(int(e))
65 func (e Errno) Is(target error) bool {
66 switch target {
67 case oserror.ErrPermission:
68 return e == EACCES || e == EPERM
69 case oserror.ErrExist:
70 return e == EEXIST || e == ENOTEMPTY
71 case oserror.ErrNotExist:
72 return e == ENOENT
74 return false
77 func (e Errno) Temporary() bool {
78 return e == EINTR || e == EMFILE || e.Timeout()
81 func (e Errno) Timeout() bool {
82 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
85 // A Signal is a number describing a process signal.
86 // It implements the os.Signal interface.
87 type Signal int
89 const (
90 _ Signal = iota
91 SIGCHLD
92 SIGINT
93 SIGKILL
94 SIGTRAP
95 SIGQUIT
96 SIGTERM
99 func (s Signal) Signal() {}
101 func (s Signal) String() string {
102 if 0 <= s && int(s) < len(signals) {
103 str := signals[s]
104 if str != "" {
105 return str
108 return "signal " + itoa(int(s))
111 var signals = [...]string{}
113 // File system
115 const (
116 Stdin = 0
117 Stdout = 1
118 Stderr = 2
121 const (
122 O_RDONLY = 0
123 O_WRONLY = 1
124 O_RDWR = 2
126 O_CREAT = 0100
127 O_CREATE = O_CREAT
128 O_TRUNC = 01000
129 O_APPEND = 02000
130 O_EXCL = 0200
131 O_SYNC = 010000
133 O_CLOEXEC = 0
136 const (
137 F_DUPFD = 0
138 F_GETFD = 1
139 F_SETFD = 2
140 F_GETFL = 3
141 F_SETFL = 4
142 F_GETOWN = 5
143 F_SETOWN = 6
144 F_GETLK = 7
145 F_SETLK = 8
146 F_SETLKW = 9
147 F_RGETLK = 10
148 F_RSETLK = 11
149 F_CNVT = 12
150 F_RSETLKW = 13
152 F_RDLCK = 1
153 F_WRLCK = 2
154 F_UNLCK = 3
155 F_UNLKSYS = 4
158 const (
159 S_IFMT = 0000370000
160 S_IFSHM_SYSV = 0000300000
161 S_IFSEMA = 0000270000
162 S_IFCOND = 0000260000
163 S_IFMUTEX = 0000250000
164 S_IFSHM = 0000240000
165 S_IFBOUNDSOCK = 0000230000
166 S_IFSOCKADDR = 0000220000
167 S_IFDSOCK = 0000210000
169 S_IFSOCK = 0000140000
170 S_IFLNK = 0000120000
171 S_IFREG = 0000100000
172 S_IFBLK = 0000060000
173 S_IFDIR = 0000040000
174 S_IFCHR = 0000020000
175 S_IFIFO = 0000010000
177 S_UNSUP = 0000370000
179 S_ISUID = 0004000
180 S_ISGID = 0002000
181 S_ISVTX = 0001000
183 S_IREAD = 0400
184 S_IWRITE = 0200
185 S_IEXEC = 0100
187 S_IRWXU = 0700
188 S_IRUSR = 0400
189 S_IWUSR = 0200
190 S_IXUSR = 0100
192 S_IRWXG = 070
193 S_IRGRP = 040
194 S_IWGRP = 020
195 S_IXGRP = 010
197 S_IRWXO = 07
198 S_IROTH = 04
199 S_IWOTH = 02
200 S_IXOTH = 01
203 type Stat_t struct {
204 Dev int64
205 Ino uint64
206 Mode uint32
207 Nlink uint32
208 Uid uint32
209 Gid uint32
210 Rdev int64
211 Size int64
212 Blksize int32
213 Blocks int32
214 Atime int64
215 AtimeNsec int64
216 Mtime int64
217 MtimeNsec int64
218 Ctime int64
219 CtimeNsec int64
222 // Processes
223 // Not supported - just enough for package os.
225 var ForkLock sync.RWMutex
227 type WaitStatus uint32
229 func (w WaitStatus) Exited() bool { return false }
230 func (w WaitStatus) ExitStatus() int { return 0 }
231 func (w WaitStatus) Signaled() bool { return false }
232 func (w WaitStatus) Signal() Signal { return 0 }
233 func (w WaitStatus) CoreDump() bool { return false }
234 func (w WaitStatus) Stopped() bool { return false }
235 func (w WaitStatus) Continued() bool { return false }
236 func (w WaitStatus) StopSignal() Signal { return 0 }
237 func (w WaitStatus) TrapCause() int { return 0 }
239 // XXX made up
240 type Rusage struct {
241 Utime Timeval
242 Stime Timeval
245 // XXX made up
246 type ProcAttr struct {
247 Dir string
248 Env []string
249 Files []uintptr
250 Sys *SysProcAttr
253 type SysProcAttr struct {
256 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
257 return 0, 0, ENOSYS
260 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
261 return 0, 0, ENOSYS
264 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
265 return 0, 0, ENOSYS
268 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
269 return 0, 0, ENOSYS
272 func Sysctl(key string) (string, error) {
273 if key == "kern.hostname" {
274 return "js", nil
276 return "", ENOSYS
279 const ImplementsGetwd = true
281 func Getwd() (wd string, err error) {
282 var buf [PathMax]byte
283 n, err := Getcwd(buf[0:])
284 if err != nil {
285 return "", err
287 return string(buf[:n]), nil
290 func Getuid() int {
291 return jsProcess.Call("getuid").Int()
294 func Getgid() int {
295 return jsProcess.Call("getgid").Int()
298 func Geteuid() int {
299 return jsProcess.Call("geteuid").Int()
302 func Getegid() int {
303 return jsProcess.Call("getegid").Int()
306 func Getgroups() (groups []int, err error) {
307 defer recoverErr(&err)
308 array := jsProcess.Call("getgroups")
309 groups = make([]int, array.Length())
310 for i := range groups {
311 groups[i] = array.Index(i).Int()
313 return groups, nil
316 func Getpid() int {
317 return jsProcess.Get("pid").Int()
320 func Getppid() int {
321 return jsProcess.Get("ppid").Int()
324 func Umask(mask int) (oldmask int) {
325 return jsProcess.Call("umask", mask).Int()
328 func Gettimeofday(tv *Timeval) error { return ENOSYS }
330 func Kill(pid int, signum Signal) error { return ENOSYS }
331 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
332 return 0, ENOSYS
334 func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
335 return 0, 0, ENOSYS
337 func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
338 return 0, ENOSYS
341 type Iovec struct{} // dummy
343 type Timespec struct {
344 Sec int64
345 Nsec int64
348 type Timeval struct {
349 Sec int64
350 Usec int64
353 func setTimespec(sec, nsec int64) Timespec {
354 return Timespec{Sec: sec, Nsec: nsec}
357 func setTimeval(sec, usec int64) Timeval {
358 return Timeval{Sec: sec, Usec: usec}