forked from bi-zone/etw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
session.go
658 lines (583 loc) · 21.4 KB
/
session.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
//go:build windows
// +build windows
// Package etw allows you to receive Event Tracing for Windows (ETW) events.
//
// etw allows you to process events from new TraceLogging providers as well as
// from classic (aka EventLog) providers, so you could actually listen to
// anything you can see in Event Viewer window.
//
// For possible usage examples take a look at
// https://github.com/bi-zone/etw/tree/master/examples
package etw
import (
"fmt"
"math"
"math/rand"
"sync"
"sync/atomic"
"time"
"unsafe"
"golang.org/x/sys/windows"
)
// ExistsError is returned by NewSession if the session name is already taken.
//
// Having ExistsError you have an option to force kill the session:
//
// var exists etw.ExistsError
// s, err = etw.NewSession(s.guid, etw.WithName(sessionName))
// if errors.As(err, &exists) {
// err = etw.KillSession(exists.SessionName)
// }
type ExistsError struct{ SessionName string }
func (e ExistsError) Error() string {
return fmt.Sprintf("session %q already exist", e.SessionName)
}
// Session represents a Windows event tracing session that is ready to start
// events processing. Session subscribes to the given ETW provider only on
// `.Process` call, so having a Session without `.Process` called should not
// affect OS performance.
//
// Session should be closed via `.Close` call to free obtained OS resources
// even if `.Process` has never been called.
type Session struct {
guids []windows.GUID
config SessionOptions
callback EventCallback
etwSessionName []uint16
hSession uint64
propertiesBuf []byte
processedEvents uint64
}
// EventCallback is any function that could handle an ETW event. EventCallback
// is called synchronously and sequentially on every event received by Session
// one by one.
//
// If EventCallback can't handle all ETW events produced, OS will handle a
// tricky file-based cache for you, however, it's recommended not to perform
// long-running tasks inside a callback.
//
// N.B. Event pointer @e is valid ONLY inside a callback. You CAN'T copy a
// whole event, only EventHeader, EventProperties and ExtendedEventInfo
// separately.
type EventCallback func(e *Event)
// NewSession creates a Windows event tracing session instance. Session with no
// options provided is a usable session, but it could be a bit noisy. It's
// recommended to refine the session with level and match keywords options
// to get rid of unnecessary events.
//
// You MUST call `.Close` on session after use to clear associated resources,
// otherwise it will leak in OS internals until system reboot.
func NewSession(options ...SessionOption) (*Session, error) {
defaultConfig := SessionOptions{
Name: "go-etw-" + randomName(),
}
for _, opt := range options {
opt(&defaultConfig)
}
s := Session{
config: defaultConfig,
}
if err := s.createETWSession(); err != nil {
return nil, err
}
// TODO: consider setting a finalizer with .Close
return &s, nil
}
// Update updates the session options with the new options.
// It is not possible to update the name of a session.
// Changing log file modes may also fail.
func (s *Session) Update(options ...SessionOption) error {
var newConfig SessionOptions
for _, opt := range options {
opt(&newConfig)
}
return s.updateSessionProperties(newConfig)
}
// AddProvider adds a provider to the session. This can also be used to change subscription parameters.
func (s *Session) AddProvider(providerGUID windows.GUID, options ...ProviderOption) error {
defaultConfig := ProviderOptions{
Level: TRACE_LEVEL_VERBOSE,
}
for _, opt := range options {
opt(&defaultConfig)
}
if err := s.subscribeToProvider(providerGUID, defaultConfig); err != nil {
return fmt.Errorf("failed to subscribe to provider; %w", err)
}
s.guids = append(s.guids, providerGUID)
return nil
}
// Process starts processing of ETW events. Events will be passed to @cb
// synchronously and sequentially. Take a look to EventCallback documentation
// for more info about events processing.
//
// N.B. Process blocks until `.Close` being called!
func (s *Session) Process(cb EventCallback) error {
s.callback = cb
callbackKey := newCallbackKey(s)
defer freeCallbackKey(callbackKey)
// Will block here until being closed.
if err := s.processEvents(callbackKey); err != nil {
return fmt.Errorf("error processing events; %w", err)
}
return nil
}
type SessionStatistics struct {
LostEvents uint64
ProcessedEvents uint64
}
// Stat queries runtime information about the session.
func (s *Session) Stat() (SessionStatistics, error) {
sessionProperties, err := s.querySessionDetails()
if err != nil {
return SessionStatistics{}, fmt.Errorf("could not query session details: %w", err)
}
return SessionStatistics{
LostEvents: uint64(sessionProperties.EventsLost),
ProcessedEvents: s.processedEvents,
}, nil
}
// Close stops trace session and frees associated resources.
func (s *Session) Close() error {
// "Be sure to disable all providers before stopping the session."
// https://docs.microsoft.com/en-us/windows/win32/etw/configuring-and-starting-an-event-tracing-session
if err := s.unsubscribeFromProviders(); err != nil {
s.stopSession()
return fmt.Errorf("failed to disable provider; %w", err)
}
if err := s.stopSession(); err != nil {
return fmt.Errorf("failed to stop session; %w", err)
}
return nil
}
const (
eventTraceControlQuery = 0
eventTraceControlStop = 1
eventTraceControlUpdate = 2
eventTraceControlFlush = 3
eventTraceControlIncrementFile = 4
)
// KillSession forces the session with a given @name to stop. Don't having a
// session handle we can't shutdown it gracefully unsubscribing from all the
// providers first, so we just stop the session itself.
//
// Use KillSession only to destroy session you've lost control over. If you
// have a session handle always prefer `.Close`.
func KillSession(name string) error {
nameUTF16, err := windows.UTF16FromString(name)
if err != nil {
return fmt.Errorf("failed to convert session name to utf16; %w", err)
}
sessionNameLength := len(nameUTF16) * int(unsafe.Sizeof(nameUTF16[0]))
//
// For a graceful shutdown we should unsubscribe from all providers associated
// with the session, but we can't find a way to query them using WinAPI.
// So we just ask the session to stop and hope that wont hurt anything too bad.
//
// We don't know if this session was opened with the log file or not
// (session could be opened without our library) so allocate memory for LogFile name too.
const maxLengthLogfileName = 1024
bufSize := int(unsafe.Sizeof(eventTraceProperties{})) + sessionNameLength + maxLengthLogfileName
propertiesBuf := make([]byte, bufSize)
pProperties := (*eventTraceProperties)(unsafe.Pointer(&propertiesBuf[0]))
pProperties.Wnode.BufferSize = uint32(bufSize)
err = controlTrace(
0,
&nameUTF16[0],
pProperties,
eventTraceControlStop,
)
// If you receive ERROR_MORE_DATA when stopping the session, ETW will have
// already stopped the session before generating this error.
// https://docs.microsoft.com/en-us/windows/win32/api/evntrace/nf-evntrace-controltracew
if err == windows.ERROR_MORE_DATA {
err = nil
}
return err
}
const (
eventTraceRealTimeMode = 0x00000100
)
func (s *Session) generateTraceProperties(config SessionOptions) []byte {
var logFileMode uint32
for _, mode := range config.LogFileModes {
if !(mode == EVENT_TRACE_SYSTEM_LOGGER_MODE && getWindowsVersion() <= windows7) {
logFileMode |= uint32(mode)
}
}
// Mark that we are going to process events in real time using a callback.
logFileMode |= eventTraceRealTimeMode
// We need to allocate a sequential buffer for a structure and a session name
// which will be placed there by an API call (for the future calls).
//
// (Ref: https://docs.microsoft.com/en-us/windows/win32/etw/wnode-header#members)
//
// The only way to do it in go -- unsafe cast of the allocated memory.
sessionNameSize := len(s.etwSessionName) * int(unsafe.Sizeof(s.etwSessionName[0]))
bufSize := int(unsafe.Sizeof(eventTraceProperties{})) + sessionNameSize
propertiesBuf := make([]byte, bufSize)
// We will use Query Performance Counter for timestamp cos it gives us higher
// time resolution. Event timestamps however would be converted to the common
// FileTime due to absence of PROCESS_TRACE_MODE_RAW_TIMESTAMP in LogFileMode.
//
// Ref: https://docs.microsoft.com/en-us/windows/win32/api/evntrace/ns-evntrace-event_trace_properties
pProperties := (*eventTraceProperties)(unsafe.Pointer(&propertiesBuf[0]))
pProperties.Wnode.BufferSize = uint32(bufSize)
pProperties.Wnode.ClientContext = 1 // QPC for event Timestamp
pProperties.Wnode.Flags = wnodeFlagTracedGuid
pProperties.MaximumFileSize = config.MaximumFileSize
pProperties.LogFileMode = logFileMode
var enableFlags uint32
for _, flag := range config.Flags {
if !traceSetInformationFlags[flag] {
enableFlags |= uint32(flag)
}
}
pProperties.EnableFlags = enableFlags
return propertiesBuf
}
// createETWSession wraps StartTraceW.
func (s *Session) createETWSession() error {
utf16Name, err := windows.UTF16FromString(s.config.Name)
if err != nil {
return fmt.Errorf("incorrect session name; %w", err) // unlikely
}
s.etwSessionName = utf16Name
for _, mode := range s.config.LogFileModes {
if mode == EVENT_TRACE_SYSTEM_LOGGER_MODE && getWindowsVersion() <= windows7 {
// We are on Windows 7 or older. These versions do not support EVENT_TRACE_SYSTEM_LOGGER_MODE
// and instead requires usage of the global kernel logger session.
s.etwSessionName, _ = windows.UTF16FromString(kernelLoggerName)
}
}
propertiesBuf := s.generateTraceProperties(s.config)
err = startTrace(&s.hSession, &s.etwSessionName[0], unsafe.Pointer(&propertiesBuf[0]))
if err != nil {
if err == windows.ERROR_ALREADY_EXISTS {
return ExistsError{SessionName: s.config.Name}
}
return fmt.Errorf("StartTraceW failed; %w", err)
}
s.propertiesBuf = propertiesBuf
if err := s.setEnableFlags(s.config.Flags); err != nil {
s.Close()
return fmt.Errorf("failed to set flags; %w", err)
}
return nil
}
func (s *Session) setEnableFlags(flags []EnableFlag) error {
var activateRundown bool
var traceSetInfoFlags uint32
for _, flag := range flags {
if traceSetInformationFlags[flag] {
traceSetInfoFlags |= uint32(flag)
}
if flag == EVENT_TRACE_FLAG_RUNDOWN {
activateRundown = true
}
}
if traceSetInfoFlags == 0 && !activateRundown {
return nil
}
var masks perfinfoGroupmask
err := traceQueryInformation(
s.hSession,
traceSystemTraceEnableFlagsInfo,
unsafe.Pointer(&masks),
uint32(unsafe.Sizeof(masks)),
nil,
)
if err != nil {
return fmt.Errorf("TraceQueryInformation failed; %w", err)
}
if activateRundown {
var emptyMask perfinfoGroupmask
err := traceSetInformation(
s.hSession,
traceSystemTraceEnableFlagsInfo,
unsafe.Pointer(&emptyMask),
uint32(unsafe.Sizeof(emptyMask)),
)
if err != nil {
return fmt.Errorf("TraceSetInformation failed; %w", err)
}
}
masks[4] = traceSetInfoFlags
err = traceSetInformation(
s.hSession,
traceSystemTraceEnableFlagsInfo,
unsafe.Pointer(&masks),
uint32(unsafe.Sizeof(masks)),
)
if err != nil {
return fmt.Errorf("TraceSetInformation failed; %w", err)
}
return nil
}
type perfinfoGroupmask [8]uint32
func (s *Session) updateSessionProperties(config SessionOptions) error {
propertiesBuf := s.generateTraceProperties(config)
err := controlTrace(
s.hSession,
&s.etwSessionName[0],
(*eventTraceProperties)(unsafe.Pointer(&propertiesBuf[0])),
eventTraceControlUpdate,
)
if err != nil {
return fmt.Errorf("ControlTraceW failed; %w", err)
}
if err := s.setEnableFlags(config.Flags); err != nil {
// Try to revert changes made with ControlTraceW
// by reverting to the old, stored propertiesBuf
_ = controlTrace(
s.hSession,
&s.etwSessionName[0],
(*eventTraceProperties)(unsafe.Pointer(&propertiesBuf[0])),
eventTraceControlUpdate,
)
return fmt.Errorf("failed to set flags; %w", err)
}
s.propertiesBuf = propertiesBuf
s.config = config
return nil
}
const (
eventControlCodeDisableProvider = 0
eventControlCodeEnableProvider = 1
eventControlCodeCaptureState = 2
)
// subscribeToProvider wraps EnableTraceEx2 with EVENT_CONTROL_CODE_ENABLE_PROVIDER.
func (s *Session) subscribeToProvider(provider windows.GUID, options ProviderOptions) error {
// https://docs.microsoft.com/en-us/windows/win32/etw/configuring-and-starting-an-event-tracing-session
var params enableTraceParameters
params.Version = 2 // ENABLE_TRACE_PARAMETERS_VERSION_2
for _, p := range options.EnableProperties {
params.EnableProperty |= uint32(p)
}
if len(options.Filters) > 0 {
filtersByType := map[EventFilterType]EventFilter{}
for _, filter := range options.Filters {
filterType := filter.Type()
if existingFilter, typeExists := filtersByType[filterType]; typeExists {
newFilter, err := filter.Merge(existingFilter)
if err != nil {
return fmt.Errorf("could not add filter: %w", err)
}
filtersByType[filterType] = newFilter
} else {
filtersByType[filterType] = filter
}
}
filterDescriptors := make([]eventFilterDescriptorC, len(filtersByType))
var index int
for _, filter := range filtersByType {
descriptor, err := filter.EventFilterDescriptor()
if err != nil {
return err
}
if descriptor.Close != nil {
defer descriptor.Close()
}
filterDescriptors[index] = descriptor.Descriptor
index++
}
params.EnableFilterDesc = &filterDescriptors[0]
params.FilterDescCount = uint32(len(filterDescriptors))
}
err := enableTraceEx2(
s.hSession,
&provider,
eventControlCodeEnableProvider,
options.Level,
options.MatchAnyKeyword,
options.MatchAllKeyword,
0, // Timeout set to zero to enable the trace asynchronously
¶ms,
)
if err != nil {
return fmt.Errorf("EVENT_CONTROL_CODE_ENABLE_PROVIDER failed for GUID %s; %w", provider, err)
}
if options.TriggerRundown {
err := enableTraceEx2(
s.hSession,
&provider,
eventControlCodeCaptureState,
options.Level,
options.MatchAnyKeyword,
options.MatchAllKeyword,
0,
¶ms,
)
if err != nil {
return fmt.Errorf("EVENT_CONTROL_CODE_CAPTURE_STATE failed for GUID %s; %w", provider, err)
}
}
return nil
}
// unsubscribeFromProviders wraps EnableTraceEx2 with EVENT_CONTROL_CODE_DISABLE_PROVIDER.
func (s *Session) unsubscribeFromProviders() error {
var lastError error
for _, guid := range s.guids {
err := enableTraceEx2(
s.hSession,
&guid,
eventControlCodeDisableProvider,
0,
0,
0,
0,
nil,
)
if err != nil && err != windows.ERROR_NOT_FOUND {
lastError = fmt.Errorf("EVENT_CONTROL_CODE_DISABLE_PROVIDER failed for GUID %s; %w", guid, err)
}
}
return lastError
}
const (
invalidTraceHandle = uint64(windows.InvalidHandle)
)
// processEvents subscribes to the actual provider events and starts its processing.
func (s *Session) processEvents(callbackContextKey uintptr) error {
// Ref: https://docs.microsoft.com/en-us/windows/win32/api/evntrace/nf-evntrace-opentracew
var trace eventTraceLogfile
trace.LoggerName = &s.etwSessionName[0]
trace.Context = callbackContextKey
trace.ProcessTraceMode = processTraceModeRealTime | processTraceModeEventRecord
trace.EventCallback = handleEventStdcall
traceHandle, err := openTrace(&trace)
if err != nil {
return fmt.Errorf("OpenTraceW failed; %w", err)
}
defer closeTrace(traceHandle)
// BLOCKS UNTIL CLOSED!
err = processTrace(&traceHandle, 1, nil, nil)
if err != nil && err != windows.ERROR_CANCELLED { // Cancelled is obviously ok when we block until closing.
return fmt.Errorf("ProcessTrace failed; %w", err)
}
return nil
}
// stopSession wraps ControlTraceW with EVENT_TRACE_CONTROL_STOP.
func (s *Session) stopSession() error {
err := controlTrace(
s.hSession,
nil,
(*eventTraceProperties)(unsafe.Pointer(&s.propertiesBuf[0])),
eventTraceControlStop,
)
// If you receive ERROR_MORE_DATA when stopping the session, ETW will have
// already stopped the session before generating this error.
// https://docs.microsoft.com/en-us/windows/win32/api/evntrace/nf-evntrace-controltracew
if err == windows.ERROR_MORE_DATA {
err = nil
}
return err
}
// stopSession wraps ControlTraceW with EVENT_TRACE_CONTROL_STOP.
func (s *Session) querySessionDetails() (*eventTraceProperties, error) {
// Allocate a buffer for EVENT_TRACE_PROPERTIES and up to 2 names with up to 1024 chars behind it
bufSize := int(unsafe.Sizeof(eventTraceProperties{}) + 2*1024)
propertiesBuf := make([]byte, bufSize)
// We will use Query Performance Counter for timestamp cos it gives us higher
// time resolution. Event timestamps however would be converted to the common
// FileTime due to absence of PROCESS_TRACE_MODE_RAW_TIMESTAMP in LogFileMode.
//
// Ref: https://docs.microsoft.com/en-us/windows/win32/api/evntrace/ns-evntrace-event_trace_properties
pProperties := (*eventTraceProperties)(unsafe.Pointer(&propertiesBuf[0]))
pProperties.Wnode.BufferSize = uint32(bufSize)
pProperties.LoggerNameOffset = uint32(unsafe.Sizeof(eventTraceProperties{}))
pProperties.LogFileNameOffset = uint32(unsafe.Sizeof(eventTraceProperties{}) + 1024)
err := controlTrace(
s.hSession,
nil,
(*eventTraceProperties)(unsafe.Pointer(&s.propertiesBuf[0])),
eventTraceControlQuery,
)
if err != nil {
return nil, err
}
return pProperties, nil
}
func randomName() string {
if g, err := windows.GenerateGUID(); err == nil {
return g.String()
}
// should be almost impossible, right?
rand.Seed(time.Now().UnixNano())
const alph = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, 32)
for i := range b {
b[i] = alph[rand.Intn(len(alph))]
}
return string(b)
}
// We can't pass Go-land pointers to the C-world so we use a classical trick
// storing real pointers inside global map and passing to C "fake pointers"
// which are actually map keys.
//
//nolint:gochecknoglobals
var (
sessions sync.Map
sessionCounter uintptr
)
// newCallbackKey stores a @ptr inside a global storage returning its' key.
// After use the key should be freed using `freeCallbackKey`.
func newCallbackKey(ptr *Session) uintptr {
key := atomic.AddUintptr(&sessionCounter, 1)
sessions.Store(key, ptr)
return key
}
func freeCallbackKey(key uintptr) {
sessions.Delete(key)
}
var handleEventStdcall = windows.NewCallback(handleEvent)
// handleEvent handles an incoming ETW event. The session is determined by the UserContext key.
func handleEvent(eventRecord *eventRecordC) uintptr {
key := eventRecord.UserContext
targetSession, ok := sessions.Load(key)
if !ok {
return 0
}
session := targetSession.(*Session)
evt := &Event{
Header: eventHeaderToGo(eventRecord.EventHeader),
eventRecord: eventRecord,
ignoreMapInfo: session.config.IgnoreMapInfo,
}
session.callback(evt)
session.processedEvents++
evt.eventRecord = nil
return 0
}
func eventHeaderToGo(header eventHeaderC) EventHeader {
return EventHeader{
EventDescriptor: header.EventDescriptor,
ThreadID: header.ThreadId,
ProcessID: header.ProcessId,
TimeStamp: stampToTime(header.Timestamp),
ProviderID: header.ProviderId,
ActivityID: header.ActivityId,
Flags: header.Flags,
KernelTime: header.KernelTime,
UserTime: header.UserTime,
ProcessorTime: uint64(header.KernelTime) + uint64(header.UserTime)<<32,
}
}
// stampToTime translates FileTime to a golang time. Same as in standard packages.
func stampToTime(quadPart uint64) time.Time {
ft := windows.Filetime{
HighDateTime: uint32(quadPart >> 32),
LowDateTime: uint32(quadPart & math.MaxUint32),
}
return time.Unix(0, ft.Nanoseconds())
}
//sys startTrace(sessionHandle *uint64, sessionName *uint16, traceProperties unsafe.Pointer) (ret error) = advapi32.StartTraceW
//sys processTrace(handleArray *uint64, handleCount uint32, startTime *windows.Filetime, endTime *windows.Filetime) (ret error) = advapi32.ProcessTrace
//sys traceQueryInformation_64(sessionHandle uint64, infoClass traceQueryInfoClass, buffer unsafe.Pointer, bufferSize uint32, returnLength *uint32) (ret error) = advapi32.TraceQueryInformation
//sys traceQueryInformation_32(sessionHandleLower uint32, sessionHandleHigher uint32, infoClass traceQueryInfoClass, buffer unsafe.Pointer, bufferSize uint32, returnLength *uint32) (ret error) = advapi32.TraceQueryInformation
//sys traceSetInformation_64(sessionHandle uint64, infoClass traceQueryInfoClass, buffer unsafe.Pointer, bufferSize uint32) (ret error) = advapi32.TraceSetInformation
//sys traceSetInformation_32(sessionHandleLower uint32, sessionHandleHigher uint32, infoClass traceQueryInfoClass, buffer unsafe.Pointer, bufferSize uint32) (ret error) = advapi32.TraceSetInformation
//sys controlTrace_64(sessionHandle uint64, instanceName *uint16, properties *eventTraceProperties, controlCode uint32) (ret error) = advapi32.ControlTraceW
//sys controlTrace_32(sessionHandleLower uint32, sessionHandleHigher uint32, instanceName *uint16, properties *eventTraceProperties, controlCode uint32) (ret error) = advapi32.ControlTraceW
//sys enableTraceEx2_64(sessionHandle uint64, providerGuid *windows.GUID, controlCode uint32, level TraceLevel, matchAnyKeyword uint64, matchAllKeyword uint64, timeout uint32, enableParameters *enableTraceParameters) (ret error) = advapi32.EnableTraceEx2
//sys enableTraceEx2_32(sessionHandleLower uint32, sessionHandleHigher uint32, providerGuid *windows.GUID, controlCode uint32, level TraceLevel, matchAnyKeywordLower uint32, matchAnyKeywordHigher uint32, matchAllKeywordLower uint32, matchAllKeywordHigher uint32, timeout uint32, enableParameters *enableTraceParameters) (ret error) = advapi32.EnableTraceEx2