2010-12-03 05:34:57 +01: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.
|
|
|
|
|
|
|
|
package syscall
|
|
|
|
|
2011-04-07 19:09:10 +02:00
|
|
|
import "unsafe"
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
var (
|
|
|
|
Stdin = 0
|
|
|
|
Stdout = 1
|
|
|
|
Stderr = 2
|
|
|
|
)
|
|
|
|
|
2011-01-13 06:17:52 +01:00
|
|
|
const ENONE = 0
|
|
|
|
|
|
|
|
func GetErrno() int
|
|
|
|
func SetErrno(int)
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
func Uname(buf *Utsname) (errno int) {
|
|
|
|
r := libc_uname(buf)
|
|
|
|
if r < 0 {
|
|
|
|
errno = GetErrno()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2011-04-07 19:09:10 +02:00
|
|
|
|
|
|
|
var mapper = &mmapper{
|
|
|
|
active: make(map[*byte][]byte),
|
|
|
|
mmap: mmap,
|
|
|
|
munmap: munmap,
|
|
|
|
}
|
|
|
|
|
|
|
|
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, errno int) {
|
|
|
|
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Munmap(b []byte) (errno int) {
|
|
|
|
return mapper.Munmap(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func libc_munmap(*byte, Size_t) int __asm__ ("munmap")
|
|
|
|
|
|
|
|
func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, errno int) {
|
|
|
|
r0 := libc_mmap((*byte)(unsafe.Pointer(addr)), Size_t(length), prot, flag, fd, Offset_t(pos))
|
|
|
|
ret = uintptr(unsafe.Pointer(r0))
|
|
|
|
if ret + 1 == 0 {
|
|
|
|
errno = GetErrno()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func munmap(addr uintptr, length uintptr) (errno int) {
|
|
|
|
if libc_munmap((*byte)(unsafe.Pointer(addr)), Size_t(length)) < 0 {
|
|
|
|
errno = GetErrno()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2011-05-20 02:18:15 +02:00
|
|
|
|
|
|
|
func libc_getrusage(who int, rusage *Rusage) int __asm__ ("getrusage")
|
|
|
|
|
|
|
|
func Getrusage(who int, rusage *Rusage) (errno int) {
|
|
|
|
if libc_getrusage(who, rusage) < 0 {
|
|
|
|
errno = GetErrno()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|