setupapi: Fix struct size mismatches
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
c7a26dfef3
commit
f1dc167901
|
@ -34,7 +34,7 @@ func SetupDiCreateDeviceInfoListEx(classGUID *windows.GUID, hwndParent uintptr,
|
||||||
// SetupDiGetDeviceInfoListDetail function retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
|
// SetupDiGetDeviceInfoListDetail function retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
|
||||||
func SetupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo) (deviceInfoSetDetailData *DevInfoListDetailData, err error) {
|
func SetupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo) (deviceInfoSetDetailData *DevInfoListDetailData, err error) {
|
||||||
data := &DevInfoListDetailData{}
|
data := &DevInfoListDetailData{}
|
||||||
data.size = uint32(unsafe.Sizeof(*data))
|
data.size = sizeofDevInfoListDetailData
|
||||||
|
|
||||||
return data, setupDiGetDeviceInfoListDetail(deviceInfoSet, data)
|
return data, setupDiGetDeviceInfoListDetail(deviceInfoSet, data)
|
||||||
}
|
}
|
||||||
|
@ -155,10 +155,7 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
|
||||||
var bufLen uint32
|
var bufLen uint32
|
||||||
|
|
||||||
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
|
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
|
||||||
|
data.size = sizeofDrvInfoDetailData
|
||||||
// unsafe.Sizeof(data) >= sizeof(SP_DRVINFO_DETAIL_DATA) due to Go trailing padding. SetupAPI expects exactly sizeof(SP_DRVINFO_DETAIL_DATA).
|
|
||||||
sizeAPI := ((unsafe.Sizeof(uintptr(0)) - 1) | (unsafe.Offsetof(data.hardwareID) + unsafe.Sizeof(data.hardwareID) - 1) + 1)
|
|
||||||
data.size = uint32(sizeAPI)
|
|
||||||
|
|
||||||
err := setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufCapacity, &bufLen)
|
err := setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufCapacity, &bufLen)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -171,7 +168,7 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
|
||||||
// The buffer was too small. Now that we got the required size, create another one big enough and retry.
|
// The buffer was too small. Now that we got the required size, create another one big enough and retry.
|
||||||
buf := make([]byte, bufLen)
|
buf := make([]byte, bufLen)
|
||||||
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
|
data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0]))
|
||||||
data.size = uint32(sizeAPI)
|
data.size = sizeofDrvInfoDetailData
|
||||||
|
|
||||||
err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufLen, &bufLen)
|
err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufLen, &bufLen)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -60,7 +60,7 @@ type DevInfoData struct {
|
||||||
|
|
||||||
// DevInfoListDetailData is a structure for detailed information on a device information set (used for SetupDiGetDeviceInfoListDetail which supercedes the functionality of SetupDiGetDeviceInfoListClass).
|
// DevInfoListDetailData is a structure for detailed information on a device information set (used for SetupDiGetDeviceInfoListDetail which supercedes the functionality of SetupDiGetDeviceInfoListClass).
|
||||||
type DevInfoListDetailData struct {
|
type DevInfoListDetailData struct {
|
||||||
size uint32
|
size uint32 // Warning: unsafe.Sizeof(DevInfoListDetailData) > sizeof(SP_DEVINFO_LIST_DETAIL_DATA) when GOARCH == 386 => use sizeofDevInfoListDetailData const.
|
||||||
ClassGUID windows.GUID
|
ClassGUID windows.GUID
|
||||||
RemoteMachineHandle windows.Handle
|
RemoteMachineHandle windows.Handle
|
||||||
remoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
|
remoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
|
||||||
|
@ -371,7 +371,7 @@ func (data *DrvInfoData) IsNewer(driverDate windows.Filetime, driverVersion uint
|
||||||
|
|
||||||
// DrvInfoDetailData is driver information details structure (provides detailed information about a particular driver information structure)
|
// DrvInfoDetailData is driver information details structure (provides detailed information about a particular driver information structure)
|
||||||
type DrvInfoDetailData struct {
|
type DrvInfoDetailData struct {
|
||||||
size uint32 // On input, this must be exactly the sizeof(DrvInfoDetailData). On output, we set this member to the actual size of structure data.
|
size uint32 // Warning: unsafe.Sizeof(DrvInfoDetailData) > sizeof(SP_DRVINFO_DETAIL_DATA) when GOARCH == 386 => use sizeofDrvInfoDetailData const.
|
||||||
InfDate windows.Filetime
|
InfDate windows.Filetime
|
||||||
compatIDsOffset uint32
|
compatIDsOffset uint32
|
||||||
compatIDsLength uint32
|
compatIDsLength uint32
|
||||||
|
|
11
tun/wintun/setupapi/types_windows_386.go
Normal file
11
tun/wintun/setupapi/types_windows_386.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package setupapi
|
||||||
|
|
||||||
|
const (
|
||||||
|
sizeofDevInfoListDetailData uint32 = 550
|
||||||
|
sizeofDrvInfoDetailData uint32 = 1570
|
||||||
|
)
|
11
tun/wintun/setupapi/types_windows_amd64.go
Normal file
11
tun/wintun/setupapi/types_windows_amd64.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package setupapi
|
||||||
|
|
||||||
|
const (
|
||||||
|
sizeofDevInfoListDetailData uint32 = 560
|
||||||
|
sizeofDrvInfoDetailData uint32 = 1584
|
||||||
|
)
|
Loading…
Reference in a new issue