hybridgroup.gobot/sysfs/syscall.go

39 lines
981 B
Go
Raw Permalink Normal View History

2014-11-08 08:56:13 +08:00
package sysfs
import (
"syscall"
)
// SystemCaller represents a Syscall
2014-11-08 08:56:13 +08:00
type SystemCaller interface {
Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}
// NativeSyscall represents the native Syscall
2014-11-08 08:56:13 +08:00
type NativeSyscall struct{}
// MockSyscall represents the mock Syscall
2014-11-08 08:56:13 +08:00
type MockSyscall struct{}
var sys SystemCaller = &NativeSyscall{}
// SetSyscall sets the Syscall implementation
2014-11-08 08:56:13 +08:00
func SetSyscall(s SystemCaller) {
sys = s
}
// Syscall calls either the NativeSyscall or user defined Syscall
2014-11-08 08:56:13 +08:00
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
return sys.Syscall(trap, a1, a2, a3)
}
// Syscall calls syscall.Syscall
2014-11-08 08:56:13 +08:00
func (sys *NativeSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
return syscall.Syscall(trap, a1, a2, a3)
}
// Syscall implements the SystemCaller interface
2014-11-08 08:56:13 +08:00
func (sys *MockSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
return 0, 0, 0
}