Pop receives the stack walk event and pops the oldest originating event with the same pid,tid tuple formerly coined as stack identifier. The originating event is then decorated with callstack return addresses.
(e *Event)
| 113 | // coined as stack identifier. The originating event is then |
| 114 | // decorated with callstack return addresses. |
| 115 | func (s *StackwalkDecorator) Pop(e *Event) *Event { |
| 116 | s.mux.Lock() |
| 117 | defer s.mux.Unlock() |
| 118 | |
| 119 | id := e.StackID() |
| 120 | q, ok := s.buckets[id] |
| 121 | if !ok { |
| 122 | return e |
| 123 | } |
| 124 | |
| 125 | var evt *Event |
| 126 | if len(q) > 0 { |
| 127 | evt, s.buckets[id] = q[0], q[1:] |
| 128 | stackwalkEnqueued.Add(-int64(len(s.buckets[id]))) |
| 129 | } |
| 130 | |
| 131 | if evt == nil { |
| 132 | return e |
| 133 | } |
| 134 | |
| 135 | if evt.IsSurrogateProcess() && s.procs[evt.Params.MustGetPid()] != nil { |
| 136 | delete(s.procs, evt.Params.MustGetPid()) |
| 137 | } |
| 138 | |
| 139 | callstack := e.Params.MustGetSlice(params.Callstack) |
| 140 | evt.AppendParam(params.Callstack, params.Slice, callstack) |
| 141 | |
| 142 | // obtain the callstack from the CreateThread event |
| 143 | // generated by the surrogate/brokered process, such as |
| 144 | // Secondary Logon. |
| 145 | // If the remote process id is present in the procs map |
| 146 | // the stack is attached to the cached event and then |
| 147 | // pushed to the queue immediately |
| 148 | if evt.IsCreateRemoteThread() { |
| 149 | pid := evt.Params.MustGetPid() |
| 150 | ev, ok := s.procs[pid] |
| 151 | if ok { |
| 152 | ev.AppendParam(params.Callstack, params.Slice, callstack) |
| 153 | _ = s.q.push(ev) |
| 154 | delete(s.procs, pid) |
| 155 | // find the most recent CreateProcess event and |
| 156 | // remove it from buckets as we have the callstack |
| 157 | qu := s.buckets[ev.StackID()] |
| 158 | for i := len(qu) - 1; i >= 0; i-- { |
| 159 | proc := qu[i] |
| 160 | if !proc.IsCreateProcess() && proc.Params.MustGetPid() != pid { |
| 161 | continue |
| 162 | } |
| 163 | qu = append(qu[:i], qu[i+1:]...) |
| 164 | } |
| 165 | s.buckets[ev.StackID()] = qu |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return evt |
| 170 | } |
| 171 | |
| 172 | // Stop shutdowns the stack walk decorator flusher. |