1 // Copyright 2009 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 darwin dragonfly freebsd linux netbsd openbsd
22 func c_syscall32(trap
int32, a1
, a2
, a3
, a4
, a5
, a6
int32) int32
25 func c_syscall64(trap
int64, a1
, a2
, a3
, a4
, a5
, a6
int64) int64
28 darwin64Bit
= runtime
.GOOS
== "darwin" && sizeofPtr
== 8
29 netbsd32Bit
= runtime
.GOOS
== "netbsd" && sizeofPtr
== 4
32 // Do a system call. We look at the size of uintptr to see how to pass
33 // the arguments, so that we don't pass a 64-bit value when the function
34 // expects a 32-bit one.
35 func Syscall(trap
, a1
, a2
, a3
uintptr) (r1
, r2
uintptr, err Errno
) {
39 if unsafe
.Sizeof(r
) == 4 {
40 r1
:= c_syscall32(int32(trap
), int32(a1
), int32(a2
), int32(a3
), 0, 0, 0)
43 r1
:= c_syscall64(int64(trap
), int64(a1
), int64(a2
), int64(a3
), 0, 0, 0)
51 func Syscall6(trap
, a1
, a2
, a3
, a4
, a5
, a6
uintptr) (r1
, r2
uintptr, err Errno
) {
55 if unsafe
.Sizeof(r
) == 4 {
56 r1
:= c_syscall32(int32(trap
), int32(a1
), int32(a2
), int32(a3
),
57 int32(a4
), int32(a5
), int32(a6
))
60 r1
:= c_syscall64(int64(trap
), int64(a1
), int64(a2
), int64(a3
),
61 int64(a4
), int64(a5
), int64(a6
))
69 func RawSyscall(trap
, a1
, a2
, a3
uintptr) (r1
, r2
uintptr, err Errno
) {
72 if unsafe
.Sizeof(r
) == 4 {
73 r1
:= c_syscall32(int32(trap
), int32(a1
), int32(a2
), int32(a3
), 0, 0, 0)
76 r1
:= c_syscall64(int64(trap
), int64(a1
), int64(a2
), int64(a3
), 0, 0, 0)
83 func RawSyscall6(trap
, a1
, a2
, a3
, a4
, a5
, a6
uintptr) (r1
, r2
uintptr, err Errno
) {
86 if unsafe
.Sizeof(r
) == 4 {
87 r1
:= c_syscall32(int32(trap
), int32(a1
), int32(a2
), int32(a3
),
88 int32(a4
), int32(a5
), int32(a6
))
91 r1
:= c_syscall64(int64(trap
), int64(a1
), int64(a2
), int64(a3
),
92 int64(a4
), int64(a5
), int64(a6
))
99 // Mmap manager, for use by operating system-specific implementations.
100 // Gccgo only has one implementation but we do this to correspond to gc.
102 type mmapper
struct {
104 active
map[*byte][]byte // active mappings; key is last byte in mapping
105 mmap
func(addr
, length
uintptr, prot
, flags
, fd
int, offset
int64) (uintptr, error
)
106 munmap
func(addr
uintptr, length
uintptr) error
109 func (m
*mmapper
) Mmap(fd
int, offset
int64, length
int, prot
int, flags
int) (data
[]byte, err error
) {
114 // Map the requested memory.
115 addr
, errno
:= m
.mmap(0, uintptr(length
), prot
, flags
, fd
, offset
)
120 // Slice memory layout
125 }{addr
, length
, length
}
127 // Use unsafe to turn sl into a []byte.
128 b
:= *(*[]byte)(unsafe
.Pointer(&sl
))
130 // Register mapping in m and return it.
138 func (m
*mmapper
) Munmap(data
[]byte) (err error
) {
139 if len(data
) == 0 ||
len(data
) != cap(data
) {
143 // Find the base of the mapping.
144 p
:= &data
[cap(data
)-1]
148 if b
== nil ||
&b
[0] != &data
[0] {
152 // Unmap the memory and update m.
153 if errno
:= m
.munmap(uintptr(unsafe
.Pointer(&b
[0])), uintptr(len(b
))); errno
!= nil {
156 m
.active
[p
] = nil, false
160 var mapper
= &mmapper
{
161 active
: make(map[*byte][]byte),
166 func Mmap(fd
int, offset
int64, length
int, prot
int, flags
int) (data
[]byte, err error
) {
167 return mapper
.Mmap(fd
, offset
, length
, prot
, flags
)
170 func Munmap(b
[]byte) (err error
) {
171 return mapper
.Munmap(b
)
174 // A Signal is a number describing a process signal.
175 // It implements the os.Signal interface.
178 func (s Signal
) Signal() {}
180 func Signame(s Signal
) string
182 func (s Signal
) String() string {
186 func Read(fd
int, p
[]byte) (n
int, err error
) {
190 raceWriteRange(unsafe
.Pointer(&p
[0]), n
)
193 raceAcquire(unsafe
.Pointer(&ioSync
))
199 func Write(fd
int, p
[]byte) (n
int, err error
) {
201 raceReleaseMerge(unsafe
.Pointer(&ioSync
))
203 n
, err
= write(fd
, p
)
204 if raceenabled
&& n
> 0 {
205 raceReadRange(unsafe
.Pointer(&p
[0]), n
)