mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 16:47:31 -04:00
Switch from sycall to windows (#295)
Where ever possible, use `golang.org/x/sys/windows` instead of `syscall` (which has been deprecated since go1.11). Using `windows.LocalFree` requires using `unsafe.Pointer`, which ensures that the Go garbage collector does not try to free memory pre-maturely if it was previously declared as a pointer. Since `syscall.Handle` is part of API for `vhd` package, it was left unchanged. For security descriptor functions, switch to using `windows.SECURITY_DESCRIPTOR` to avoid unnecessary byte manipulation and panics due to missing input validation and error checking. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
This commit is contained in:
@@ -6,7 +6,8 @@ package etw
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// eventData maintains a buffer which builds up the data for an ETW event. It
|
||||
@@ -69,6 +70,6 @@ func (ed *eventData) writeUint64(value uint64) {
|
||||
}
|
||||
|
||||
// writeFiletime appends a FILETIME to the buffer.
|
||||
func (ed *eventData) writeFiletime(value syscall.Filetime) {
|
||||
func (ed *eventData) writeFiletime(value windows.Filetime) {
|
||||
_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// FieldOpt defines the option function type that can be passed to
|
||||
@@ -397,7 +398,7 @@ func Struct(name string, opts ...FieldOpt) FieldOpt {
|
||||
func Time(name string, value time.Time) FieldOpt {
|
||||
return func(em *eventMetadata, ed *eventData) {
|
||||
em.writeField(name, inTypeFileTime, outTypeDateTimeUTC, 0)
|
||||
ed.writeFiletime(syscall.NsecToFiletime(value.UTC().UnixNano()))
|
||||
ed.writeFiletime(windows.NsecToFiletime(value.UTC().UnixNano()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user