2024-07-12 00:59:32 +08:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// Linux system calls.
|
|
|
|
|
// This file is compiled as ordinary Go code,
|
|
|
|
|
// but it is also input to mksyscall,
|
|
|
|
|
// which parses the //sys lines and generates system call stubs.
|
|
|
|
|
// Note that sometimes we use a lowercase //sys name and
|
|
|
|
|
// wrap it in our own nicer implementation.
|
|
|
|
|
|
|
|
|
|
package syscall
|
|
|
|
|
|
2024-07-26 13:46:21 +08:00
|
|
|
type WaitStatus uint32
|
|
|
|
|
|
|
|
|
|
// Wait status is 7 bits at bottom, either 0 (exited),
|
|
|
|
|
// 0x7F (stopped), or a signal number that caused an exit.
|
|
|
|
|
// The 0x80 bit is whether there was a core dump.
|
|
|
|
|
// An extra number (exit code, signal causing a stop)
|
|
|
|
|
// is in the high bits. At least that's the idea.
|
|
|
|
|
// There are various irregularities. For example, the
|
|
|
|
|
// "continued" status is 0xFFFF, distinguishing itself
|
|
|
|
|
// from stopped via the core dump bit.
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
mask = 0x7F
|
|
|
|
|
core = 0x80
|
|
|
|
|
exited = 0x00
|
|
|
|
|
stopped = 0x7F
|
|
|
|
|
shift = 8
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) Exited() bool { return w&mask == exited }
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != exited }
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) Stopped() bool { return w&0xFF == stopped }
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) Continued() bool { return w == 0xFFFF }
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) ExitStatus() int {
|
|
|
|
|
if !w.Exited() {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return int(w>>shift) & 0xFF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) Signal() Signal {
|
|
|
|
|
if !w.Signaled() {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return Signal(w & mask)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w WaitStatus) StopSignal() Signal {
|
|
|
|
|
if !w.Stopped() {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return Signal(w>>shift) & 0xFF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO(xsw):
|
|
|
|
|
func (w WaitStatus) TrapCause() int {
|
|
|
|
|
if w.StopSignal() != SIGTRAP {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return int(w>>shift) >> 8
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2024-07-12 00:59:32 +08:00
|
|
|
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
|
|
|
|
|
panic("todo: syscall.Faccessat")
|
|
|
|
|
}
|