github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/dist/sys_windows.go (about)

     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://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx
    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  const (
    33  	PROCESSOR_ARCHITECTURE_AMD64 = 9
    34  	PROCESSOR_ARCHITECTURE_INTEL = 0
    35  	PROCESSOR_ARCHITECTURE_ARM   = 5
    36  )
    37  
    38  var sysinfo systeminfo
    39  
    40  func sysinit() {
    41  	syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0)
    42  	switch sysinfo.wProcessorArchitecture {
    43  	case PROCESSOR_ARCHITECTURE_AMD64:
    44  		gohostarch = "amd64"
    45  	case PROCESSOR_ARCHITECTURE_INTEL:
    46  		gohostarch = "386"
    47  	case PROCESSOR_ARCHITECTURE_ARM:
    48  		gohostarch = "arm"
    49  	default:
    50  		fatalf("unknown processor architecture")
    51  	}
    52  }