From a2a7cd6b7d9f8b079b910d0a8c21a1e9968df090 Mon Sep 17 00:00:00 2001 From: Kevin Parsons Date: Wed, 8 May 2019 16:43:22 -0700 Subject: [PATCH] Fix errors introduced with guid-by-value change Signed-off-by: Kevin Parsons --- hvsock.go | 2 +- pkg/etw/eventopt.go | 8 ++++---- pkg/etw/newprovider.go | 4 ++-- pkg/etw/newprovider_unsupported.go | 2 +- pkg/etw/provider.go | 18 +++++++++--------- pkg/etw/sample/sample.go | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hvsock.go b/hvsock.go index 29389ef..dbfe790 100644 --- a/hvsock.go +++ b/hvsock.go @@ -46,7 +46,7 @@ func (addr *HvsockAddr) String() string { func VsockServiceID(port uint32) guid.GUID { g, _ := guid.FromString("00000000-facb-11e6-bd58-64006a7986d3") g.Data1 = port - return *g + return g } func (addr *HvsockAddr) raw() rawHvsockAddr { diff --git a/pkg/etw/eventopt.go b/pkg/etw/eventopt.go index a0a8176..fb6ac7d 100644 --- a/pkg/etw/eventopt.go +++ b/pkg/etw/eventopt.go @@ -6,8 +6,8 @@ import ( type eventOptions struct { descriptor *eventDescriptor - activityID *guid.GUID - relatedActivityID *guid.GUID + activityID guid.GUID + relatedActivityID guid.GUID tags uint32 } @@ -59,14 +59,14 @@ func WithTags(newTags uint32) EventOpt { } // 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) { options.activityID = activityID } } // 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) { options.relatedActivityID = activityID } diff --git a/pkg/etw/newprovider.go b/pkg/etw/newprovider.go index bf82fa5..f344fb6 100644 --- a/pkg/etw/newprovider.go +++ b/pkg/etw/newprovider.go @@ -15,7 +15,7 @@ import ( // 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 // 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() { globalProviderCallback = windows.NewCallback(providerCallbackAdapter) }) @@ -29,7 +29,7 @@ func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (pro provider.ID = id 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 } diff --git a/pkg/etw/newprovider_unsupported.go b/pkg/etw/newprovider_unsupported.go index 43b8142..808455c 100644 --- a/pkg/etw/newprovider_unsupported.go +++ b/pkg/etw/newprovider_unsupported.go @@ -7,6 +7,6 @@ import ( ) // 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 } diff --git a/pkg/etw/provider.go b/pkg/etw/provider.go index f71dc7c..28db0d5 100644 --- a/pkg/etw/provider.go +++ b/pkg/etw/provider.go @@ -14,7 +14,7 @@ import ( // 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). type Provider struct { - ID *guid.GUID + ID guid.GUID handle providerHandle metadata []byte callback EnableCallback @@ -61,9 +61,9 @@ const ( // EnableCallback is the form of the callback function that receives provider // 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)) 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 // the appropriate types when calling providerCallback. 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 } @@ -97,7 +97,7 @@ func providerCallbackAdapter(sourceID *guid.GUID, state uintptr, level uintptr, // The algorithm is roughly: // Hash = Sha1(namespace + arg.ToUpper().ToUtf16be()) // 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() 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[7] = (sum[7] & 0xf) | 0x50 - return &guid.GUID{ + return guid.GUID{ Data1: binary.LittleEndian.Uint32(sum[0:4]), Data2: binary.LittleEndian.Uint16(sum[4:6]), Data3: binary.LittleEndian.Uint16(sum[6:8]), @@ -219,8 +219,8 @@ func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpt // the ETW infrastructure. func (provider *Provider) writeEventRaw( descriptor *eventDescriptor, - activityID *guid.GUID, - relatedActivityID *guid.GUID, + activityID guid.GUID, + relatedActivityID guid.GUID, metadataBlobs [][]byte, dataBlobs [][]byte) error { @@ -235,5 +235,5 @@ func (provider *Provider) writeEventRaw( 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]) } diff --git a/pkg/etw/sample/sample.go b/pkg/etw/sample/sample.go index d86d43e..0f3bebe 100644 --- a/pkg/etw/sample/sample.go +++ b/pkg/etw/sample/sample.go @@ -11,7 +11,7 @@ import ( "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) }