forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscall.go
43 lines (34 loc) · 1.09 KB
/
syscall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sysfs
import (
"syscall"
)
// SystemCaller represents a Syscall
type SystemCaller interface {
Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}
// NativeSyscall represents the native Syscall
type NativeSyscall struct{}
// MockSyscall represents the mock Syscall
type MockSyscall struct {
Impl func(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}
var sys SystemCaller = &NativeSyscall{}
// SetSyscall sets the Syscall implementation
func SetSyscall(s SystemCaller) {
sys = s
}
// Syscall calls either the NativeSyscall or user defined Syscall
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
return sys.Syscall(trap, a1, a2, a3)
}
// Syscall calls syscall.Syscall
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
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)
}
return 0, 0, 0
}