Closed daladim closed 1 year ago
I'm on my way to fix it.
But this (more or less) requires some changes to make the unsafe
s less unsafe. E.g.
Builder
pattern, and less pub
members, to guarantee more data stays constant during the lifetime of the trace session. Because having non-mutable data is a requirement when accessing this data from a raw pointer (e.g. the one given by the ETW callback)TraceInfo
and EventTraceProperties
, or flatten some data from TraceInfo
into TraceData
, remove the fill_info()
functions, etc.Note that race 2 is rather likely. If CloseTrace
returns an ERROR_CTX_CLOSE_PENDING
, this means the callback will be invoked again, after we may be tempted to drop the closure.
Both races have been fixed, and fixes are included in ferrisetw 1.0
Race 1
There is no specific synchronization mechanism in
trace_callback_thunk()
. Which means a thread could be closing the trace session and destroying theTraceData
, just at the same time the last callback was triggered. And theevent_record.user_context
dereferenced in another thread, supposed to point to aTraceData
could be dangling hereRace 2
If a thread closes the trace session and destroys the
TraceData
, the associatedProvider
, hence the associatedcallbacks
, which are closures, are dropped. That's a problem in case a callback is still in progress (e.g. a callback is stuck in a blocking function call), because the closure may contain state (e.g. in amove ||
closure).Notes
krabsetw may have the same issues. See the issue in krabsetw