mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-08-28 04:46:50 -04:00
Fix ETW package to work on 386
The ETW registration handle is defined to be 64-bits on all platforms. The Go type previously used a uintptr which created problems on 32-bit systems. This change adds a new wrapper file which receives a 64-bit handle for the functions defined in it, and correctly passes it to the native ETW functions either as-is (on 64-bit) or as two 32-bit values (on 32-bit). This required a minor change in mksyscall_windows.go, to allow multiple syscalls that map to the same underlying function without causing a duplicate definition error in the generated file.
This commit is contained in:
+9
-4
@@ -7,9 +7,14 @@
|
||||
// set of C macros.
|
||||
package etw
|
||||
|
||||
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go etw.go
|
||||
//go:generate go run mksyscall_windows.go -output zsyscall_windows.go etw.go
|
||||
|
||||
//sys eventRegister(providerId *windows.GUID, callback uintptr, callbackContext uintptr, providerHandle *providerHandle) (win32err error) = advapi32.EventRegister
|
||||
//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 eventSetInformation(providerHandle providerHandle, class eventInfoClass, information uintptr, length uint32) (win32err error) = advapi32.EventSetInformation
|
||||
|
||||
//sys eventUnregister_64(providerHandle providerHandle) (win32err error) = advapi32.EventUnregister
|
||||
//sys eventWriteTransfer_64(providerHandle providerHandle, descriptor *eventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) = advapi32.EventWriteTransfer
|
||||
//sys eventSetInformation_64(providerHandle providerHandle, class eventInfoClass, information uintptr, length uint32) (win32err error) = advapi32.EventSetInformation
|
||||
|
||||
//sys eventUnregister_32(providerHandle_low uint32, providerHandle_high uint32) (win32err error) = advapi32.EventUnregister
|
||||
//sys eventWriteTransfer_32(providerHandle_low uint32, providerHandle_high uint32, descriptor *eventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) = advapi32.EventWriteTransfer
|
||||
//sys eventSetInformation_32(providerHandle_low uint32, providerHandle_high uint32, class eventInfoClass, information uintptr, length uint32) (win32err error) = advapi32.EventSetInformation
|
||||
|
||||
@@ -603,6 +603,19 @@ type Source struct {
|
||||
ExternalImports []string
|
||||
}
|
||||
|
||||
func (src *Source) FuncImports() []*Fn {
|
||||
uniq := make(map[string]bool)
|
||||
r := make([]*Fn, 0)
|
||||
for _, f := range src.Funcs {
|
||||
name := f.DLLFuncName()
|
||||
if _, found := uniq[name]; !found {
|
||||
uniq[name] = true
|
||||
r = append(r, f)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (src *Source) Import(pkg string) {
|
||||
src.StdLibImports = append(src.StdLibImports, pkg)
|
||||
sort.Strings(src.StdLibImports)
|
||||
@@ -865,7 +878,7 @@ var (
|
||||
{{define "dlls"}}{{range .DLLs}} mod{{.}} = {{newlazydll .}}
|
||||
{{end}}{{end}}
|
||||
|
||||
{{define "funcnames"}}{{range .Funcs}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}")
|
||||
{{define "funcnames"}}{{range .FuncImports}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}")
|
||||
{{end}}{{end}}
|
||||
|
||||
{{define "helperbody"}}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build amd64 arm64
|
||||
// +build amd64 arm64 386
|
||||
|
||||
package etw
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build arm 386
|
||||
// +build arm
|
||||
|
||||
package etw
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ func (provider *Provider) String() string {
|
||||
return provider.ID.String()
|
||||
}
|
||||
|
||||
type providerHandle windows.Handle
|
||||
type providerHandle uint64
|
||||
|
||||
// ProviderState informs the provider EnableCallback what action is being
|
||||
// performed.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// +build 386 arm
|
||||
|
||||
package etw
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func low(v providerHandle) uint32 {
|
||||
return uint32(v & 0xffffffff)
|
||||
}
|
||||
|
||||
func high(v providerHandle) uint32 {
|
||||
return low(v >> 32)
|
||||
}
|
||||
|
||||
func eventUnregister(providerHandle providerHandle) (win32err error) {
|
||||
return eventUnregister_32(low(providerHandle), high(providerHandle))
|
||||
}
|
||||
|
||||
func eventWriteTransfer(
|
||||
providerHandle providerHandle,
|
||||
descriptor *eventDescriptor,
|
||||
activityID *windows.GUID,
|
||||
relatedActivityID *windows.GUID,
|
||||
dataDescriptorCount uint32,
|
||||
dataDescriptors *eventDataDescriptor) (win32err error) {
|
||||
|
||||
return eventWriteTransfer_32(
|
||||
low(providerHandle),
|
||||
high(providerHandle),
|
||||
descriptor,
|
||||
activityID,
|
||||
relatedActivityID,
|
||||
dataDescriptorCount,
|
||||
dataDescriptors)
|
||||
}
|
||||
|
||||
func eventSetInformation(
|
||||
providerHandle providerHandle,
|
||||
class eventInfoClass,
|
||||
information uintptr,
|
||||
length uint32) (win32err error) {
|
||||
|
||||
return eventSetInformation_32(
|
||||
low(providerHandle),
|
||||
high(providerHandle),
|
||||
class,
|
||||
information,
|
||||
length)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// +build amd64 arm64
|
||||
|
||||
package etw
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func eventUnregister(providerHandle providerHandle) (win32err error) {
|
||||
return eventUnregister_64(providerHandle)
|
||||
}
|
||||
|
||||
func eventWriteTransfer(
|
||||
providerHandle providerHandle,
|
||||
descriptor *eventDescriptor,
|
||||
activityID *windows.GUID,
|
||||
relatedActivityID *windows.GUID,
|
||||
dataDescriptorCount uint32,
|
||||
dataDescriptors *eventDataDescriptor) (win32err error) {
|
||||
|
||||
return eventWriteTransfer_64(
|
||||
providerHandle,
|
||||
descriptor,
|
||||
activityID,
|
||||
relatedActivityID,
|
||||
dataDescriptorCount,
|
||||
dataDescriptors)
|
||||
}
|
||||
|
||||
func eventSetInformation(
|
||||
providerHandle providerHandle,
|
||||
class eventInfoClass,
|
||||
information uintptr,
|
||||
length uint32) (win32err error) {
|
||||
|
||||
return eventSetInformation_64(
|
||||
providerHandle,
|
||||
class,
|
||||
information,
|
||||
length)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func eventRegister(providerId *windows.GUID, callback uintptr, callbackContext u
|
||||
return
|
||||
}
|
||||
|
||||
func eventUnregister(providerHandle providerHandle) (win32err error) {
|
||||
func eventUnregister_64(providerHandle providerHandle) (win32err error) {
|
||||
r0, _, _ := syscall.Syscall(procEventUnregister.Addr(), 1, uintptr(providerHandle), 0, 0)
|
||||
if r0 != 0 {
|
||||
win32err = syscall.Errno(r0)
|
||||
@@ -61,7 +61,7 @@ func eventUnregister(providerHandle providerHandle) (win32err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func eventWriteTransfer(providerHandle providerHandle, descriptor *eventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) {
|
||||
func eventWriteTransfer_64(providerHandle providerHandle, descriptor *eventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) {
|
||||
r0, _, _ := syscall.Syscall6(procEventWriteTransfer.Addr(), 6, uintptr(providerHandle), uintptr(unsafe.Pointer(descriptor)), uintptr(unsafe.Pointer(activityID)), uintptr(unsafe.Pointer(relatedActivityID)), uintptr(dataDescriptorCount), uintptr(unsafe.Pointer(dataDescriptors)))
|
||||
if r0 != 0 {
|
||||
win32err = syscall.Errno(r0)
|
||||
@@ -69,10 +69,34 @@ func eventWriteTransfer(providerHandle providerHandle, descriptor *eventDescript
|
||||
return
|
||||
}
|
||||
|
||||
func eventSetInformation(providerHandle providerHandle, class eventInfoClass, information uintptr, length uint32) (win32err error) {
|
||||
func eventSetInformation_64(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
|
||||
}
|
||||
|
||||
func eventUnregister_32(providerHandle_low uint32, providerHandle_high uint32) (win32err error) {
|
||||
r0, _, _ := syscall.Syscall(procEventUnregister.Addr(), 2, uintptr(providerHandle_low), uintptr(providerHandle_high), 0)
|
||||
if r0 != 0 {
|
||||
win32err = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func eventWriteTransfer_32(providerHandle_low uint32, providerHandle_high uint32, descriptor *eventDescriptor, activityID *windows.GUID, relatedActivityID *windows.GUID, dataDescriptorCount uint32, dataDescriptors *eventDataDescriptor) (win32err error) {
|
||||
r0, _, _ := syscall.Syscall9(procEventWriteTransfer.Addr(), 7, uintptr(providerHandle_low), uintptr(providerHandle_high), uintptr(unsafe.Pointer(descriptor)), uintptr(unsafe.Pointer(activityID)), uintptr(unsafe.Pointer(relatedActivityID)), uintptr(dataDescriptorCount), uintptr(unsafe.Pointer(dataDescriptors)), 0, 0)
|
||||
if r0 != 0 {
|
||||
win32err = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func eventSetInformation_32(providerHandle_low uint32, providerHandle_high uint32, class eventInfoClass, information uintptr, length uint32) (win32err error) {
|
||||
r0, _, _ := syscall.Syscall6(procEventSetInformation.Addr(), 5, uintptr(providerHandle_low), uintptr(providerHandle_high), uintptr(class), uintptr(information), uintptr(length), 0)
|
||||
if r0 != 0 {
|
||||
win32err = syscall.Errno(r0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user