wrapper_32.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //go:build windows && (386 || arm)
  2. // +build windows
  3. // +build 386 arm
  4. package etw
  5. import (
  6. "github.com/Microsoft/go-winio/pkg/guid"
  7. "golang.org/x/sys/windows"
  8. )
  9. func low(v providerHandle) uint32 {
  10. return uint32(v & 0xffffffff)
  11. }
  12. func high(v providerHandle) uint32 {
  13. return low(v >> 32)
  14. }
  15. func eventUnregister(providerHandle providerHandle) (win32err error) {
  16. return eventUnregister_32(low(providerHandle), high(providerHandle))
  17. }
  18. func eventWriteTransfer(
  19. providerHandle providerHandle,
  20. descriptor *eventDescriptor,
  21. activityID *windows.GUID,
  22. relatedActivityID *windows.GUID,
  23. dataDescriptorCount uint32,
  24. dataDescriptors *eventDataDescriptor) (win32err error) {
  25. return eventWriteTransfer_32(
  26. low(providerHandle),
  27. high(providerHandle),
  28. descriptor,
  29. activityID,
  30. relatedActivityID,
  31. dataDescriptorCount,
  32. dataDescriptors)
  33. }
  34. func eventSetInformation(
  35. providerHandle providerHandle,
  36. class eventInfoClass,
  37. information uintptr,
  38. length uint32) (win32err error) {
  39. return eventSetInformation_32(
  40. low(providerHandle),
  41. high(providerHandle),
  42. class,
  43. information,
  44. length)
  45. }
  46. // providerCallbackAdapter acts as the first-level callback from the C/ETW side
  47. // for provider notifications. Because Go has trouble with callback arguments of
  48. // different size, it has only pointer-sized arguments, which are then cast to
  49. // the appropriate types when calling providerCallback.
  50. // For x86, the matchAny and matchAll keywords need to be assembled from two
  51. // 32-bit integers, because the max size of an argument is uintptr, but those
  52. // two arguments are actually 64-bit integers.
  53. func providerCallbackAdapter(sourceID *guid.GUID, state uint32, level uint32, matchAnyKeyword_low uint32, matchAnyKeyword_high uint32, matchAllKeyword_low uint32, matchAllKeyword_high uint32, filterData uintptr, i uintptr) uintptr {
  54. matchAnyKeyword := uint64(matchAnyKeyword_high)<<32 | uint64(matchAnyKeyword_low)
  55. matchAllKeyword := uint64(matchAllKeyword_high)<<32 | uint64(matchAllKeyword_low)
  56. providerCallback(*sourceID, ProviderState(state), Level(level), uint64(matchAnyKeyword), uint64(matchAllKeyword), filterData, i)
  57. return 0
  58. }