aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--tunnel/firewall/rules.go10
-rw-r--r--version/os_windows.go35
-rw-r--r--version/zsyscall_windows.go14
3 files changed, 6 insertions, 53 deletions
diff --git a/tunnel/firewall/rules.go b/tunnel/firewall/rules.go
index 1216065b..08dfce50 100644
--- a/tunnel/firewall/rules.go
+++ b/tunnel/firewall/rules.go
@@ -13,7 +13,6 @@ import (
"unsafe"
"golang.org/x/sys/windows"
- "golang.zx2c4.com/wireguard/windows/version"
)
//
@@ -829,12 +828,9 @@ func permitHyperV(session uintptr, baseObjects *baseObjects, weight uint8) error
// Only applicable on Win8+.
//
{
- v, err := version.OsVersion()
- if err != nil {
- panic(err)
- }
-
- win8plus := v.MajorVersion > 6 || (v.MajorVersion == 6 && v.MinorVersion >= 3)
+ //TODO: use RtlGetNtVersionNumbers instead when that's merged.
+ versionInfo := windows.RtlGetVersion()
+ win8plus := versionInfo.MajorVersion > 6 || (versionInfo.MajorVersion == 6 && versionInfo.MinorVersion >= 3)
if !win8plus {
return nil
diff --git a/version/os_windows.go b/version/os_windows.go
index 2f5e8d44..70d3e82f 100644
--- a/version/os_windows.go
+++ b/version/os_windows.go
@@ -7,8 +7,8 @@ package version
import (
"fmt"
- "unsafe"
+ "golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)
@@ -167,35 +167,9 @@ const (
PRODUCT_UNLICENSED = 0xABCDABCD
)
-type OsVersionInfo struct {
- osVersionInfoSize uint32
- MajorVersion uint32
- MinorVersion uint32
- BuildNumber uint32
- PlatformId uint32
- CsdVersion [128]uint16
- ServicePackMajor uint16
- ServicePackMinor uint16
- SuiteMask uint16
- ProductType byte
- _ byte
-}
-
-//sys rtlGetVersion(versionInfo *OsVersionInfo) (err error) [failretval!=0] = ntdll.RtlGetVersion
-
-func OsVersion() (versionInfo OsVersionInfo, err error) {
- versionInfo.osVersionInfoSize = uint32(unsafe.Sizeof(versionInfo))
- err = rtlGetVersion(&versionInfo)
- return
-}
func OsIsCore() bool {
- versionInfo := OsVersionInfo{osVersionInfoSize: uint32(unsafe.Sizeof(OsVersionInfo{}))}
- err := rtlGetVersion(&versionInfo)
- if err != nil {
- return false
- }
-
+ versionInfo := windows.RtlGetVersion()
if versionInfo.MajorVersion > 6 || (versionInfo.MajorVersion == 6 && versionInfo.MinorVersion >= 2) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels`, registry.READ)
if err != nil {
@@ -219,10 +193,7 @@ func OsIsCore() bool {
}
func OsName() string {
- versionInfo, err := OsVersion()
- if err != nil {
- return "Windows Unknown"
- }
+ versionInfo := windows.RtlGetVersion()
winType := ""
switch versionInfo.ProductType {
case 3:
diff --git a/version/zsyscall_windows.go b/version/zsyscall_windows.go
index 711d76da..21684bb3 100644
--- a/version/zsyscall_windows.go
+++ b/version/zsyscall_windows.go
@@ -37,27 +37,13 @@ func errnoErr(e syscall.Errno) error {
}
var (
- modntdll = windows.NewLazySystemDLL("ntdll.dll")
modversion = windows.NewLazySystemDLL("version.dll")
- procRtlGetVersion = modntdll.NewProc("RtlGetVersion")
procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW")
procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW")
procVerQueryValueW = modversion.NewProc("VerQueryValueW")
)
-func rtlGetVersion(versionInfo *OsVersionInfo) (err error) {
- r1, _, e1 := syscall.Syscall(procRtlGetVersion.Addr(), 1, uintptr(unsafe.Pointer(versionInfo)), 0, 0)
- if r1 != 0 {
- if e1 != 0 {
- err = errnoErr(e1)
- } else {
- err = syscall.EINVAL
- }
- }
- return
-}
-
func GetFileVersionInfoSize(filename *uint16, zero *uint32) (size uint32, err error) {
r0, _, e1 := syscall.Syscall(procGetFileVersionInfoSizeW.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(zero)), 0)
size = uint32(r0)