github.com/criyle/go-sandbox@v0.10.3/runner/ptrace/filehandler/syscallcounter.go (about)

     1  package filehandler
     2  
     3  // SyscallCounter defines a count-down for each each syscall occurs
     4  type SyscallCounter map[string]int
     5  
     6  // NewSyscallCounter creates a new SyscallCounter
     7  func NewSyscallCounter() SyscallCounter {
     8  	return SyscallCounter(make(map[string]int))
     9  }
    10  
    11  // Add adds single counter to SyscallCounter
    12  func (s SyscallCounter) Add(name string, count int) {
    13  	s[name] = count
    14  }
    15  
    16  // AddRange add multiple counter to SyscallCounter
    17  func (s SyscallCounter) AddRange(m map[string]int) {
    18  	for k, v := range m {
    19  		s[k] = v
    20  	}
    21  }
    22  
    23  // Check return inside, allow
    24  func (s SyscallCounter) Check(name string) (bool, bool) {
    25  	n, o := s[name]
    26  	if o {
    27  		s[name] = n - 1
    28  		if n <= 1 {
    29  			return true, false
    30  		}
    31  		return true, true
    32  	}
    33  	return false, true
    34  }