forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
52 lines (43 loc) · 1.25 KB
/
state.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
//go:build linux
// Package ptracer holds ptracer related files
package ptracer
// SyscallState defines the state of the syscall
type SyscallState struct {
Entry bool
Exec bool
}
// SyscallStateTracker defines a syscall state tracker
type SyscallStateTracker struct {
states map[int]*SyscallState
}
// NewSyscallStateTracker returns a new syscall state tracker
func NewSyscallStateTracker() *SyscallStateTracker {
return &SyscallStateTracker{
states: make(map[int]*SyscallState),
}
}
// NextStop update the state for the given pid
func (st *SyscallStateTracker) NextStop(pid int) *SyscallState {
state, exists := st.states[pid]
if exists {
state.Entry = !state.Entry
} else {
state = &SyscallState{
Entry: true,
}
st.states[pid] = state
}
return state
}
// Exit delete the pid from the tracker
func (st *SyscallStateTracker) Exit(pid int) {
delete(st.states, pid)
}
// PeekState return the state of the given pid
func (st *SyscallStateTracker) PeekState(pid int) *SyscallState {
return st.states[pid]
}