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 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
27 const darwinAMD64 = runtime.GOOS == "darwin" && runtime.GOARCH == "amd64"
29 // Do a system call. We look at the size of uintptr to see how to pass
30 // the arguments, so that we don't pass a 64-bit value when the function
31 // expects a 32-bit one.
32 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
36 if unsafe.Sizeof(r) == 4 {
37 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
40 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
48 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
52 if unsafe.Sizeof(r) == 4 {
53 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
54 int32(a4), int32(a5), int32(a6))
57 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
58 int64(a4), int64(a5), int64(a6))
66 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
69 if unsafe.Sizeof(r) == 4 {
70 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
73 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
80 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
83 if unsafe.Sizeof(r) == 4 {
84 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
85 int32(a4), int32(a5), int32(a6))
88 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
89 int64(a4), int64(a5), int64(a6))
96 // Mmap manager, for use by operating system-specific implementations.
97 // Gccgo only has one implementation but we do this to correspond to gc.
101 active map[*byte][]byte // active mappings; key is last byte in mapping
102 mmap func(addr, length uintptr, prot, flags, fd int, offset int64) (uintptr, error)
103 munmap func(addr uintptr, length uintptr) error
106 func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
111 // Map the requested memory.
112 addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset)
117 // Slice memory layout
122 }{addr, length, length}
124 // Use unsafe to turn sl into a []byte.
125 b := *(*[]byte)(unsafe.Pointer(&sl))
127 // Register mapping in m and return it.
135 func (m *mmapper) Munmap(data []byte) (err error) {
136 if len(data) == 0 || len(data) != cap(data) {
140 // Find the base of the mapping.
141 p := &data[cap(data)-1]
145 if b == nil || &b[0] != &data[0] {
149 // Unmap the memory and update m.
150 if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))); errno != nil {
153 m.active[p] = nil, false
157 var mapper = &mmapper{
158 active: make(map[*byte][]byte),
163 func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
164 return mapper.Mmap(fd, offset, length, prot, flags)
167 func Munmap(b []byte) (err error) {
168 return mapper.Munmap(b)
171 // A Signal is a number describing a process signal.
172 // It implements the os.Signal interface.
175 func (s Signal) Signal() {}
177 func Signame(s Signal) string
179 func (s Signal) String() string {
183 func Read(fd int, p []byte) (n int, err error) {
185 if raceenabled && err == nil {
186 raceAcquire(unsafe.Pointer(&ioSync))
191 func Write(fd int, p []byte) (n int, err error) {
193 raceReleaseMerge(unsafe.Pointer(&ioSync))