mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 16:47:31 -04:00
Merge pull request #142 from microsoft/fix-guid
Fix errors introduced with guid-by-value change
This commit is contained in:
@@ -46,7 +46,7 @@ func (addr *HvsockAddr) String() string {
|
|||||||
func VsockServiceID(port uint32) guid.GUID {
|
func VsockServiceID(port uint32) guid.GUID {
|
||||||
g, _ := guid.FromString("00000000-facb-11e6-bd58-64006a7986d3")
|
g, _ := guid.FromString("00000000-facb-11e6-bd58-64006a7986d3")
|
||||||
g.Data1 = port
|
g.Data1 = port
|
||||||
return *g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (addr *HvsockAddr) raw() rawHvsockAddr {
|
func (addr *HvsockAddr) raw() rawHvsockAddr {
|
||||||
|
|||||||
+4
-4
@@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
type eventOptions struct {
|
type eventOptions struct {
|
||||||
descriptor *eventDescriptor
|
descriptor *eventDescriptor
|
||||||
activityID *guid.GUID
|
activityID guid.GUID
|
||||||
relatedActivityID *guid.GUID
|
relatedActivityID guid.GUID
|
||||||
tags uint32
|
tags uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +59,14 @@ func WithTags(newTags uint32) EventOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithActivityID specifies the activity ID of the event to be written.
|
// WithActivityID specifies the activity ID of the event to be written.
|
||||||
func WithActivityID(activityID *guid.GUID) EventOpt {
|
func WithActivityID(activityID guid.GUID) EventOpt {
|
||||||
return func(options *eventOptions) {
|
return func(options *eventOptions) {
|
||||||
options.activityID = activityID
|
options.activityID = activityID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithRelatedActivityID specifies the parent activity ID of the event to be written.
|
// WithRelatedActivityID specifies the parent activity ID of the event to be written.
|
||||||
func WithRelatedActivityID(activityID *guid.GUID) EventOpt {
|
func WithRelatedActivityID(activityID guid.GUID) EventOpt {
|
||||||
return func(options *eventOptions) {
|
return func(options *eventOptions) {
|
||||||
options.relatedActivityID = activityID
|
options.relatedActivityID = activityID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
// provider ID to be manually specified. This is most useful when there is an
|
// provider ID to be manually specified. This is most useful when there is an
|
||||||
// existing provider ID that must be used to conform to existing diagnostic
|
// existing provider ID that must be used to conform to existing diagnostic
|
||||||
// infrastructure.
|
// infrastructure.
|
||||||
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) {
|
func NewProviderWithID(name string, id guid.GUID, callback EnableCallback) (provider *Provider, err error) {
|
||||||
providerCallbackOnce.Do(func() {
|
providerCallbackOnce.Do(func() {
|
||||||
globalProviderCallback = windows.NewCallback(providerCallbackAdapter)
|
globalProviderCallback = windows.NewCallback(providerCallbackAdapter)
|
||||||
})
|
})
|
||||||
@@ -29,7 +29,7 @@ func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (pro
|
|||||||
provider.ID = id
|
provider.ID = id
|
||||||
provider.callback = callback
|
provider.callback = callback
|
||||||
|
|
||||||
if err := eventRegister((*windows.GUID)(provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil {
|
if err := eventRegister((*windows.GUID)(&provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewProviderWithID returns a nil provider on unsupported platforms.
|
// NewProviderWithID returns a nil provider on unsupported platforms.
|
||||||
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) {
|
func NewProviderWithID(name string, id guid.GUID, callback EnableCallback) (provider *Provider, err error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -14,7 +14,7 @@ import (
|
|||||||
// name and ID (GUID), which should always have a 1:1 mapping to each other
|
// name and ID (GUID), which should always have a 1:1 mapping to each other
|
||||||
// (e.g. don't use multiple provider names with the same ID, or vice versa).
|
// (e.g. don't use multiple provider names with the same ID, or vice versa).
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
ID *guid.GUID
|
ID guid.GUID
|
||||||
handle providerHandle
|
handle providerHandle
|
||||||
metadata []byte
|
metadata []byte
|
||||||
callback EnableCallback
|
callback EnableCallback
|
||||||
@@ -61,9 +61,9 @@ const (
|
|||||||
|
|
||||||
// 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(*guid.GUID, ProviderState, Level, uint64, uint64, uintptr)
|
type EnableCallback func(guid.GUID, ProviderState, Level, uint64, uint64, uintptr)
|
||||||
|
|
||||||
func providerCallback(sourceID *guid.GUID, state ProviderState, level Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr, i uintptr) {
|
func providerCallback(sourceID guid.GUID, state ProviderState, level Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr, i uintptr) {
|
||||||
provider := providers.getProvider(uint(i))
|
provider := providers.getProvider(uint(i))
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
@@ -86,7 +86,7 @@ func providerCallback(sourceID *guid.GUID, state ProviderState, level Level, mat
|
|||||||
// different size, it has only pointer-sized arguments, which are then cast to
|
// different size, it has only pointer-sized arguments, which are then cast to
|
||||||
// the appropriate types when calling providerCallback.
|
// the appropriate types when calling providerCallback.
|
||||||
func providerCallbackAdapter(sourceID *guid.GUID, state uintptr, level uintptr, matchAnyKeyword uintptr, matchAllKeyword uintptr, filterData uintptr, i uintptr) uintptr {
|
func providerCallbackAdapter(sourceID *guid.GUID, state uintptr, level uintptr, matchAnyKeyword uintptr, matchAllKeyword uintptr, filterData uintptr, i uintptr) uintptr {
|
||||||
providerCallback(sourceID, ProviderState(state), Level(level), uint64(matchAnyKeyword), uint64(matchAllKeyword), filterData, i)
|
providerCallback(*sourceID, ProviderState(state), Level(level), uint64(matchAnyKeyword), uint64(matchAllKeyword), filterData, i)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ func providerCallbackAdapter(sourceID *guid.GUID, state uintptr, level uintptr,
|
|||||||
// The algorithm is roughly:
|
// The algorithm is roughly:
|
||||||
// Hash = Sha1(namespace + arg.ToUpper().ToUtf16be())
|
// Hash = Sha1(namespace + arg.ToUpper().ToUtf16be())
|
||||||
// Guid = Hash[0..15], with Hash[7] tweaked according to RFC 4122
|
// Guid = Hash[0..15], with Hash[7] tweaked according to RFC 4122
|
||||||
func providerIDFromName(name string) *guid.GUID {
|
func providerIDFromName(name string) guid.GUID {
|
||||||
buffer := sha1.New()
|
buffer := sha1.New()
|
||||||
|
|
||||||
namespace := []byte{0x48, 0x2C, 0x2D, 0xB2, 0xC3, 0x90, 0x47, 0xC8, 0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB}
|
namespace := []byte{0x48, 0x2C, 0x2D, 0xB2, 0xC3, 0x90, 0x47, 0xC8, 0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB}
|
||||||
@@ -108,7 +108,7 @@ func providerIDFromName(name string) *guid.GUID {
|
|||||||
sum := buffer.Sum(nil)
|
sum := buffer.Sum(nil)
|
||||||
sum[7] = (sum[7] & 0xf) | 0x50
|
sum[7] = (sum[7] & 0xf) | 0x50
|
||||||
|
|
||||||
return &guid.GUID{
|
return guid.GUID{
|
||||||
Data1: binary.LittleEndian.Uint32(sum[0:4]),
|
Data1: binary.LittleEndian.Uint32(sum[0:4]),
|
||||||
Data2: binary.LittleEndian.Uint16(sum[4:6]),
|
Data2: binary.LittleEndian.Uint16(sum[4:6]),
|
||||||
Data3: binary.LittleEndian.Uint16(sum[6:8]),
|
Data3: binary.LittleEndian.Uint16(sum[6:8]),
|
||||||
@@ -219,8 +219,8 @@ func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpt
|
|||||||
// the ETW infrastructure.
|
// the ETW infrastructure.
|
||||||
func (provider *Provider) writeEventRaw(
|
func (provider *Provider) writeEventRaw(
|
||||||
descriptor *eventDescriptor,
|
descriptor *eventDescriptor,
|
||||||
activityID *guid.GUID,
|
activityID guid.GUID,
|
||||||
relatedActivityID *guid.GUID,
|
relatedActivityID guid.GUID,
|
||||||
metadataBlobs [][]byte,
|
metadataBlobs [][]byte,
|
||||||
dataBlobs [][]byte) error {
|
dataBlobs [][]byte) error {
|
||||||
|
|
||||||
@@ -235,5 +235,5 @@ func (provider *Provider) writeEventRaw(
|
|||||||
dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob))
|
dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob))
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(activityID), (*windows.GUID)(relatedActivityID), dataDescriptorCount, &dataDescriptors[0])
|
return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(&activityID), (*windows.GUID)(&relatedActivityID), dataDescriptorCount, &dataDescriptors[0])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func callback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
|
func callback(sourceID guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
|
||||||
fmt.Printf("Callback: isEnabled=%d, level=%d, matchAnyKeyword=%d\n", state, level, matchAnyKeyword)
|
fmt.Printf("Callback: isEnabled=%d, level=%d, matchAnyKeyword=%d\n", state, level, matchAnyKeyword)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user