1 // syscall.go -- Basic syscall interface.
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // This package contains an interface to the low-level operating system
8 // primitives. The details vary depending on the underlying system.
9 // Its primary use is inside other packages that provide a more portable
10 // interface to the system, such as "os", "time" and "net". Use those
11 // packages rather than this one if you can.
12 // For details of the functions and data types in this package consult
13 // the manuals for the appropriate operating system.
18 func libc_syscall32(trap int32, a1, a2, a3, a4, a5, a6 int32) int32 __asm__ ("syscall");
19 func libc_syscall64(trap int64, a1, a2, a3, a4, a5, a6 int64) int64 __asm__ ("syscall");
21 // Do a system call. We look at the size of uintptr to see how to pass
22 // the arguments, so that we don't pass a 64-bit value when the function
23 // expects a 32-bit one.
24 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
26 if unsafe.Sizeof(r) == 4 {
27 r1 := libc_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0);
30 r1 := libc_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0);
33 return r, 0, uintptr(GetErrno());
36 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
38 if unsafe.Sizeof(r) == 4 {
39 r1 := libc_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
40 int32(a4), int32(a5), int32(a6));
43 r1 := libc_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
44 int64(a4), int64(a5), int64(a6));
47 return r, 0, uintptr(GetErrno());