2018-02-05 16:05:59 -05:00
|
|
|
package platform // import "github.com/docker/docker/pkg/platform"
|
2015-11-14 17:03:02 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
2016-11-21 17:35:06 -05:00
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
2015-11-14 17:03:02 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-11-21 17:35:06 -05:00
|
|
|
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
2015-11-14 17:03:02 -05:00
|
|
|
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 (
|
2022-04-09 06:19:12 -04:00
|
|
|
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
|
2015-11-14 17:03:02 -05:00
|
|
|
)
|
|
|
|
|
2016-04-09 09:18:15 -04:00
|
|
|
// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …)
|
2015-11-19 08:55:57 -05:00
|
|
|
func runtimeArchitecture() (string, error) {
|
2016-11-08 20:52:38 -05:00
|
|
|
var sysinfo systeminfo
|
2015-11-14 17:03:02 -05:00
|
|
|
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
|
2022-04-09 06:19:12 -04:00
|
|
|
case ProcessorArchitectureArm64:
|
|
|
|
return "arm64", nil
|
2015-11-14 17:03:02 -05:00
|
|
|
default:
|
2022-04-09 06:19:12 -04:00
|
|
|
return "", fmt.Errorf("unknown processor architecture %+v", sysinfo.wProcessorArchitecture)
|
2015-11-14 17:03:02 -05:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 19:08:51 -04:00
|
|
|
|
|
|
|
// NumProcs returns the number of processors on the system
|
|
|
|
func NumProcs() uint32 {
|
2016-11-08 20:52:38 -05:00
|
|
|
var sysinfo systeminfo
|
2016-09-07 19:08:51 -04:00
|
|
|
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
|
|
|
|
return sysinfo.dwNumberOfProcessors
|
|
|
|
}
|