github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/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 modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll")) 42 modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll")) 43 44 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses") 45 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") 46 procMoveFileExW = modkernel32.NewProc("MoveFileExW") 47 procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW") 48 procGetACP = modkernel32.NewProc("GetACP") 49 procGetConsoleCP = modkernel32.NewProc("GetConsoleCP") 50 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar") 51 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread") 52 procNetShareAdd = modnetapi32.NewProc("NetShareAdd") 53 procNetShareDel = modnetapi32.NewProc("NetShareDel") 54 procGetFinalPathNameByHandleW = modkernel32.NewProc("GetFinalPathNameByHandleW") 55 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf") 56 procRevertToSelf = modadvapi32.NewProc("RevertToSelf") 57 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken") 58 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW") 59 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges") 60 ) 61 62 func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) { 63 r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0) 64 if r0 != 0 { 65 errcode = syscall.Errno(r0) 66 } 67 return 68 } 69 70 func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) { 71 r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) 72 if r1 == 0 { 73 if e1 != 0 { 74 err = errnoErr(e1) 75 } else { 76 err = syscall.EINVAL 77 } 78 } 79 return 80 } 81 82 func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { 83 r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) 84 if r1 == 0 { 85 if e1 != 0 { 86 err = errnoErr(e1) 87 } else { 88 err = syscall.EINVAL 89 } 90 } 91 return 92 } 93 94 func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) { 95 r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len)) 96 n = uint32(r0) 97 if n == 0 { 98 if e1 != 0 { 99 err = errnoErr(e1) 100 } else { 101 err = syscall.EINVAL 102 } 103 } 104 return 105 } 106 107 func GetACP() (acp uint32) { 108 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0) 109 acp = uint32(r0) 110 return 111 } 112 113 func GetConsoleCP() (ccp uint32) { 114 r0, _, _ := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0) 115 ccp = uint32(r0) 116 return 117 } 118 119 func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) { 120 r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar)) 121 nwrite = int32(r0) 122 if nwrite == 0 { 123 if e1 != 0 { 124 err = errnoErr(e1) 125 } else { 126 err = syscall.EINVAL 127 } 128 } 129 return 130 } 131 132 func GetCurrentThread() (pseudoHandle syscall.Handle, err error) { 133 r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0) 134 pseudoHandle = syscall.Handle(r0) 135 if pseudoHandle == 0 { 136 if e1 != 0 { 137 err = errnoErr(e1) 138 } else { 139 err = syscall.EINVAL 140 } 141 } 142 return 143 } 144 145 func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) { 146 r0, _, _ := syscall.Syscall6(procNetShareAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0) 147 if r0 != 0 { 148 neterr = syscall.Errno(r0) 149 } 150 return 151 } 152 153 func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) { 154 r0, _, _ := syscall.Syscall(procNetShareDel.Addr(), 3, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved)) 155 if r0 != 0 { 156 neterr = syscall.Errno(r0) 157 } 158 return 159 } 160 161 func GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) { 162 r0, _, e1 := syscall.Syscall6(procGetFinalPathNameByHandleW.Addr(), 4, uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags), 0, 0) 163 n = uint32(r0) 164 if n == 0 { 165 if e1 != 0 { 166 err = errnoErr(e1) 167 } else { 168 err = syscall.EINVAL 169 } 170 } 171 return 172 } 173 174 func ImpersonateSelf(impersonationlevel uint32) (err error) { 175 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0) 176 if r1 == 0 { 177 if e1 != 0 { 178 err = errnoErr(e1) 179 } else { 180 err = syscall.EINVAL 181 } 182 } 183 return 184 } 185 186 func RevertToSelf() (err error) { 187 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0) 188 if r1 == 0 { 189 if e1 != 0 { 190 err = errnoErr(e1) 191 } else { 192 err = syscall.EINVAL 193 } 194 } 195 return 196 } 197 198 func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) { 199 var _p0 uint32 200 if openasself { 201 _p0 = 1 202 } else { 203 _p0 = 0 204 } 205 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0) 206 if r1 == 0 { 207 if e1 != 0 { 208 err = errnoErr(e1) 209 } else { 210 err = syscall.EINVAL 211 } 212 } 213 return 214 } 215 216 func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) { 217 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid))) 218 if r1 == 0 { 219 if e1 != 0 { 220 err = errnoErr(e1) 221 } else { 222 err = syscall.EINVAL 223 } 224 } 225 return 226 } 227 228 func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) { 229 var _p0 uint32 230 if disableAllPrivileges { 231 _p0 = 1 232 } else { 233 _p0 = 0 234 } 235 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))) 236 ret = uint32(r0) 237 if true { 238 if e1 != 0 { 239 err = errnoErr(e1) 240 } else { 241 err = syscall.EINVAL 242 } 243 } 244 return 245 }