1// Licensed to Elasticsearch B.V. under one or more contributor 2// license agreements. See the NOTICE file distributed with 3// this work for additional information regarding copyright 4// ownership. Elasticsearch B.V. licenses this file to you under 5// the Apache License, Version 2.0 (the "License"); you may 6// not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// 9// http://www.apache.org/licenses/LICENSE-2.0 10// 11// Unless required by applicable law or agreed to in writing, 12// software distributed under the License is distributed on an 13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14// KIND, either express or implied. See the License for the 15// specific language governing permissions and limitations 16// under the License. 17 18// Code generated by 'go generate'; DO NOT EDIT. 19 20package windows 21 22import ( 23 "syscall" 24 "unsafe" 25 26 "golang.org/x/sys/windows" 27) 28 29var _ unsafe.Pointer 30 31// Do the interface allocations only once for common 32// Errno values. 33const ( 34 errnoERROR_IO_PENDING = 997 35) 36 37var ( 38 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) 39) 40 41// errnoErr returns common boxed Errno values, to prevent 42// allocations at runtime. 43func errnoErr(e syscall.Errno) error { 44 switch e { 45 case 0: 46 return nil 47 case errnoERROR_IO_PENDING: 48 return errERROR_IO_PENDING 49 } 50 // TODO: add more here, after collecting data on the common 51 // error values see on Windows. (perhaps when running 52 // all.bat?) 53 return e 54} 55 56var ( 57 modkernel32 = windows.NewLazySystemDLL("kernel32.dll") 58 modversion = windows.NewLazySystemDLL("version.dll") 59 modpsapi = windows.NewLazySystemDLL("psapi.dll") 60 modntdll = windows.NewLazySystemDLL("ntdll.dll") 61 62 procGetNativeSystemInfo = modkernel32.NewProc("GetNativeSystemInfo") 63 procGetTickCount64 = modkernel32.NewProc("GetTickCount64") 64 procGetSystemTimes = modkernel32.NewProc("GetSystemTimes") 65 procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") 66 procReadProcessMemory = modkernel32.NewProc("ReadProcessMemory") 67 procGetProcessHandleCount = modkernel32.NewProc("GetProcessHandleCount") 68 procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW") 69 procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW") 70 procVerQueryValueW = modversion.NewProc("VerQueryValueW") 71 procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo") 72 procGetProcessImageFileNameA = modpsapi.NewProc("GetProcessImageFileNameA") 73 procEnumProcesses = modpsapi.NewProc("EnumProcesses") 74 procNtQueryInformationProcess = modntdll.NewProc("NtQueryInformationProcess") 75) 76 77func _GetNativeSystemInfo(systemInfo *SystemInfo) { 78 syscall.Syscall(procGetNativeSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(systemInfo)), 0, 0) 79 return 80} 81 82func _GetTickCount64() (millis uint64, err error) { 83 r0, _, e1 := syscall.Syscall(procGetTickCount64.Addr(), 0, 0, 0, 0) 84 millis = uint64(r0) 85 if millis == 0 { 86 if e1 != 0 { 87 err = errnoErr(e1) 88 } else { 89 err = syscall.EINVAL 90 } 91 } 92 return 93} 94 95func _GetSystemTimes(idleTime *syscall.Filetime, kernelTime *syscall.Filetime, userTime *syscall.Filetime) (err error) { 96 r1, _, e1 := syscall.Syscall(procGetSystemTimes.Addr(), 3, uintptr(unsafe.Pointer(idleTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime))) 97 if r1 == 0 { 98 if e1 != 0 { 99 err = errnoErr(e1) 100 } else { 101 err = syscall.EINVAL 102 } 103 } 104 return 105} 106 107func _GlobalMemoryStatusEx(buffer *MemoryStatusEx) (err error) { 108 r1, _, e1 := syscall.Syscall(procGlobalMemoryStatusEx.Addr(), 1, uintptr(unsafe.Pointer(buffer)), 0, 0) 109 if r1 == 0 { 110 if e1 != 0 { 111 err = errnoErr(e1) 112 } else { 113 err = syscall.EINVAL 114 } 115 } 116 return 117} 118 119func _ReadProcessMemory(handle syscall.Handle, baseAddress uintptr, buffer uintptr, size uintptr, numRead *uintptr) (err error) { 120 r1, _, e1 := syscall.Syscall6(procReadProcessMemory.Addr(), 5, uintptr(handle), uintptr(baseAddress), uintptr(buffer), uintptr(size), uintptr(unsafe.Pointer(numRead)), 0) 121 if r1 == 0 { 122 if e1 != 0 { 123 err = errnoErr(e1) 124 } else { 125 err = syscall.EINVAL 126 } 127 } 128 return 129} 130 131func _GetProcessHandleCount(handle syscall.Handle, pdwHandleCount *uint32) (err error) { 132 r1, _, e1 := syscall.Syscall(procGetProcessHandleCount.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(pdwHandleCount)), 0) 133 if r1 == 0 { 134 if e1 != 0 { 135 err = errnoErr(e1) 136 } else { 137 err = syscall.EINVAL 138 } 139 } 140 return 141} 142 143func _GetFileVersionInfo(filename string, reserved uint32, dataLen uint32, data *byte) (success bool, err error) { 144 var _p0 *uint16 145 _p0, err = syscall.UTF16PtrFromString(filename) 146 if err != nil { 147 return 148 } 149 return __GetFileVersionInfo(_p0, reserved, dataLen, data) 150} 151 152func __GetFileVersionInfo(filename *uint16, reserved uint32, dataLen uint32, data *byte) (success bool, err error) { 153 r0, _, e1 := syscall.Syscall6(procGetFileVersionInfoW.Addr(), 4, uintptr(unsafe.Pointer(filename)), uintptr(reserved), uintptr(dataLen), uintptr(unsafe.Pointer(data)), 0, 0) 154 success = r0 != 0 155 if !success { 156 if e1 != 0 { 157 err = errnoErr(e1) 158 } else { 159 err = syscall.EINVAL 160 } 161 } 162 return 163} 164 165func _GetFileVersionInfoSize(filename string, handle uintptr) (size uint32, err error) { 166 var _p0 *uint16 167 _p0, err = syscall.UTF16PtrFromString(filename) 168 if err != nil { 169 return 170 } 171 return __GetFileVersionInfoSize(_p0, handle) 172} 173 174func __GetFileVersionInfoSize(filename *uint16, handle uintptr) (size uint32, err error) { 175 r0, _, e1 := syscall.Syscall(procGetFileVersionInfoSizeW.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(handle), 0) 176 size = uint32(r0) 177 if size == 0 { 178 if e1 != 0 { 179 err = errnoErr(e1) 180 } else { 181 err = syscall.EINVAL 182 } 183 } 184 return 185} 186 187func _VerQueryValueW(data *byte, subBlock string, pBuffer *uintptr, len *uint32) (success bool, err error) { 188 var _p0 *uint16 189 _p0, err = syscall.UTF16PtrFromString(subBlock) 190 if err != nil { 191 return 192 } 193 return __VerQueryValueW(data, _p0, pBuffer, len) 194} 195 196func __VerQueryValueW(data *byte, subBlock *uint16, pBuffer *uintptr, len *uint32) (success bool, err error) { 197 r0, _, e1 := syscall.Syscall6(procVerQueryValueW.Addr(), 4, uintptr(unsafe.Pointer(data)), uintptr(unsafe.Pointer(subBlock)), uintptr(unsafe.Pointer(pBuffer)), uintptr(unsafe.Pointer(len)), 0, 0) 198 success = r0 != 0 199 if !success { 200 if e1 != 0 { 201 err = errnoErr(e1) 202 } else { 203 err = syscall.EINVAL 204 } 205 } 206 return 207} 208 209func _GetProcessMemoryInfo(handle syscall.Handle, psmemCounters *ProcessMemoryCountersEx, cb uint32) (err error) { 210 r1, _, e1 := syscall.Syscall(procGetProcessMemoryInfo.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(psmemCounters)), uintptr(cb)) 211 if r1 == 0 { 212 if e1 != 0 { 213 err = errnoErr(e1) 214 } else { 215 err = syscall.EINVAL 216 } 217 } 218 return 219} 220 221func _GetProcessImageFileNameA(handle syscall.Handle, imageFileName *byte, nSize uint32) (len uint32, err error) { 222 r0, _, e1 := syscall.Syscall(procGetProcessImageFileNameA.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(imageFileName)), uintptr(nSize)) 223 len = uint32(r0) 224 if len == 0 { 225 if e1 != 0 { 226 err = errnoErr(e1) 227 } else { 228 err = syscall.EINVAL 229 } 230 } 231 return 232} 233 234func _EnumProcesses(lpidProcess *uint32, cb uint32, lpcbNeeded *uint32) (err error) { 235 r1, _, e1 := syscall.Syscall(procEnumProcesses.Addr(), 3, uintptr(unsafe.Pointer(lpidProcess)), uintptr(cb), uintptr(unsafe.Pointer(lpcbNeeded))) 236 if r1 == 0 { 237 if e1 != 0 { 238 err = errnoErr(e1) 239 } else { 240 err = syscall.EINVAL 241 } 242 } 243 return 244} 245 246func _NtQueryInformationProcess(handle syscall.Handle, infoClass uint32, info uintptr, infoLen uint32, returnLen *uint32) (ntStatus uint32) { 247 r0, _, _ := syscall.Syscall6(procNtQueryInformationProcess.Addr(), 5, uintptr(handle), uintptr(infoClass), uintptr(info), uintptr(infoLen), uintptr(unsafe.Pointer(returnLen)), 0) 248 ntStatus = uint32(r0) 249 return 250} 251