mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 16:47:31 -04:00
Set ETW provider info so it's always treated as TraceLogging
Signed-off-by: Kevin Parsons <kevpar@ntdev.microsoft.com>
This commit is contained in:
@@ -12,3 +12,4 @@ package etw
|
|||||||
//sys eventRegister(providerId *windows.GUID, callback uintptr, callbackContext uintptr, providerHandle *providerHandle) (win32err error) = advapi32.EventRegister
|
//sys eventRegister(providerId *windows.GUID, callback uintptr, callbackContext uintptr, providerHandle *providerHandle) (win32err error) = advapi32.EventRegister
|
||||||
//sys eventUnregister(providerHandle providerHandle) (win32err error) = advapi32.EventUnregister
|
//sys eventUnregister(providerHandle providerHandle) (win32err error) = advapi32.EventUnregister
|
||||||
//sys eventWriteTransfer(providerHandle providerHandle, descriptor *EventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) = advapi32.EventWriteTransfer
|
//sys eventWriteTransfer(providerHandle providerHandle, descriptor *EventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) = advapi32.EventWriteTransfer
|
||||||
|
//sys eventSetInformation(providerHandle providerHandle, class eventInfoClass, information uintptr, length uint32) (win32err error) = advapi32.EventSetInformation
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ func WithKeyword(keyword uint64) EventOpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithChannel(channel Channel) EventOpt {
|
||||||
|
return func(options *eventOptions) {
|
||||||
|
options.descriptor.Channel = channel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithTags specifies the tags of the event to be written. Tags is a 28-bit
|
// WithTags specifies the tags of the event to be written. Tags is a 28-bit
|
||||||
// value (top 4 bits are ignored) which are interpreted by the event consumer.
|
// value (top 4 bits are ignored) which are interpreted by the event consumer.
|
||||||
func WithTags(newTags uint32) EventOpt {
|
func WithTags(newTags uint32) EventOpt {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
@@ -41,6 +42,15 @@ const (
|
|||||||
ProviderStateCaptureState
|
ProviderStateCaptureState
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type eventInfoClass uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
eventInfoClassProviderBinaryTrackInfo eventInfoClass = iota
|
||||||
|
eventInfoClassProviderSetReserved1
|
||||||
|
eventInfoClassProviderSetTraits
|
||||||
|
eventInfoClassProviderUseDescriptorType
|
||||||
|
)
|
||||||
|
|
||||||
// EnableCallback is the form of the callback function that receives provider
|
// EnableCallback is the form of the callback function that receives provider
|
||||||
// enable/disable notifications from ETW.
|
// enable/disable notifications from ETW.
|
||||||
type EnableCallback func(*windows.GUID, ProviderState, Level, uint64, uint64, uintptr)
|
type EnableCallback func(*windows.GUID, ProviderState, Level, uint64, uint64, uintptr)
|
||||||
@@ -133,6 +143,15 @@ func NewProviderWithID(name string, id *windows.GUID, callback EnableCallback) (
|
|||||||
binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer
|
binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer
|
||||||
provider.metadata = metadata.Bytes()
|
provider.metadata = metadata.Bytes()
|
||||||
|
|
||||||
|
if err := eventSetInformation(
|
||||||
|
provider.handle,
|
||||||
|
eventInfoClassProviderSetTraits,
|
||||||
|
uintptr(unsafe.Pointer(&provider.metadata[0])),
|
||||||
|
uint32(len(provider.metadata))); err != nil {
|
||||||
|
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return provider, nil
|
return provider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ var (
|
|||||||
procEventRegister = modadvapi32.NewProc("EventRegister")
|
procEventRegister = modadvapi32.NewProc("EventRegister")
|
||||||
procEventUnregister = modadvapi32.NewProc("EventUnregister")
|
procEventUnregister = modadvapi32.NewProc("EventUnregister")
|
||||||
procEventWriteTransfer = modadvapi32.NewProc("EventWriteTransfer")
|
procEventWriteTransfer = modadvapi32.NewProc("EventWriteTransfer")
|
||||||
|
procEventSetInformation = modadvapi32.NewProc("EventSetInformation")
|
||||||
)
|
)
|
||||||
|
|
||||||
func eventRegister(providerId *windows.GUID, callback uintptr, callbackContext uintptr, providerHandle *providerHandle) (win32err error) {
|
func eventRegister(providerId *windows.GUID, callback uintptr, callbackContext uintptr, providerHandle *providerHandle) (win32err error) {
|
||||||
@@ -67,3 +68,11 @@ func eventWriteTransfer(providerHandle providerHandle, descriptor *EventDescript
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func eventSetInformation(providerHandle providerHandle, class eventInfoClass, information uintptr, length uint32) (win32err error) {
|
||||||
|
r0, _, _ := syscall.Syscall6(procEventSetInformation.Addr(), 4, uintptr(providerHandle), uintptr(class), uintptr(information), uintptr(length), 0, 0)
|
||||||
|
if r0 != 0 {
|
||||||
|
win32err = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user