-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
91 lines (74 loc) · 1.67 KB
/
types.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package processwatcher
import (
"unsafe"
)
type ProcEventType uint32
type Pid uint32
const (
PROC_EVENT_NONE ProcEventType = 0x00000000
PROC_EVENT_FORK = 0x00000001
PROC_EVENT_EXEC = 0x00000002
PROC_EVENT_UID = 0x00000004
PROC_EVENT_GID = 0x00000040
PROC_EVENT_SID = 0x00000080
PROC_EVENT_PTRACE = 0x00000100
PROC_EVENT_COMM = 0x00000200
PROC_EVENT_COREDUMP = 0x40000000
PROC_EVENT_EXIT = 0x80000000
)
type WatchEvent struct {
Err error
ProcEvent
}
type ProcEventHeader struct {
Type ProcEventType
CPU uint32
// Number of nano seconds since system boot
Timestamps uint64
}
type ProcEvent struct {
ptr unsafe.Pointer
}
type Fork struct {
ParentPid Pid
ParentTgid Pid
ChildPid Pid
ChildTgid Pid
}
type Exec struct {
ProcessPid Pid
ProcessTgid Pid
}
type Comm struct {
ProcessPid Pid
ProcessTgid Pid
}
type Exit struct {
ProcessPid Pid
ProcessTgid Pid
ExitCode uint32
ExitSignal uint32
ParentPid Pid
ParentTgid Pid
}
func (p *ProcEvent) GetHeader() ProcEventHeader {
return *(*ProcEventHeader)(p.ptr)
}
func (p *ProcEvent) GetType() ProcEventType {
return p.GetHeader().Type
}
func (p *ProcEvent) dataPtr() unsafe.Pointer {
return unsafe.Pointer(uintptr(p.ptr) + uintptr(unsafe.Sizeof(ProcEventHeader{})))
}
func (p *ProcEvent) GetFork() Fork {
return *(*Fork)(p.dataPtr())
}
func (p *ProcEvent) GetExec() Exec {
return *(*Exec)(p.dataPtr())
}
func (p *ProcEvent) GetComm() Comm {
return *(*Comm)(p.dataPtr())
}
func (p *ProcEvent) GetExit() Exit {
return *(*Exit)(p.dataPtr())
}