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) {
35 if unsafe.Sizeof(r) == 4 {
36 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
39 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
47 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
50 if unsafe.Sizeof(r) == 4 {
51 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
52 int32(a4), int32(a5), int32(a6))
55 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
56 int64(a4), int64(a5), int64(a6))
64 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
66 if unsafe.Sizeof(r) == 4 {
67 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
70 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
77 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
79 if unsafe.Sizeof(r) == 4 {
80 r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
81 int32(a4), int32(a5), int32(a6))
84 r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
85 int64(a4), int64(a5), int64(a6))
92 // Mmap manager, for use by operating system-specific implementations.
93 // Gccgo only has one implementation but we do this to correspond to gc.
97 active map[*byte][]byte // active mappings; key is last byte in mapping
98 mmap func(addr, length uintptr, prot, flags, fd int, offset int64) (uintptr, error)
99 munmap func(addr uintptr, length uintptr) error
102 func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
107 // Map the requested memory.
108 addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset)
113 // Slice memory layout
118 }{addr, length, length}
120 // Use unsafe to turn sl into a []byte.
121 b := *(*[]byte)(unsafe.Pointer(&sl))
123 // Register mapping in m and return it.
131 func (m *mmapper) Munmap(data []byte) (err error) {
132 if len(data) == 0 || len(data) != cap(data) {
136 // Find the base of the mapping.
137 p := &data[cap(data)-1]
141 if b == nil || &b[0] != &data[0] {
145 // Unmap the memory and update m.
146 if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))); errno != nil {
149 m.active[p] = nil, false
153 var mapper = &mmapper{
154 active: make(map[*byte][]byte),
159 func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
160 return mapper.Mmap(fd, offset, length, prot, flags)
163 func Munmap(b []byte) (err error) {
164 return mapper.Munmap(b)
167 // A Signal is a number describing a process signal.
168 // It implements the os.Signal interface.
171 func (s Signal) Signal() {}
173 func Signame(s Signal) string
175 func (s Signal) String() string {