github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/internal/syscall/windows/zsyscall_windows.go (about) 1 // MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT 2 3 package windows 4 5 import ( 6 "internal/syscall/windows/sysdll" 7 "syscall" 8 "unsafe" 9 ) 10 11 var _ unsafe.Pointer 12 13 // Do the interface allocations only once for common 14 // Errno values. 15 const ( 16 errnoERROR_IO_PENDING = 997 17 ) 18 19 var ( 20 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) 21 ) 22 23 // errnoErr returns common boxed Errno values, to prevent 24 // allocations at runtime. 25 func errnoErr(e syscall.Errno) error { 26 switch e { 27 case 0: 28 return nil 29 case errnoERROR_IO_PENDING: 30 return errERROR_IO_PENDING 31 } 32 // TODO: add more here, after collecting data on the common 33 // error values see on Windows. (perhaps when running 34 // all.bat?) 35 return e 36 } 37 38 var ( 39 modiphlpapi = syscall.NewLazyDLL(sysdll.Add("iphlpapi.dll")) 40 modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll")) 41 modws2_32 = syscall.NewLazyDLL(sysdll.Add("ws2_32.dll")) 42 modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll")) 43 modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll")) 44 moduserenv = syscall.NewLazyDLL(sysdll.Add("userenv.dll")) 45 modpsapi = syscall.NewLazyDLL(sysdll.Add("psapi.dll")) 46 47 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses") 48 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") 49 procMoveFileExW = modkernel32.NewProc("MoveFileExW") 50 procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW") 51 procWSASocketW = modws2_32.NewProc("WSASocketW") 52 procGetACP = modkernel32.NewProc("GetACP") 53 procGetConsoleCP = modkernel32.NewProc("GetConsoleCP") 54 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar") 55 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread") 56 procNetShareAdd = modnetapi32.NewProc("NetShareAdd") 57 procNetShareDel = modnetapi32.NewProc("NetShareDel") 58 procGetFinalPathNameByHandleW = modkernel32.NewProc("GetFinalPathNameByHandleW") 59 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf") 60 procRevertToSelf = modadvapi32.NewProc("RevertToSelf") 61 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken") 62 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW") 63 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges") 64 procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx") 65 procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation") 66 procGetProfilesDirectoryW = moduserenv.NewProc("GetProfilesDirectoryW") 67 procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo") 68 ) 69 70 func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) { 71 r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0) 72 if r0 != 0 { 73 errcode = syscall.Errno(r0) 74 } 75 return 76 } 77 78 func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) { 79 r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) 80 if r1 == 0 { 81 if e1 != 0 { 82 err = errnoErr(e1) 83 } else { 84 err = syscall.EINVAL 85 } 86 } 87 return 88 } 89 90 func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { 91 r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) 92 if r1 == 0 { 93 if e1 != 0 { 94 err = errnoErr(e1) 95 } else { 96 err = syscall.EINVAL 97 } 98 } 99 return 100 } 101 102 func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) { 103 r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len)) 104 n = uint32(r0) 105 if n == 0 { 106 if e1 != 0 { 107 err = errnoErr(e1) 108 } else { 109 err = syscall.EINVAL 110 } 111 } 112 return 113 } 114 115 func WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) { 116 r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protinfo)), uintptr(group), uintptr(flags)) 117 handle = syscall.Handle(r0) 118 if handle == syscall.InvalidHandle { 119 if e1 != 0 { 120 err = errnoErr(e1) 121 } else { 122 err = syscall.EINVAL 123 } 124 } 125 return 126 } 127 128 func GetACP() (acp uint32) { 129 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0) 130 acp = uint32(r0) 131 return 132 } 133 134 func GetConsoleCP() (ccp uint32) { 135 r0, _, _ := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0) 136 ccp = uint32(r0) 137 return 138 } 139 140 func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) { 141 r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar)) 142 nwrite = int32(r0) 143 if nwrite == 0 { 144 if e1 != 0 { 145 err = errnoErr(e1) 146 } else { 147 err = syscall.EINVAL 148 } 149 } 150 return 151 } 152 153 func GetCurrentThread() (pseudoHandle syscall.Handle, err error) { 154 r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0) 155 pseudoHandle = syscall.Handle(r0) 156 if pseudoHandle == 0 { 157 if e1 != 0 { 158 err = errnoErr(e1) 159 } else { 160 err = syscall.EINVAL 161 } 162 } 163 return 164 } 165 166 func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) { 167 r0, _, _ := syscall.Syscall6(procNetShareAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0) 168 if r0 != 0 { 169 neterr = syscall.Errno(r0) 170 } 171 return 172 } 173 174 func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) { 175 r0, _, _ := syscall.Syscall(procNetShareDel.Addr(), 3, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved)) 176 if r0 != 0 { 177 neterr = syscall.Errno(r0) 178 } 179 return 180 } 181 182 func GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) { 183 r0, _, e1 := syscall.Syscall6(procGetFinalPathNameByHandleW.Addr(), 4, uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags), 0, 0) 184 n = uint32(r0) 185 if n == 0 { 186 if e1 != 0 { 187 err = errnoErr(e1) 188 } else { 189 err = syscall.EINVAL 190 } 191 } 192 return 193 } 194 195 func ImpersonateSelf(impersonationlevel uint32) (err error) { 196 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0) 197 if r1 == 0 { 198 if e1 != 0 { 199 err = errnoErr(e1) 200 } else { 201 err = syscall.EINVAL 202 } 203 } 204 return 205 } 206 207 func RevertToSelf() (err error) { 208 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0) 209 if r1 == 0 { 210 if e1 != 0 { 211 err = errnoErr(e1) 212 } else { 213 err = syscall.EINVAL 214 } 215 } 216 return 217 } 218 219 func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) { 220 var _p0 uint32 221 if openasself { 222 _p0 = 1 223 } else { 224 _p0 = 0 225 } 226 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0) 227 if r1 == 0 { 228 if e1 != 0 { 229 err = errnoErr(e1) 230 } else { 231 err = syscall.EINVAL 232 } 233 } 234 return 235 } 236 237 func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) { 238 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid))) 239 if r1 == 0 { 240 if e1 != 0 { 241 err = errnoErr(e1) 242 } else { 243 err = syscall.EINVAL 244 } 245 } 246 return 247 } 248 249 func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) { 250 var _p0 uint32 251 if disableAllPrivileges { 252 _p0 = 1 253 } else { 254 _p0 = 0 255 } 256 r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen))) 257 ret = uint32(r0) 258 if true { 259 if e1 != 0 { 260 err = errnoErr(e1) 261 } else { 262 err = syscall.EINVAL 263 } 264 } 265 return 266 } 267 268 func DuplicateTokenEx(hExistingToken syscall.Token, dwDesiredAccess uint32, lpTokenAttributes *syscall.SecurityAttributes, impersonationLevel uint32, tokenType TokenType, phNewToken *syscall.Token) (err error) { 269 r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpTokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(phNewToken))) 270 if r1 == 0 { 271 if e1 != 0 { 272 err = errnoErr(e1) 273 } else { 274 err = syscall.EINVAL 275 } 276 } 277 return 278 } 279 280 func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass uint32, tokenInformation uintptr, tokenInformationLength uint32) (err error) { 281 r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(tokenHandle), uintptr(tokenInformationClass), uintptr(tokenInformation), uintptr(tokenInformationLength), 0, 0) 282 if r1 == 0 { 283 if e1 != 0 { 284 err = errnoErr(e1) 285 } else { 286 err = syscall.EINVAL 287 } 288 } 289 return 290 } 291 292 func GetProfilesDirectory(dir *uint16, dirLen *uint32) (err error) { 293 r1, _, e1 := syscall.Syscall(procGetProfilesDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)), 0) 294 if r1 == 0 { 295 if e1 != 0 { 296 err = errnoErr(e1) 297 } else { 298 err = syscall.EINVAL 299 } 300 } 301 return 302 } 303 304 func GetProcessMemoryInfo(handle syscall.Handle, memCounters *PROCESS_MEMORY_COUNTERS, cb uint32) (err error) { 305 r1, _, e1 := syscall.Syscall(procGetProcessMemoryInfo.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(memCounters)), uintptr(cb)) 306 if r1 == 0 { 307 if e1 != 0 { 308 err = errnoErr(e1) 309 } else { 310 err = syscall.EINVAL 311 } 312 } 313 return 314 }