| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"syscall" |
| 9 |
"unsafe" |
| 10 |
) |
| 11 |
|
| 12 |
var ( |
| 13 |
modkernel32 = syscall.NewLazyDLL("kernel32.dll") |
| 14 |
procGetSystemInfo = modkernel32.NewProc("GetSystemInfo") |
| 15 |
) |
| 16 |
|
| 17 |
// see https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info |
| 18 |
type systeminfo struct { |
| 19 |
wProcessorArchitecture uint16 |
| 20 |
wReserved uint16 |
| 21 |
dwPageSize uint32 |
| 22 |
lpMinimumApplicationAddress uintptr |
| 23 |
lpMaximumApplicationAddress uintptr |
| 24 |
dwActiveProcessorMask uintptr |
| 25 |
dwNumberOfProcessors uint32 |
| 26 |
dwProcessorType uint32 |
| 27 |
dwAllocationGranularity uint32 |
| 28 |
wProcessorLevel uint16 |
| 29 |
wProcessorRevision uint16 |
| 30 |
} |
| 31 |
|
| 32 |
// See https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info |
| 33 |
const ( |
| 34 |
PROCESSOR_ARCHITECTURE_AMD64 = 9 |
| 35 |
PROCESSOR_ARCHITECTURE_INTEL = 0 |
| 36 |
PROCESSOR_ARCHITECTURE_ARM64 = 12 |
| 37 |
PROCESSOR_ARCHITECTURE_IA64 = 6 |
| 38 |
) |
| 39 |
|
| 40 |
var sysinfo systeminfo |
| 41 |
|
| 42 |
func sysinit() { |
| 43 |
syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) |
| 44 |
switch sysinfo.wProcessorArchitecture { |
| 45 |
case PROCESSOR_ARCHITECTURE_AMD64: |
| 46 |
gohostarch = "amd64" |
| 47 |
case PROCESSOR_ARCHITECTURE_INTEL: |
| 48 |
gohostarch = "386" |
| 49 |
case PROCESSOR_ARCHITECTURE_ARM64: |
| 50 |
gohostarch = "arm64" |
| 51 |
default: |
| 52 |
fatalf("unknown processor architecture") |
| 53 |
} |
| 54 |
} |