summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/info.go2
-rw-r--r--pkg/platform/architecture_windows.go63
-rw-r--r--pkg/platform/platform.go25
-rw-r--r--pkg/platform/platform_unix.go (renamed from pkg/platform/architecture_unix.go)2
-rw-r--r--pkg/platform/platform_windows.go71
5 files changed, 89 insertions, 74 deletions
diff --git a/daemon/info.go b/daemon/info.go
index 80dfb39deb..226eef9c27 100644
--- a/daemon/info.go
+++ b/daemon/info.go
@@ -44,7 +44,7 @@ func (daemon *Daemon) SystemInfo() *types.Info {
OperatingSystem: operatingSystem(),
OSVersion: osVersion(),
IndexServerAddress: registry.IndexServer,
- OSType: platform.OSType,
+ OSType: runtime.GOOS,
Architecture: platform.Architecture,
RegistryConfig: daemon.registryService.ServiceConfig(),
NCPU: sysinfo.NumCPU(),
diff --git a/pkg/platform/architecture_windows.go b/pkg/platform/architecture_windows.go
deleted file mode 100644
index 68036eb763..0000000000
--- a/pkg/platform/architecture_windows.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package platform // import "github.com/docker/docker/pkg/platform"
-
-import (
- "fmt"
- "syscall"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-var (
- modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
- procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
-)
-
-// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx
-type systeminfo struct {
- wProcessorArchitecture uint16
- wReserved uint16
- dwPageSize uint32
- lpMinimumApplicationAddress uintptr
- lpMaximumApplicationAddress uintptr
- dwActiveProcessorMask uintptr
- dwNumberOfProcessors uint32
- dwProcessorType uint32
- dwAllocationGranularity uint32
- wProcessorLevel uint16
- wProcessorRevision uint16
-}
-
-// Constants
-const (
- ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64
- ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64
- ProcessorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL
- ProcessorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM
- ProcessorArchitectureArm64 = 12 // PROCESSOR_ARCHITECTURE_ARM64
-)
-
-// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …)
-func runtimeArchitecture() (string, error) {
- var sysinfo systeminfo
- syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
- switch sysinfo.wProcessorArchitecture {
- case ProcessorArchitecture64, ProcessorArchitectureIA64:
- return "x86_64", nil
- case ProcessorArchitecture32:
- return "i686", nil
- case ProcessorArchitectureArm:
- return "arm", nil
- case ProcessorArchitectureArm64:
- return "arm64", nil
- default:
- return "", fmt.Errorf("unknown processor architecture %+v", sysinfo.wProcessorArchitecture)
- }
-}
-
-// NumProcs returns the number of processors on the system
-func NumProcs() uint32 {
- var sysinfo systeminfo
- syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
- return sysinfo.dwNumberOfProcessors
-}
diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go
index f6b02b734a..8d90433b60 100644
--- a/pkg/platform/platform.go
+++ b/pkg/platform/platform.go
@@ -1,3 +1,5 @@
+// Package platform provides helper function to get the runtime architecture
+// for different platforms.
package platform // import "github.com/docker/docker/pkg/platform"
import (
@@ -6,18 +8,25 @@ import (
"github.com/sirupsen/logrus"
)
-var (
- // Architecture holds the runtime architecture of the process.
- Architecture string
- // OSType holds the runtime operating system type (Linux, …) of the process.
- OSType string
-)
+// Architecture holds the runtime architecture of the process.
+//
+// Unlike [runtime.GOARCH] (which refers to the compiler platform),
+// Architecture refers to the running platform.
+//
+// For example, Architecture reports "x86_64" as architecture, even
+// when running a "linux/386" compiled binary on "linux/amd64" hardware.
+var Architecture string
+
+// OSType holds the runtime operating system type of the process. It is
+// an alias for [runtime.GOOS].
+//
+// Deprecated: use [runtime.GOOS] instead.
+const OSType = runtime.GOOS
func init() {
var err error
Architecture, err = runtimeArchitecture()
if err != nil {
- logrus.Errorf("Could not read system architecture info: %v", err)
+ logrus.WithError(err).Error("Could not read system architecture info")
}
- OSType = runtime.GOOS
}
diff --git a/pkg/platform/architecture_unix.go b/pkg/platform/platform_unix.go
index 9911b820ca..b52708d112 100644
--- a/pkg/platform/architecture_unix.go
+++ b/pkg/platform/platform_unix.go
@@ -1,8 +1,6 @@
//go:build !windows
// +build !windows
-// Package platform provides helper function to get the runtime architecture
-// for different platforms.
package platform // import "github.com/docker/docker/pkg/platform"
import (
diff --git a/pkg/platform/platform_windows.go b/pkg/platform/platform_windows.go
new file mode 100644
index 0000000000..d913121444
--- /dev/null
+++ b/pkg/platform/platform_windows.go
@@ -0,0 +1,71 @@
+package platform // import "github.com/docker/docker/pkg/platform"
+
+import (
+ "fmt"
+ "syscall"
+ "unsafe"
+
+ "golang.org/x/sys/windows"
+)
+
+var (
+ modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
+ procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
+)
+
+// see https://learn.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
+type systeminfo struct {
+ wProcessorArchitecture uint16
+ wReserved uint16
+ dwPageSize uint32
+ lpMinimumApplicationAddress uintptr
+ lpMaximumApplicationAddress uintptr
+ dwActiveProcessorMask uintptr
+ dwNumberOfProcessors uint32
+ dwProcessorType uint32
+ dwAllocationGranularity uint32
+ wProcessorLevel uint16
+ wProcessorRevision uint16
+}
+
+// Windows processor architectures.
+//
+// see https://github.com/microsoft/go-winio/blob/v0.6.0/wim/wim.go#L48-L65
+// see https://learn.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
+const (
+ processorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64
+ processorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64
+ processorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL
+ processorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM
+ processorArchitectureArm64 = 12 // PROCESSOR_ARCHITECTURE_ARM64
+)
+
+// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …)
+func runtimeArchitecture() (string, error) {
+ // TODO(thaJeztah): rewrite this to use "GetNativeSystemInfo" instead.
+ // See: https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo
+ // See: https://github.com/shirou/gopsutil/blob/v3.23.3/host/host_windows.go#L267-L297
+ // > To retrieve accurate information for an application running on WOW64,
+ // > call the GetNativeSystemInfo function.
+ var sysinfo systeminfo
+ _, _, _ = syscall.SyscallN(procGetSystemInfo.Addr(), uintptr(unsafe.Pointer(&sysinfo)))
+ switch sysinfo.wProcessorArchitecture {
+ case processorArchitecture64, processorArchitectureIA64:
+ return "x86_64", nil
+ case processorArchitecture32:
+ return "i686", nil
+ case processorArchitectureArm:
+ return "arm", nil
+ case processorArchitectureArm64:
+ return "arm64", nil
+ default:
+ return "", fmt.Errorf("unknown processor architecture %+v", sysinfo.wProcessorArchitecture)
+ }
+}
+
+// NumProcs returns the number of processors on the system
+func NumProcs() uint32 {
+ var sysinfo systeminfo
+ _, _, _ = syscall.SyscallN(procGetSystemInfo.Addr(), uintptr(unsafe.Pointer(&sysinfo)))
+ return sysinfo.dwNumberOfProcessors
+}