hybridgroup.gobot/sysfs/syscall.go

45 lines
1.1 KiB
Go
Raw 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
type MockSyscall struct {
Impl func(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}
2014-11-08 08:56:13 +08:00
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) {
if sys.Impl != nil {
return sys.Impl(trap, a1, a2, a3)
} else {
return 0, 0, 0
}
2014-11-08 08:56:13 +08:00
}