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.
15 const direntSize
= 8 + 8 + 2 + 256
22 func direntIno(buf
[]byte) (uint64, bool) {
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
)
35 return reclen
- uint64(unsafe
.Offsetof(Dirent
{}.Name
)), true
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:
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) ...
55 func (e Errno
) Error() string {
56 if 0 <= int(e
) && int(e
) < len(errorstr
) {
62 return "errno " + itoa(int(e
))
65 func (e Errno
) Is(target error
) bool {
67 case oserror
.ErrPermission
:
68 return e
== EACCES || e
== EPERM
69 case oserror
.ErrExist
:
70 return e
== EEXIST || e
== ENOTEMPTY
71 case oserror
.ErrNotExist
:
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.
99 func (s Signal
) Signal() {}
101 func (s Signal
) String() string {
102 if 0 <= s
&& int(s
) < len(signals
) {
108 return "signal " + itoa(int(s
))
111 var signals
= [...]string{}
160 S_IFSHM_SYSV
= 0000300000
161 S_IFSEMA
= 0000270000
162 S_IFCOND
= 0000260000
163 S_IFMUTEX
= 0000250000
165 S_IFBOUNDSOCK
= 0000230000
166 S_IFSOCKADDR
= 0000220000
167 S_IFDSOCK
= 0000210000
169 S_IFSOCK
= 0000140000
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 }
246 type ProcAttr
struct {
253 type SysProcAttr
struct {
256 func Syscall(trap
, a1
, a2
, a3
uintptr) (r1
, r2
uintptr, err Errno
) {
260 func Syscall6(trap
, a1
, a2
, a3
, a4
, a5
, a6
uintptr) (r1
, r2
uintptr, err Errno
) {
264 func RawSyscall(trap
, a1
, a2
, a3
uintptr) (r1
, r2
uintptr, err Errno
) {
268 func RawSyscall6(trap
, a1
, a2
, a3
, a4
, a5
, a6
uintptr) (r1
, r2
uintptr, err Errno
) {
272 func Sysctl(key
string) (string, error
) {
273 if key
== "kern.hostname" {
279 const ImplementsGetwd
= true
281 func Getwd() (wd
string, err error
) {
282 var buf
[PathMax
]byte
283 n
, err
:= Getcwd(buf
[0:])
287 return string(buf
[:n
]), nil
291 return jsProcess
.Call("getuid").Int()
295 return jsProcess
.Call("getgid").Int()
299 return jsProcess
.Call("geteuid").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()
317 return jsProcess
.Get("pid").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
) {
334 func StartProcess(argv0
string, argv
[]string, attr
*ProcAttr
) (pid
int, handle
uintptr, err error
) {
337 func Wait4(pid
int, wstatus
*WaitStatus
, options
int, rusage
*Rusage
) (wpid
int, err error
) {
341 type Iovec
struct{} // dummy
343 type Timespec
struct {
348 type Timeval
struct {
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
}