...
Run Format

Source file src/syscall/zsyscall_windows.go

Documentation: syscall

     1  // Code generated by 'go generate'; DO NOT EDIT.
     2  
     3  package syscall
     4  
     5  import (
     6  	"internal/syscall/windows/sysdll"
     7  	"unsafe"
     8  )
     9  
    10  var _ unsafe.Pointer
    11  
    12  // Do the interface allocations only once for common
    13  // Errno values.
    14  const (
    15  	errnoERROR_IO_PENDING = 997
    16  )
    17  
    18  var (
    19  	errERROR_IO_PENDING error = Errno(errnoERROR_IO_PENDING)
    20  )
    21  
    22  // errnoErr returns common boxed Errno values, to prevent
    23  // allocations at runtime.
    24  func errnoErr(e Errno) error {
    25  	switch e {
    26  	case 0:
    27  		return nil
    28  	case errnoERROR_IO_PENDING:
    29  		return errERROR_IO_PENDING
    30  	}
    31  	// TODO: add more here, after collecting data on the common
    32  	// error values see on Windows. (perhaps when running
    33  	// all.bat?)
    34  	return e
    35  }
    36  
    37  var (
    38  	modkernel32 = NewLazyDLL(sysdll.Add("kernel32.dll"))
    39  	modadvapi32 = NewLazyDLL(sysdll.Add("advapi32.dll"))
    40  	modshell32  = NewLazyDLL(sysdll.Add("shell32.dll"))
    41  	modmswsock  = NewLazyDLL(sysdll.Add("mswsock.dll"))
    42  	modcrypt32  = NewLazyDLL(sysdll.Add("crypt32.dll"))
    43  	modws2_32   = NewLazyDLL(sysdll.Add("ws2_32.dll"))
    44  	moddnsapi   = NewLazyDLL(sysdll.Add("dnsapi.dll"))
    45  	modiphlpapi = NewLazyDLL(sysdll.Add("iphlpapi.dll"))
    46  	modsecur32  = NewLazyDLL(sysdll.Add("secur32.dll"))
    47  	modnetapi32 = NewLazyDLL(sysdll.Add("netapi32.dll"))
    48  	moduserenv  = NewLazyDLL(sysdll.Add("userenv.dll"))
    49  
    50  	procGetLastError                       = modkernel32.NewProc("GetLastError")
    51  	procLoadLibraryW                       = modkernel32.NewProc("LoadLibraryW")
    52  	procFreeLibrary                        = modkernel32.NewProc("FreeLibrary")
    53  	procGetProcAddress                     = modkernel32.NewProc("GetProcAddress")
    54  	procGetVersion                         = modkernel32.NewProc("GetVersion")
    55  	procFormatMessageW                     = modkernel32.NewProc("FormatMessageW")
    56  	procExitProcess                        = modkernel32.NewProc("ExitProcess")
    57  	procCreateFileW                        = modkernel32.NewProc("CreateFileW")
    58  	procReadFile                           = modkernel32.NewProc("ReadFile")
    59  	procWriteFile                          = modkernel32.NewProc("WriteFile")
    60  	procSetFilePointer                     = modkernel32.NewProc("SetFilePointer")
    61  	procCloseHandle                        = modkernel32.NewProc("CloseHandle")
    62  	procGetStdHandle                       = modkernel32.NewProc("GetStdHandle")
    63  	procFindFirstFileW                     = modkernel32.NewProc("FindFirstFileW")
    64  	procFindNextFileW                      = modkernel32.NewProc("FindNextFileW")
    65  	procFindClose                          = modkernel32.NewProc("FindClose")
    66  	procGetFileInformationByHandle         = modkernel32.NewProc("GetFileInformationByHandle")
    67  	procGetCurrentDirectoryW               = modkernel32.NewProc("GetCurrentDirectoryW")
    68  	procSetCurrentDirectoryW               = modkernel32.NewProc("SetCurrentDirectoryW")
    69  	procCreateDirectoryW                   = modkernel32.NewProc("CreateDirectoryW")
    70  	procRemoveDirectoryW                   = modkernel32.NewProc("RemoveDirectoryW")
    71  	procDeleteFileW                        = modkernel32.NewProc("DeleteFileW")
    72  	procMoveFileW                          = modkernel32.NewProc("MoveFileW")
    73  	procGetComputerNameW                   = modkernel32.NewProc("GetComputerNameW")
    74  	procSetEndOfFile                       = modkernel32.NewProc("SetEndOfFile")
    75  	procGetSystemTimeAsFileTime            = modkernel32.NewProc("GetSystemTimeAsFileTime")
    76  	procGetTimeZoneInformation             = modkernel32.NewProc("GetTimeZoneInformation")
    77  	procCreateIoCompletionPort             = modkernel32.NewProc("CreateIoCompletionPort")
    78  	procGetQueuedCompletionStatus          = modkernel32.NewProc("GetQueuedCompletionStatus")
    79  	procPostQueuedCompletionStatus         = modkernel32.NewProc("PostQueuedCompletionStatus")
    80  	procCancelIo                           = modkernel32.NewProc("CancelIo")
    81  	procCancelIoEx                         = modkernel32.NewProc("CancelIoEx")
    82  	procCreateProcessW                     = modkernel32.NewProc("CreateProcessW")
    83  	procCreateProcessAsUserW               = modadvapi32.NewProc("CreateProcessAsUserW")
    84  	procOpenProcess                        = modkernel32.NewProc("OpenProcess")
    85  	procTerminateProcess                   = modkernel32.NewProc("TerminateProcess")
    86  	procGetExitCodeProcess                 = modkernel32.NewProc("GetExitCodeProcess")
    87  	procGetStartupInfoW                    = modkernel32.NewProc("GetStartupInfoW")
    88  	procGetCurrentProcess                  = modkernel32.NewProc("GetCurrentProcess")
    89  	procGetProcessTimes                    = modkernel32.NewProc("GetProcessTimes")
    90  	procDuplicateHandle                    = modkernel32.NewProc("DuplicateHandle")
    91  	procWaitForSingleObject                = modkernel32.NewProc("WaitForSingleObject")
    92  	procGetTempPathW                       = modkernel32.NewProc("GetTempPathW")
    93  	procCreatePipe                         = modkernel32.NewProc("CreatePipe")
    94  	procGetFileType                        = modkernel32.NewProc("GetFileType")
    95  	procCryptAcquireContextW               = modadvapi32.NewProc("CryptAcquireContextW")
    96  	procCryptReleaseContext                = modadvapi32.NewProc("CryptReleaseContext")
    97  	procCryptGenRandom                     = modadvapi32.NewProc("CryptGenRandom")
    98  	procGetEnvironmentStringsW             = modkernel32.NewProc("GetEnvironmentStringsW")
    99  	procFreeEnvironmentStringsW            = modkernel32.NewProc("FreeEnvironmentStringsW")
   100  	procGetEnvironmentVariableW            = modkernel32.NewProc("GetEnvironmentVariableW")
   101  	procSetEnvironmentVariableW            = modkernel32.NewProc("SetEnvironmentVariableW")
   102  	procSetFileTime                        = modkernel32.NewProc("SetFileTime")
   103  	procGetFileAttributesW                 = modkernel32.NewProc("GetFileAttributesW")
   104  	procSetFileAttributesW                 = modkernel32.NewProc("SetFileAttributesW")
   105  	procGetFileAttributesExW               = modkernel32.NewProc("GetFileAttributesExW")
   106  	procGetCommandLineW                    = modkernel32.NewProc("GetCommandLineW")
   107  	procCommandLineToArgvW                 = modshell32.NewProc("CommandLineToArgvW")
   108  	procLocalFree                          = modkernel32.NewProc("LocalFree")
   109  	procSetHandleInformation               = modkernel32.NewProc("SetHandleInformation")
   110  	procFlushFileBuffers                   = modkernel32.NewProc("FlushFileBuffers")
   111  	procGetFullPathNameW                   = modkernel32.NewProc("GetFullPathNameW")
   112  	procGetLongPathNameW                   = modkernel32.NewProc("GetLongPathNameW")
   113  	procGetShortPathNameW                  = modkernel32.NewProc("GetShortPathNameW")
   114  	procCreateFileMappingW                 = modkernel32.NewProc("CreateFileMappingW")
   115  	procMapViewOfFile                      = modkernel32.NewProc("MapViewOfFile")
   116  	procUnmapViewOfFile                    = modkernel32.NewProc("UnmapViewOfFile")
   117  	procFlushViewOfFile                    = modkernel32.NewProc("FlushViewOfFile")
   118  	procVirtualLock                        = modkernel32.NewProc("VirtualLock")
   119  	procVirtualUnlock                      = modkernel32.NewProc("VirtualUnlock")
   120  	procTransmitFile                       = modmswsock.NewProc("TransmitFile")
   121  	procReadDirectoryChangesW              = modkernel32.NewProc("ReadDirectoryChangesW")
   122  	procCertOpenSystemStoreW               = modcrypt32.NewProc("CertOpenSystemStoreW")
   123  	procCertOpenStore                      = modcrypt32.NewProc("CertOpenStore")
   124  	procCertEnumCertificatesInStore        = modcrypt32.NewProc("CertEnumCertificatesInStore")
   125  	procCertAddCertificateContextToStore   = modcrypt32.NewProc("CertAddCertificateContextToStore")
   126  	procCertCloseStore                     = modcrypt32.NewProc("CertCloseStore")
   127  	procCertGetCertificateChain            = modcrypt32.NewProc("CertGetCertificateChain")
   128  	procCertFreeCertificateChain           = modcrypt32.NewProc("CertFreeCertificateChain")
   129  	procCertCreateCertificateContext       = modcrypt32.NewProc("CertCreateCertificateContext")
   130  	procCertFreeCertificateContext         = modcrypt32.NewProc("CertFreeCertificateContext")
   131  	procCertVerifyCertificateChainPolicy   = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
   132  	procRegOpenKeyExW                      = modadvapi32.NewProc("RegOpenKeyExW")
   133  	procRegCloseKey                        = modadvapi32.NewProc("RegCloseKey")
   134  	procRegQueryInfoKeyW                   = modadvapi32.NewProc("RegQueryInfoKeyW")
   135  	procRegEnumKeyExW                      = modadvapi32.NewProc("RegEnumKeyExW")
   136  	procRegQueryValueExW                   = modadvapi32.NewProc("RegQueryValueExW")
   137  	procGetCurrentProcessId                = modkernel32.NewProc("GetCurrentProcessId")
   138  	procGetConsoleMode                     = modkernel32.NewProc("GetConsoleMode")
   139  	procWriteConsoleW                      = modkernel32.NewProc("WriteConsoleW")
   140  	procReadConsoleW                       = modkernel32.NewProc("ReadConsoleW")
   141  	procCreateToolhelp32Snapshot           = modkernel32.NewProc("CreateToolhelp32Snapshot")
   142  	procProcess32FirstW                    = modkernel32.NewProc("Process32FirstW")
   143  	procProcess32NextW                     = modkernel32.NewProc("Process32NextW")
   144  	procDeviceIoControl                    = modkernel32.NewProc("DeviceIoControl")
   145  	procCreateSymbolicLinkW                = modkernel32.NewProc("CreateSymbolicLinkW")
   146  	procCreateHardLinkW                    = modkernel32.NewProc("CreateHardLinkW")
   147  	procWSAStartup                         = modws2_32.NewProc("WSAStartup")
   148  	procWSACleanup                         = modws2_32.NewProc("WSACleanup")
   149  	procWSAIoctl                           = modws2_32.NewProc("WSAIoctl")
   150  	procsocket                             = modws2_32.NewProc("socket")
   151  	procsetsockopt                         = modws2_32.NewProc("setsockopt")
   152  	procgetsockopt                         = modws2_32.NewProc("getsockopt")
   153  	procbind                               = modws2_32.NewProc("bind")
   154  	procconnect                            = modws2_32.NewProc("connect")
   155  	procgetsockname                        = modws2_32.NewProc("getsockname")
   156  	procgetpeername                        = modws2_32.NewProc("getpeername")
   157  	proclisten                             = modws2_32.NewProc("listen")
   158  	procshutdown                           = modws2_32.NewProc("shutdown")
   159  	procclosesocket                        = modws2_32.NewProc("closesocket")
   160  	procAcceptEx                           = modmswsock.NewProc("AcceptEx")
   161  	procGetAcceptExSockaddrs               = modmswsock.NewProc("GetAcceptExSockaddrs")
   162  	procWSARecv                            = modws2_32.NewProc("WSARecv")
   163  	procWSASend                            = modws2_32.NewProc("WSASend")
   164  	procWSARecvFrom                        = modws2_32.NewProc("WSARecvFrom")
   165  	procWSASendTo                          = modws2_32.NewProc("WSASendTo")
   166  	procgethostbyname                      = modws2_32.NewProc("gethostbyname")
   167  	procgetservbyname                      = modws2_32.NewProc("getservbyname")
   168  	procntohs                              = modws2_32.NewProc("ntohs")
   169  	procgetprotobyname                     = modws2_32.NewProc("getprotobyname")
   170  	procDnsQuery_W                         = moddnsapi.NewProc("DnsQuery_W")
   171  	procDnsRecordListFree                  = moddnsapi.NewProc("DnsRecordListFree")
   172  	procDnsNameCompare_W                   = moddnsapi.NewProc("DnsNameCompare_W")
   173  	procGetAddrInfoW                       = modws2_32.NewProc("GetAddrInfoW")
   174  	procFreeAddrInfoW                      = modws2_32.NewProc("FreeAddrInfoW")
   175  	procGetIfEntry                         = modiphlpapi.NewProc("GetIfEntry")
   176  	procGetAdaptersInfo                    = modiphlpapi.NewProc("GetAdaptersInfo")
   177  	procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
   178  	procWSAEnumProtocolsW                  = modws2_32.NewProc("WSAEnumProtocolsW")
   179  	procTranslateNameW                     = modsecur32.NewProc("TranslateNameW")
   180  	procGetUserNameExW                     = modsecur32.NewProc("GetUserNameExW")
   181  	procNetUserGetInfo                     = modnetapi32.NewProc("NetUserGetInfo")
   182  	procNetGetJoinInformation              = modnetapi32.NewProc("NetGetJoinInformation")
   183  	procNetApiBufferFree                   = modnetapi32.NewProc("NetApiBufferFree")
   184  	procLookupAccountSidW                  = modadvapi32.NewProc("LookupAccountSidW")
   185  	procLookupAccountNameW                 = modadvapi32.NewProc("LookupAccountNameW")
   186  	procConvertSidToStringSidW             = modadvapi32.NewProc("ConvertSidToStringSidW")
   187  	procConvertStringSidToSidW             = modadvapi32.NewProc("ConvertStringSidToSidW")
   188  	procGetLengthSid                       = modadvapi32.NewProc("GetLengthSid")
   189  	procCopySid                            = modadvapi32.NewProc("CopySid")
   190  	procOpenProcessToken                   = modadvapi32.NewProc("OpenProcessToken")
   191  	procGetTokenInformation                = modadvapi32.NewProc("GetTokenInformation")
   192  	procGetUserProfileDirectoryW           = moduserenv.NewProc("GetUserProfileDirectoryW")
   193  	procGetSystemDirectoryW                = modkernel32.NewProc("GetSystemDirectoryW")
   194  )
   195  
   196  func GetLastError() (lasterr error) {
   197  	r0, _, _ := Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
   198  	if r0 != 0 {
   199  		lasterr = Errno(r0)
   200  	}
   201  	return
   202  }
   203  
   204  func LoadLibrary(libname string) (handle Handle, err error) {
   205  	var _p0 *uint16
   206  	_p0, err = UTF16PtrFromString(libname)
   207  	if err != nil {
   208  		return
   209  	}
   210  	return _LoadLibrary(_p0)
   211  }
   212  
   213  func _LoadLibrary(libname *uint16) (handle Handle, err error) {
   214  	r0, _, e1 := Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
   215  	handle = Handle(r0)
   216  	if handle == 0 {
   217  		if e1 != 0 {
   218  			err = errnoErr(e1)
   219  		} else {
   220  			err = EINVAL
   221  		}
   222  	}
   223  	return
   224  }
   225  
   226  func FreeLibrary(handle Handle) (err error) {
   227  	r1, _, e1 := Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
   228  	if r1 == 0 {
   229  		if e1 != 0 {
   230  			err = errnoErr(e1)
   231  		} else {
   232  			err = EINVAL
   233  		}
   234  	}
   235  	return
   236  }
   237  
   238  func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
   239  	var _p0 *byte
   240  	_p0, err = BytePtrFromString(procname)
   241  	if err != nil {
   242  		return
   243  	}
   244  	return _GetProcAddress(module, _p0)
   245  }
   246  
   247  func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
   248  	r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
   249  	proc = uintptr(r0)
   250  	if proc == 0 {
   251  		if e1 != 0 {
   252  			err = errnoErr(e1)
   253  		} else {
   254  			err = EINVAL
   255  		}
   256  	}
   257  	return
   258  }
   259  
   260  func GetVersion() (ver uint32, err error) {
   261  	r0, _, e1 := Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
   262  	ver = uint32(r0)
   263  	if ver == 0 {
   264  		if e1 != 0 {
   265  			err = errnoErr(e1)
   266  		} else {
   267  			err = EINVAL
   268  		}
   269  	}
   270  	return
   271  }
   272  
   273  func formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
   274  	var _p0 *uint16
   275  	if len(buf) > 0 {
   276  		_p0 = &buf[0]
   277  	}
   278  	r0, _, e1 := Syscall9(procFormatMessageW.Addr(), 7, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0)
   279  	n = uint32(r0)
   280  	if n == 0 {
   281  		if e1 != 0 {
   282  			err = errnoErr(e1)
   283  		} else {
   284  			err = EINVAL
   285  		}
   286  	}
   287  	return
   288  }
   289  
   290  func ExitProcess(exitcode uint32) {
   291  	Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
   292  	return
   293  }
   294  
   295  func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) {
   296  	r0, _, e1 := Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
   297  	handle = Handle(r0)
   298  	if handle == InvalidHandle {
   299  		if e1 != 0 {
   300  			err = errnoErr(e1)
   301  		} else {
   302  			err = EINVAL
   303  		}
   304  	}
   305  	return
   306  }
   307  
   308  func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
   309  	var _p0 *byte
   310  	if len(buf) > 0 {
   311  		_p0 = &buf[0]
   312  	}
   313  	r1, _, e1 := Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
   314  	if r1 == 0 {
   315  		if e1 != 0 {
   316  			err = errnoErr(e1)
   317  		} else {
   318  			err = EINVAL
   319  		}
   320  	}
   321  	return
   322  }
   323  
   324  func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
   325  	var _p0 *byte
   326  	if len(buf) > 0 {
   327  		_p0 = &buf[0]
   328  	}
   329  	r1, _, e1 := Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
   330  	if r1 == 0 {
   331  		if e1 != 0 {
   332  			err = errnoErr(e1)
   333  		} else {
   334  			err = EINVAL
   335  		}
   336  	}
   337  	return
   338  }
   339  
   340  func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
   341  	r0, _, e1 := Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
   342  	newlowoffset = uint32(r0)
   343  	if newlowoffset == 0xffffffff {
   344  		if e1 != 0 {
   345  			err = errnoErr(e1)
   346  		} else {
   347  			err = EINVAL
   348  		}
   349  	}
   350  	return
   351  }
   352  
   353  func CloseHandle(handle Handle) (err error) {
   354  	r1, _, e1 := Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
   355  	if r1 == 0 {
   356  		if e1 != 0 {
   357  			err = errnoErr(e1)
   358  		} else {
   359  			err = EINVAL
   360  		}
   361  	}
   362  	return
   363  }
   364  
   365  func GetStdHandle(stdhandle int) (handle Handle, err error) {
   366  	r0, _, e1 := Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
   367  	handle = Handle(r0)
   368  	if handle == InvalidHandle {
   369  		if e1 != 0 {
   370  			err = errnoErr(e1)
   371  		} else {
   372  			err = EINVAL
   373  		}
   374  	}
   375  	return
   376  }
   377  
   378  func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
   379  	r0, _, e1 := Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
   380  	handle = Handle(r0)
   381  	if handle == InvalidHandle {
   382  		if e1 != 0 {
   383  			err = errnoErr(e1)
   384  		} else {
   385  			err = EINVAL
   386  		}
   387  	}
   388  	return
   389  }
   390  
   391  func findNextFile1(handle Handle, data *win32finddata1) (err error) {
   392  	r1, _, e1 := Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
   393  	if r1 == 0 {
   394  		if e1 != 0 {
   395  			err = errnoErr(e1)
   396  		} else {
   397  			err = EINVAL
   398  		}
   399  	}
   400  	return
   401  }
   402  
   403  func FindClose(handle Handle) (err error) {
   404  	r1, _, e1 := Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
   405  	if r1 == 0 {
   406  		if e1 != 0 {
   407  			err = errnoErr(e1)
   408  		} else {
   409  			err = EINVAL
   410  		}
   411  	}
   412  	return
   413  }
   414  
   415  func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
   416  	r1, _, e1 := Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
   417  	if r1 == 0 {
   418  		if e1 != 0 {
   419  			err = errnoErr(e1)
   420  		} else {
   421  			err = EINVAL
   422  		}
   423  	}
   424  	return
   425  }
   426  
   427  func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
   428  	r0, _, e1 := Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
   429  	n = uint32(r0)
   430  	if n == 0 {
   431  		if e1 != 0 {
   432  			err = errnoErr(e1)
   433  		} else {
   434  			err = EINVAL
   435  		}
   436  	}
   437  	return
   438  }
   439  
   440  func SetCurrentDirectory(path *uint16) (err error) {
   441  	r1, _, e1 := Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
   442  	if r1 == 0 {
   443  		if e1 != 0 {
   444  			err = errnoErr(e1)
   445  		} else {
   446  			err = EINVAL
   447  		}
   448  	}
   449  	return
   450  }
   451  
   452  func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
   453  	r1, _, e1 := Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
   454  	if r1 == 0 {
   455  		if e1 != 0 {
   456  			err = errnoErr(e1)
   457  		} else {
   458  			err = EINVAL
   459  		}
   460  	}
   461  	return
   462  }
   463  
   464  func RemoveDirectory(path *uint16) (err error) {
   465  	r1, _, e1 := Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
   466  	if r1 == 0 {
   467  		if e1 != 0 {
   468  			err = errnoErr(e1)
   469  		} else {
   470  			err = EINVAL
   471  		}
   472  	}
   473  	return
   474  }
   475  
   476  func DeleteFile(path *uint16) (err error) {
   477  	r1, _, e1 := Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
   478  	if r1 == 0 {
   479  		if e1 != 0 {
   480  			err = errnoErr(e1)
   481  		} else {
   482  			err = EINVAL
   483  		}
   484  	}
   485  	return
   486  }
   487  
   488  func MoveFile(from *uint16, to *uint16) (err error) {
   489  	r1, _, e1 := Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
   490  	if r1 == 0 {
   491  		if e1 != 0 {
   492  			err = errnoErr(e1)
   493  		} else {
   494  			err = EINVAL
   495  		}
   496  	}
   497  	return
   498  }
   499  
   500  func GetComputerName(buf *uint16, n *uint32) (err error) {
   501  	r1, _, e1 := Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
   502  	if r1 == 0 {
   503  		if e1 != 0 {
   504  			err = errnoErr(e1)
   505  		} else {
   506  			err = EINVAL
   507  		}
   508  	}
   509  	return
   510  }
   511  
   512  func SetEndOfFile(handle Handle) (err error) {
   513  	r1, _, e1 := Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
   514  	if r1 == 0 {
   515  		if e1 != 0 {
   516  			err = errnoErr(e1)
   517  		} else {
   518  			err = EINVAL
   519  		}
   520  	}
   521  	return
   522  }
   523  
   524  func GetSystemTimeAsFileTime(time *Filetime) {
   525  	Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
   526  	return
   527  }
   528  
   529  func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
   530  	r0, _, e1 := Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
   531  	rc = uint32(r0)
   532  	if rc == 0xffffffff {
   533  		if e1 != 0 {
   534  			err = errnoErr(e1)
   535  		} else {
   536  			err = EINVAL
   537  		}
   538  	}
   539  	return
   540  }
   541  
   542  func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
   543  	r0, _, e1 := Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
   544  	handle = Handle(r0)
   545  	if handle == 0 {
   546  		if e1 != 0 {
   547  			err = errnoErr(e1)
   548  		} else {
   549  			err = EINVAL
   550  		}
   551  	}
   552  	return
   553  }
   554  
   555  func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
   556  	r1, _, e1 := Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
   557  	if r1 == 0 {
   558  		if e1 != 0 {
   559  			err = errnoErr(e1)
   560  		} else {
   561  			err = EINVAL
   562  		}
   563  	}
   564  	return
   565  }
   566  
   567  func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
   568  	r1, _, e1 := Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
   569  	if r1 == 0 {
   570  		if e1 != 0 {
   571  			err = errnoErr(e1)
   572  		} else {
   573  			err = EINVAL
   574  		}
   575  	}
   576  	return
   577  }
   578  
   579  func CancelIo(s Handle) (err error) {
   580  	r1, _, e1 := Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
   581  	if r1 == 0 {
   582  		if e1 != 0 {
   583  			err = errnoErr(e1)
   584  		} else {
   585  			err = EINVAL
   586  		}
   587  	}
   588  	return
   589  }
   590  
   591  func CancelIoEx(s Handle, o *Overlapped) (err error) {
   592  	r1, _, e1 := Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
   593  	if r1 == 0 {
   594  		if e1 != 0 {
   595  			err = errnoErr(e1)
   596  		} else {
   597  			err = EINVAL
   598  		}
   599  	}
   600  	return
   601  }
   602  
   603  func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
   604  	var _p0 uint32
   605  	if inheritHandles {
   606  		_p0 = 1
   607  	} else {
   608  		_p0 = 0
   609  	}
   610  	r1, _, e1 := Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0)
   611  	if r1 == 0 {
   612  		if e1 != 0 {
   613  			err = errnoErr(e1)
   614  		} else {
   615  			err = EINVAL
   616  		}
   617  	}
   618  	return
   619  }
   620  
   621  func CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
   622  	var _p0 uint32
   623  	if inheritHandles {
   624  		_p0 = 1
   625  	} else {
   626  		_p0 = 0
   627  	}
   628  	r1, _, e1 := Syscall12(procCreateProcessAsUserW.Addr(), 11, uintptr(token), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0)
   629  	if r1 == 0 {
   630  		if e1 != 0 {
   631  			err = errnoErr(e1)
   632  		} else {
   633  			err = EINVAL
   634  		}
   635  	}
   636  	return
   637  }
   638  
   639  func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
   640  	var _p0 uint32
   641  	if inheritHandle {
   642  		_p0 = 1
   643  	} else {
   644  		_p0 = 0
   645  	}
   646  	r0, _, e1 := Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
   647  	handle = Handle(r0)
   648  	if handle == 0 {
   649  		if e1 != 0 {
   650  			err = errnoErr(e1)
   651  		} else {
   652  			err = EINVAL
   653  		}
   654  	}
   655  	return
   656  }
   657  
   658  func TerminateProcess(handle Handle, exitcode uint32) (err error) {
   659  	r1, _, e1 := Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
   660  	if r1 == 0 {
   661  		if e1 != 0 {
   662  			err = errnoErr(e1)
   663  		} else {
   664  			err = EINVAL
   665  		}
   666  	}
   667  	return
   668  }
   669  
   670  func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
   671  	r1, _, e1 := Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
   672  	if r1 == 0 {
   673  		if e1 != 0 {
   674  			err = errnoErr(e1)
   675  		} else {
   676  			err = EINVAL
   677  		}
   678  	}
   679  	return
   680  }
   681  
   682  func GetStartupInfo(startupInfo *StartupInfo) (err error) {
   683  	r1, _, e1 := Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
   684  	if r1 == 0 {
   685  		if e1 != 0 {
   686  			err = errnoErr(e1)
   687  		} else {
   688  			err = EINVAL
   689  		}
   690  	}
   691  	return
   692  }
   693  
   694  func GetCurrentProcess() (pseudoHandle Handle, err error) {
   695  	r0, _, e1 := Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
   696  	pseudoHandle = Handle(r0)
   697  	if pseudoHandle == 0 {
   698  		if e1 != 0 {
   699  			err = errnoErr(e1)
   700  		} else {
   701  			err = EINVAL
   702  		}
   703  	}
   704  	return
   705  }
   706  
   707  func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
   708  	r1, _, e1 := Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0)
   709  	if r1 == 0 {
   710  		if e1 != 0 {
   711  			err = errnoErr(e1)
   712  		} else {
   713  			err = EINVAL
   714  		}
   715  	}
   716  	return
   717  }
   718  
   719  func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
   720  	var _p0 uint32
   721  	if bInheritHandle {
   722  		_p0 = 1
   723  	} else {
   724  		_p0 = 0
   725  	}
   726  	r1, _, e1 := Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
   727  	if r1 == 0 {
   728  		if e1 != 0 {
   729  			err = errnoErr(e1)
   730  		} else {
   731  			err = EINVAL
   732  		}
   733  	}
   734  	return
   735  }
   736  
   737  func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
   738  	r0, _, e1 := Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
   739  	event = uint32(r0)
   740  	if event == 0xffffffff {
   741  		if e1 != 0 {
   742  			err = errnoErr(e1)
   743  		} else {
   744  			err = EINVAL
   745  		}
   746  	}
   747  	return
   748  }
   749  
   750  func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
   751  	r0, _, e1 := Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
   752  	n = uint32(r0)
   753  	if n == 0 {
   754  		if e1 != 0 {
   755  			err = errnoErr(e1)
   756  		} else {
   757  			err = EINVAL
   758  		}
   759  	}
   760  	return
   761  }
   762  
   763  func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
   764  	r1, _, e1 := Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
   765  	if r1 == 0 {
   766  		if e1 != 0 {
   767  			err = errnoErr(e1)
   768  		} else {
   769  			err = EINVAL
   770  		}
   771  	}
   772  	return
   773  }
   774  
   775  func GetFileType(filehandle Handle) (n uint32, err error) {
   776  	r0, _, e1 := Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
   777  	n = uint32(r0)
   778  	if n == 0 {
   779  		if e1 != 0 {
   780  			err = errnoErr(e1)
   781  		} else {
   782  			err = EINVAL
   783  		}
   784  	}
   785  	return
   786  }
   787  
   788  func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
   789  	r1, _, e1 := Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
   790  	if r1 == 0 {
   791  		if e1 != 0 {
   792  			err = errnoErr(e1)
   793  		} else {
   794  			err = EINVAL
   795  		}
   796  	}
   797  	return
   798  }
   799  
   800  func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
   801  	r1, _, e1 := Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
   802  	if r1 == 0 {
   803  		if e1 != 0 {
   804  			err = errnoErr(e1)
   805  		} else {
   806  			err = EINVAL
   807  		}
   808  	}
   809  	return
   810  }
   811  
   812  func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
   813  	r1, _, e1 := Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
   814  	if r1 == 0 {
   815  		if e1 != 0 {
   816  			err = errnoErr(e1)
   817  		} else {
   818  			err = EINVAL
   819  		}
   820  	}
   821  	return
   822  }
   823  
   824  func GetEnvironmentStrings() (envs *uint16, err error) {
   825  	r0, _, e1 := Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
   826  	envs = (*uint16)(unsafe.Pointer(r0))
   827  	if envs == nil {
   828  		if e1 != 0 {
   829  			err = errnoErr(e1)
   830  		} else {
   831  			err = EINVAL
   832  		}
   833  	}
   834  	return
   835  }
   836  
   837  func FreeEnvironmentStrings(envs *uint16) (err error) {
   838  	r1, _, e1 := Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
   839  	if r1 == 0 {
   840  		if e1 != 0 {
   841  			err = errnoErr(e1)
   842  		} else {
   843  			err = EINVAL
   844  		}
   845  	}
   846  	return
   847  }
   848  
   849  func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
   850  	r0, _, e1 := Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
   851  	n = uint32(r0)
   852  	if n == 0 {
   853  		if e1 != 0 {
   854  			err = errnoErr(e1)
   855  		} else {
   856  			err = EINVAL
   857  		}
   858  	}
   859  	return
   860  }
   861  
   862  func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
   863  	r1, _, e1 := Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
   864  	if r1 == 0 {
   865  		if e1 != 0 {
   866  			err = errnoErr(e1)
   867  		} else {
   868  			err = EINVAL
   869  		}
   870  	}
   871  	return
   872  }
   873  
   874  func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
   875  	r1, _, e1 := Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
   876  	if r1 == 0 {
   877  		if e1 != 0 {
   878  			err = errnoErr(e1)
   879  		} else {
   880  			err = EINVAL
   881  		}
   882  	}
   883  	return
   884  }
   885  
   886  func GetFileAttributes(name *uint16) (attrs uint32, err error) {
   887  	r0, _, e1 := Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
   888  	attrs = uint32(r0)
   889  	if attrs == INVALID_FILE_ATTRIBUTES {
   890  		if e1 != 0 {
   891  			err = errnoErr(e1)
   892  		} else {
   893  			err = EINVAL
   894  		}
   895  	}
   896  	return
   897  }
   898  
   899  func SetFileAttributes(name *uint16, attrs uint32) (err error) {
   900  	r1, _, e1 := Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
   901  	if r1 == 0 {
   902  		if e1 != 0 {
   903  			err = errnoErr(e1)
   904  		} else {
   905  			err = EINVAL
   906  		}
   907  	}
   908  	return
   909  }
   910  
   911  func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
   912  	r1, _, e1 := Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
   913  	if r1 == 0 {
   914  		if e1 != 0 {
   915  			err = errnoErr(e1)
   916  		} else {
   917  			err = EINVAL
   918  		}
   919  	}
   920  	return
   921  }
   922  
   923  func GetCommandLine() (cmd *uint16) {
   924  	r0, _, _ := Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
   925  	cmd = (*uint16)(unsafe.Pointer(r0))
   926  	return
   927  }
   928  
   929  func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
   930  	r0, _, e1 := Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
   931  	argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
   932  	if argv == nil {
   933  		if e1 != 0 {
   934  			err = errnoErr(e1)
   935  		} else {
   936  			err = EINVAL
   937  		}
   938  	}
   939  	return
   940  }
   941  
   942  func LocalFree(hmem Handle) (handle Handle, err error) {
   943  	r0, _, e1 := Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
   944  	handle = Handle(r0)
   945  	if handle != 0 {
   946  		if e1 != 0 {
   947  			err = errnoErr(e1)
   948  		} else {
   949  			err = EINVAL
   950  		}
   951  	}
   952  	return
   953  }
   954  
   955  func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
   956  	r1, _, e1 := Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
   957  	if r1 == 0 {
   958  		if e1 != 0 {
   959  			err = errnoErr(e1)
   960  		} else {
   961  			err = EINVAL
   962  		}
   963  	}
   964  	return
   965  }
   966  
   967  func FlushFileBuffers(handle Handle) (err error) {
   968  	r1, _, e1 := Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
   969  	if r1 == 0 {
   970  		if e1 != 0 {
   971  			err = errnoErr(e1)
   972  		} else {
   973  			err = EINVAL
   974  		}
   975  	}
   976  	return
   977  }
   978  
   979  func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
   980  	r0, _, e1 := Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
   981  	n = uint32(r0)
   982  	if n == 0 {
   983  		if e1 != 0 {
   984  			err = errnoErr(e1)
   985  		} else {
   986  			err = EINVAL
   987  		}
   988  	}
   989  	return
   990  }
   991  
   992  func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
   993  	r0, _, e1 := Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
   994  	n = uint32(r0)
   995  	if n == 0 {
   996  		if e1 != 0 {
   997  			err = errnoErr(e1)
   998  		} else {
   999  			err = EINVAL
  1000  		}
  1001  	}
  1002  	return
  1003  }
  1004  
  1005  func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
  1006  	r0, _, e1 := Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
  1007  	n = uint32(r0)
  1008  	if n == 0 {
  1009  		if e1 != 0 {
  1010  			err = errnoErr(e1)
  1011  		} else {
  1012  			err = EINVAL
  1013  		}
  1014  	}
  1015  	return
  1016  }
  1017  
  1018  func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
  1019  	r0, _, e1 := Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
  1020  	handle = Handle(r0)
  1021  	if handle == 0 {
  1022  		if e1 != 0 {
  1023  			err = errnoErr(e1)
  1024  		} else {
  1025  			err = EINVAL
  1026  		}
  1027  	}
  1028  	return
  1029  }
  1030  
  1031  func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
  1032  	r0, _, e1 := Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
  1033  	addr = uintptr(r0)
  1034  	if addr == 0 {
  1035  		if e1 != 0 {
  1036  			err = errnoErr(e1)
  1037  		} else {
  1038  			err = EINVAL
  1039  		}
  1040  	}
  1041  	return
  1042  }
  1043  
  1044  func UnmapViewOfFile(addr uintptr) (err error) {
  1045  	r1, _, e1 := Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
  1046  	if r1 == 0 {
  1047  		if e1 != 0 {
  1048  			err = errnoErr(e1)
  1049  		} else {
  1050  			err = EINVAL
  1051  		}
  1052  	}
  1053  	return
  1054  }
  1055  
  1056  func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
  1057  	r1, _, e1 := Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1058  	if r1 == 0 {
  1059  		if e1 != 0 {
  1060  			err = errnoErr(e1)
  1061  		} else {
  1062  			err = EINVAL
  1063  		}
  1064  	}
  1065  	return
  1066  }
  1067  
  1068  func VirtualLock(addr uintptr, length uintptr) (err error) {
  1069  	r1, _, e1 := Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1070  	if r1 == 0 {
  1071  		if e1 != 0 {
  1072  			err = errnoErr(e1)
  1073  		} else {
  1074  			err = EINVAL
  1075  		}
  1076  	}
  1077  	return
  1078  }
  1079  
  1080  func VirtualUnlock(addr uintptr, length uintptr) (err error) {
  1081  	r1, _, e1 := Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1082  	if r1 == 0 {
  1083  		if e1 != 0 {
  1084  			err = errnoErr(e1)
  1085  		} else {
  1086  			err = EINVAL
  1087  		}
  1088  	}
  1089  	return
  1090  }
  1091  
  1092  func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
  1093  	r1, _, e1 := Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
  1094  	if r1 == 0 {
  1095  		if e1 != 0 {
  1096  			err = errnoErr(e1)
  1097  		} else {
  1098  			err = EINVAL
  1099  		}
  1100  	}
  1101  	return
  1102  }
  1103  
  1104  func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  1105  	var _p0 uint32
  1106  	if watchSubTree {
  1107  		_p0 = 1
  1108  	} else {
  1109  		_p0 = 0
  1110  	}
  1111  	r1, _, e1 := Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0)
  1112  	if r1 == 0 {
  1113  		if e1 != 0 {
  1114  			err = errnoErr(e1)
  1115  		} else {
  1116  			err = EINVAL
  1117  		}
  1118  	}
  1119  	return
  1120  }
  1121  
  1122  func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
  1123  	r0, _, e1 := Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
  1124  	store = Handle(r0)
  1125  	if store == 0 {
  1126  		if e1 != 0 {
  1127  			err = errnoErr(e1)
  1128  		} else {
  1129  			err = EINVAL
  1130  		}
  1131  	}
  1132  	return
  1133  }
  1134  
  1135  func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
  1136  	r0, _, e1 := Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
  1137  	handle = Handle(r0)
  1138  	if handle == InvalidHandle {
  1139  		if e1 != 0 {
  1140  			err = errnoErr(e1)
  1141  		} else {
  1142  			err = EINVAL
  1143  		}
  1144  	}
  1145  	return
  1146  }
  1147  
  1148  func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
  1149  	r0, _, e1 := Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
  1150  	context = (*CertContext)(unsafe.Pointer(r0))
  1151  	if context == nil {
  1152  		if e1 != 0 {
  1153  			err = errnoErr(e1)
  1154  		} else {
  1155  			err = EINVAL
  1156  		}
  1157  	}
  1158  	return
  1159  }
  1160  
  1161  func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
  1162  	r1, _, e1 := Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
  1163  	if r1 == 0 {
  1164  		if e1 != 0 {
  1165  			err = errnoErr(e1)
  1166  		} else {
  1167  			err = EINVAL
  1168  		}
  1169  	}
  1170  	return
  1171  }
  1172  
  1173  func CertCloseStore(store Handle, flags uint32) (err error) {
  1174  	r1, _, e1 := Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
  1175  	if r1 == 0 {
  1176  		if e1 != 0 {
  1177  			err = errnoErr(e1)
  1178  		} else {
  1179  			err = EINVAL
  1180  		}
  1181  	}
  1182  	return
  1183  }
  1184  
  1185  func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
  1186  	r1, _, e1 := Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0)
  1187  	if r1 == 0 {
  1188  		if e1 != 0 {
  1189  			err = errnoErr(e1)
  1190  		} else {
  1191  			err = EINVAL
  1192  		}
  1193  	}
  1194  	return
  1195  }
  1196  
  1197  func CertFreeCertificateChain(ctx *CertChainContext) {
  1198  	Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1199  	return
  1200  }
  1201  
  1202  func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
  1203  	r0, _, e1 := Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
  1204  	context = (*CertContext)(unsafe.Pointer(r0))
  1205  	if context == nil {
  1206  		if e1 != 0 {
  1207  			err = errnoErr(e1)
  1208  		} else {
  1209  			err = EINVAL
  1210  		}
  1211  	}
  1212  	return
  1213  }
  1214  
  1215  func CertFreeCertificateContext(ctx *CertContext) (err error) {
  1216  	r1, _, e1 := Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1217  	if r1 == 0 {
  1218  		if e1 != 0 {
  1219  			err = errnoErr(e1)
  1220  		} else {
  1221  			err = EINVAL
  1222  		}
  1223  	}
  1224  	return
  1225  }
  1226  
  1227  func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
  1228  	r1, _, e1 := Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
  1229  	if r1 == 0 {
  1230  		if e1 != 0 {
  1231  			err = errnoErr(e1)
  1232  		} else {
  1233  			err = EINVAL
  1234  		}
  1235  	}
  1236  	return
  1237  }
  1238  
  1239  func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
  1240  	r0, _, _ := Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
  1241  	if r0 != 0 {
  1242  		regerrno = Errno(r0)
  1243  	}
  1244  	return
  1245  }
  1246  
  1247  func RegCloseKey(key Handle) (regerrno error) {
  1248  	r0, _, _ := Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
  1249  	if r0 != 0 {
  1250  		regerrno = Errno(r0)
  1251  	}
  1252  	return
  1253  }
  1254  
  1255  func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
  1256  	r0, _, _ := Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
  1257  	if r0 != 0 {
  1258  		regerrno = Errno(r0)
  1259  	}
  1260  	return
  1261  }
  1262  
  1263  func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
  1264  	r0, _, _ := Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
  1265  	if r0 != 0 {
  1266  		regerrno = Errno(r0)
  1267  	}
  1268  	return
  1269  }
  1270  
  1271  func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
  1272  	r0, _, _ := Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
  1273  	if r0 != 0 {
  1274  		regerrno = Errno(r0)
  1275  	}
  1276  	return
  1277  }
  1278  
  1279  func getCurrentProcessId() (pid uint32) {
  1280  	r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
  1281  	pid = uint32(r0)
  1282  	return
  1283  }
  1284  
  1285  func GetConsoleMode(console Handle, mode *uint32) (err error) {
  1286  	r1, _, e1 := Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
  1287  	if r1 == 0 {
  1288  		if e1 != 0 {
  1289  			err = errnoErr(e1)
  1290  		} else {
  1291  			err = EINVAL
  1292  		}
  1293  	}
  1294  	return
  1295  }
  1296  
  1297  func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
  1298  	r1, _, e1 := Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
  1299  	if r1 == 0 {
  1300  		if e1 != 0 {
  1301  			err = errnoErr(e1)
  1302  		} else {
  1303  			err = EINVAL
  1304  		}
  1305  	}
  1306  	return
  1307  }
  1308  
  1309  func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
  1310  	r1, _, e1 := Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
  1311  	if r1 == 0 {
  1312  		if e1 != 0 {
  1313  			err = errnoErr(e1)
  1314  		} else {
  1315  			err = EINVAL
  1316  		}
  1317  	}
  1318  	return
  1319  }
  1320  
  1321  func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
  1322  	r0, _, e1 := Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
  1323  	handle = Handle(r0)
  1324  	if handle == InvalidHandle {
  1325  		if e1 != 0 {
  1326  			err = errnoErr(e1)
  1327  		} else {
  1328  			err = EINVAL
  1329  		}
  1330  	}
  1331  	return
  1332  }
  1333  
  1334  func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1335  	r1, _, e1 := Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1336  	if r1 == 0 {
  1337  		if e1 != 0 {
  1338  			err = errnoErr(e1)
  1339  		} else {
  1340  			err = EINVAL
  1341  		}
  1342  	}
  1343  	return
  1344  }
  1345  
  1346  func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1347  	r1, _, e1 := Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1348  	if r1 == 0 {
  1349  		if e1 != 0 {
  1350  			err = errnoErr(e1)
  1351  		} else {
  1352  			err = EINVAL
  1353  		}
  1354  	}
  1355  	return
  1356  }
  1357  
  1358  func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
  1359  	r1, _, e1 := Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0)
  1360  	if r1 == 0 {
  1361  		if e1 != 0 {
  1362  			err = errnoErr(e1)
  1363  		} else {
  1364  			err = EINVAL
  1365  		}
  1366  	}
  1367  	return
  1368  }
  1369  
  1370  func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
  1371  	r1, _, e1 := Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
  1372  	if r1&0xff == 0 {
  1373  		if e1 != 0 {
  1374  			err = errnoErr(e1)
  1375  		} else {
  1376  			err = EINVAL
  1377  		}
  1378  	}
  1379  	return
  1380  }
  1381  
  1382  func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
  1383  	r1, _, e1 := Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
  1384  	if r1&0xff == 0 {
  1385  		if e1 != 0 {
  1386  			err = errnoErr(e1)
  1387  		} else {
  1388  			err = EINVAL
  1389  		}
  1390  	}
  1391  	return
  1392  }
  1393  
  1394  func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
  1395  	r0, _, _ := Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
  1396  	if r0 != 0 {
  1397  		sockerr = Errno(r0)
  1398  	}
  1399  	return
  1400  }
  1401  
  1402  func WSACleanup() (err error) {
  1403  	r1, _, e1 := Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
  1404  	if r1 == socket_error {
  1405  		if e1 != 0 {
  1406  			err = errnoErr(e1)
  1407  		} else {
  1408  			err = EINVAL
  1409  		}
  1410  	}
  1411  	return
  1412  }
  1413  
  1414  func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  1415  	r1, _, e1 := Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine))
  1416  	if r1 == socket_error {
  1417  		if e1 != 0 {
  1418  			err = errnoErr(e1)
  1419  		} else {
  1420  			err = EINVAL
  1421  		}
  1422  	}
  1423  	return
  1424  }
  1425  
  1426  func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
  1427  	r0, _, e1 := Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
  1428  	handle = Handle(r0)
  1429  	if handle == InvalidHandle {
  1430  		if e1 != 0 {
  1431  			err = errnoErr(e1)
  1432  		} else {
  1433  			err = EINVAL
  1434  		}
  1435  	}
  1436  	return
  1437  }
  1438  
  1439  func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
  1440  	r1, _, e1 := Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
  1441  	if r1 == socket_error {
  1442  		if e1 != 0 {
  1443  			err = errnoErr(e1)
  1444  		} else {
  1445  			err = EINVAL
  1446  		}
  1447  	}
  1448  	return
  1449  }
  1450  
  1451  func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
  1452  	r1, _, e1 := Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
  1453  	if r1 == socket_error {
  1454  		if e1 != 0 {
  1455  			err = errnoErr(e1)
  1456  		} else {
  1457  			err = EINVAL
  1458  		}
  1459  	}
  1460  	return
  1461  }
  1462  
  1463  func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  1464  	r1, _, e1 := Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  1465  	if r1 == socket_error {
  1466  		if e1 != 0 {
  1467  			err = errnoErr(e1)
  1468  		} else {
  1469  			err = EINVAL
  1470  		}
  1471  	}
  1472  	return
  1473  }
  1474  
  1475  func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  1476  	r1, _, e1 := Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  1477  	if r1 == socket_error {
  1478  		if e1 != 0 {
  1479  			err = errnoErr(e1)
  1480  		} else {
  1481  			err = EINVAL
  1482  		}
  1483  	}
  1484  	return
  1485  }
  1486  
  1487  func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  1488  	r1, _, e1 := Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  1489  	if r1 == socket_error {
  1490  		if e1 != 0 {
  1491  			err = errnoErr(e1)
  1492  		} else {
  1493  			err = EINVAL
  1494  		}
  1495  	}
  1496  	return
  1497  }
  1498  
  1499  func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  1500  	r1, _, e1 := Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  1501  	if r1 == socket_error {
  1502  		if e1 != 0 {
  1503  			err = errnoErr(e1)
  1504  		} else {
  1505  			err = EINVAL
  1506  		}
  1507  	}
  1508  	return
  1509  }
  1510  
  1511  func listen(s Handle, backlog int32) (err error) {
  1512  	r1, _, e1 := Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
  1513  	if r1 == socket_error {
  1514  		if e1 != 0 {
  1515  			err = errnoErr(e1)
  1516  		} else {
  1517  			err = EINVAL
  1518  		}
  1519  	}
  1520  	return
  1521  }
  1522  
  1523  func shutdown(s Handle, how int32) (err error) {
  1524  	r1, _, e1 := Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
  1525  	if r1 == socket_error {
  1526  		if e1 != 0 {
  1527  			err = errnoErr(e1)
  1528  		} else {
  1529  			err = EINVAL
  1530  		}
  1531  	}
  1532  	return
  1533  }
  1534  
  1535  func Closesocket(s Handle) (err error) {
  1536  	r1, _, e1 := Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
  1537  	if r1 == socket_error {
  1538  		if e1 != 0 {
  1539  			err = errnoErr(e1)
  1540  		} else {
  1541  			err = EINVAL
  1542  		}
  1543  	}
  1544  	return
  1545  }
  1546  
  1547  func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
  1548  	r1, _, e1 := Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0)
  1549  	if r1 == 0 {
  1550  		if e1 != 0 {
  1551  			err = errnoErr(e1)
  1552  		} else {
  1553  			err = EINVAL
  1554  		}
  1555  	}
  1556  	return
  1557  }
  1558  
  1559  func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
  1560  	Syscall9(procGetAcceptExSockaddrs.Addr(), 8, uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen)), 0)
  1561  	return
  1562  }
  1563  
  1564  func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
  1565  	r1, _, e1 := Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
  1566  	if r1 == socket_error {
  1567  		if e1 != 0 {
  1568  			err = errnoErr(e1)
  1569  		} else {
  1570  			err = EINVAL
  1571  		}
  1572  	}
  1573  	return
  1574  }
  1575  
  1576  func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
  1577  	r1, _, e1 := Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
  1578  	if r1 == socket_error {
  1579  		if e1 != 0 {
  1580  			err = errnoErr(e1)
  1581  		} else {
  1582  			err = EINVAL
  1583  		}
  1584  	}
  1585  	return
  1586  }
  1587  
  1588  func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
  1589  	r1, _, e1 := Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
  1590  	if r1 == socket_error {
  1591  		if e1 != 0 {
  1592  			err = errnoErr(e1)
  1593  		} else {
  1594  			err = EINVAL
  1595  		}
  1596  	}
  1597  	return
  1598  }
  1599  
  1600  func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
  1601  	r1, _, e1 := Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
  1602  	if r1 == socket_error {
  1603  		if e1 != 0 {
  1604  			err = errnoErr(e1)
  1605  		} else {
  1606  			err = EINVAL
  1607  		}
  1608  	}
  1609  	return
  1610  }
  1611  
  1612  func GetHostByName(name string) (h *Hostent, err error) {
  1613  	var _p0 *byte
  1614  	_p0, err = BytePtrFromString(name)
  1615  	if err != nil {
  1616  		return
  1617  	}
  1618  	return _GetHostByName(_p0)
  1619  }
  1620  
  1621  func _GetHostByName(name *byte) (h *Hostent, err error) {
  1622  	r0, _, e1 := Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1623  	h = (*Hostent)(unsafe.Pointer(r0))
  1624  	if h == nil {
  1625  		if e1 != 0 {
  1626  			err = errnoErr(e1)
  1627  		} else {
  1628  			err = EINVAL
  1629  		}
  1630  	}
  1631  	return
  1632  }
  1633  
  1634  func GetServByName(name string, proto string) (s *Servent, err error) {
  1635  	var _p0 *byte
  1636  	_p0, err = BytePtrFromString(name)
  1637  	if err != nil {
  1638  		return
  1639  	}
  1640  	var _p1 *byte
  1641  	_p1, err = BytePtrFromString(proto)
  1642  	if err != nil {
  1643  		return
  1644  	}
  1645  	return _GetServByName(_p0, _p1)
  1646  }
  1647  
  1648  func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
  1649  	r0, _, e1 := Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
  1650  	s = (*Servent)(unsafe.Pointer(r0))
  1651  	if s == nil {
  1652  		if e1 != 0 {
  1653  			err = errnoErr(e1)
  1654  		} else {
  1655  			err = EINVAL
  1656  		}
  1657  	}
  1658  	return
  1659  }
  1660  
  1661  func Ntohs(netshort uint16) (u uint16) {
  1662  	r0, _, _ := Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
  1663  	u = uint16(r0)
  1664  	return
  1665  }
  1666  
  1667  func GetProtoByName(name string) (p *Protoent, err error) {
  1668  	var _p0 *byte
  1669  	_p0, err = BytePtrFromString(name)
  1670  	if err != nil {
  1671  		return
  1672  	}
  1673  	return _GetProtoByName(_p0)
  1674  }
  1675  
  1676  func _GetProtoByName(name *byte) (p *Protoent, err error) {
  1677  	r0, _, e1 := Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1678  	p = (*Protoent)(unsafe.Pointer(r0))
  1679  	if p == nil {
  1680  		if e1 != 0 {
  1681  			err = errnoErr(e1)
  1682  		} else {
  1683  			err = EINVAL
  1684  		}
  1685  	}
  1686  	return
  1687  }
  1688  
  1689  func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  1690  	var _p0 *uint16
  1691  	_p0, status = UTF16PtrFromString(name)
  1692  	if status != nil {
  1693  		return
  1694  	}
  1695  	return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
  1696  }
  1697  
  1698  func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  1699  	r0, _, _ := Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
  1700  	if r0 != 0 {
  1701  		status = Errno(r0)
  1702  	}
  1703  	return
  1704  }
  1705  
  1706  func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
  1707  	Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
  1708  	return
  1709  }
  1710  
  1711  func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
  1712  	r0, _, _ := Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
  1713  	same = r0 != 0
  1714  	return
  1715  }
  1716  
  1717  func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
  1718  	r0, _, _ := Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
  1719  	if r0 != 0 {
  1720  		sockerr = Errno(r0)
  1721  	}
  1722  	return
  1723  }
  1724  
  1725  func FreeAddrInfoW(addrinfo *AddrinfoW) {
  1726  	Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
  1727  	return
  1728  }
  1729  
  1730  func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
  1731  	r0, _, _ := Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
  1732  	if r0 != 0 {
  1733  		errcode = Errno(r0)
  1734  	}
  1735  	return
  1736  }
  1737  
  1738  func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
  1739  	r0, _, _ := Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
  1740  	if r0 != 0 {
  1741  		errcode = Errno(r0)
  1742  	}
  1743  	return
  1744  }
  1745  
  1746  func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
  1747  	r1, _, e1 := Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
  1748  	if r1 == 0 {
  1749  		if e1 != 0 {
  1750  			err = errnoErr(e1)
  1751  		} else {
  1752  			err = EINVAL
  1753  		}
  1754  	}
  1755  	return
  1756  }
  1757  
  1758  func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
  1759  	r0, _, e1 := Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
  1760  	n = int32(r0)
  1761  	if n == -1 {
  1762  		if e1 != 0 {
  1763  			err = errnoErr(e1)
  1764  		} else {
  1765  			err = EINVAL
  1766  		}
  1767  	}
  1768  	return
  1769  }
  1770  
  1771  func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
  1772  	r1, _, e1 := Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
  1773  	if r1&0xff == 0 {
  1774  		if e1 != 0 {
  1775  			err = errnoErr(e1)
  1776  		} else {
  1777  			err = EINVAL
  1778  		}
  1779  	}
  1780  	return
  1781  }
  1782  
  1783  func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
  1784  	r1, _, e1 := Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
  1785  	if r1&0xff == 0 {
  1786  		if e1 != 0 {
  1787  			err = errnoErr(e1)
  1788  		} else {
  1789  			err = EINVAL
  1790  		}
  1791  	}
  1792  	return
  1793  }
  1794  
  1795  func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
  1796  	r0, _, _ := Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
  1797  	if r0 != 0 {
  1798  		neterr = Errno(r0)
  1799  	}
  1800  	return
  1801  }
  1802  
  1803  func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
  1804  	r0, _, _ := Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
  1805  	if r0 != 0 {
  1806  		neterr = Errno(r0)
  1807  	}
  1808  	return
  1809  }
  1810  
  1811  func NetApiBufferFree(buf *byte) (neterr error) {
  1812  	r0, _, _ := Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
  1813  	if r0 != 0 {
  1814  		neterr = Errno(r0)
  1815  	}
  1816  	return
  1817  }
  1818  
  1819  func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  1820  	r1, _, e1 := Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
  1821  	if r1 == 0 {
  1822  		if e1 != 0 {
  1823  			err = errnoErr(e1)
  1824  		} else {
  1825  			err = EINVAL
  1826  		}
  1827  	}
  1828  	return
  1829  }
  1830  
  1831  func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  1832  	r1, _, e1 := Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
  1833  	if r1 == 0 {
  1834  		if e1 != 0 {
  1835  			err = errnoErr(e1)
  1836  		} else {
  1837  			err = EINVAL
  1838  		}
  1839  	}
  1840  	return
  1841  }
  1842  
  1843  func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
  1844  	r1, _, e1 := Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
  1845  	if r1 == 0 {
  1846  		if e1 != 0 {
  1847  			err = errnoErr(e1)
  1848  		} else {
  1849  			err = EINVAL
  1850  		}
  1851  	}
  1852  	return
  1853  }
  1854  
  1855  func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
  1856  	r1, _, e1 := Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
  1857  	if r1 == 0 {
  1858  		if e1 != 0 {
  1859  			err = errnoErr(e1)
  1860  		} else {
  1861  			err = EINVAL
  1862  		}
  1863  	}
  1864  	return
  1865  }
  1866  
  1867  func GetLengthSid(sid *SID) (len uint32) {
  1868  	r0, _, _ := Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
  1869  	len = uint32(r0)
  1870  	return
  1871  }
  1872  
  1873  func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
  1874  	r1, _, e1 := Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
  1875  	if r1 == 0 {
  1876  		if e1 != 0 {
  1877  			err = errnoErr(e1)
  1878  		} else {
  1879  			err = EINVAL
  1880  		}
  1881  	}
  1882  	return
  1883  }
  1884  
  1885  func OpenProcessToken(h Handle, access uint32, token *Token) (err error) {
  1886  	r1, _, e1 := Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token)))
  1887  	if r1 == 0 {
  1888  		if e1 != 0 {
  1889  			err = errnoErr(e1)
  1890  		} else {
  1891  			err = EINVAL
  1892  		}
  1893  	}
  1894  	return
  1895  }
  1896  
  1897  func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
  1898  	r1, _, e1 := Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
  1899  	if r1 == 0 {
  1900  		if e1 != 0 {
  1901  			err = errnoErr(e1)
  1902  		} else {
  1903  			err = EINVAL
  1904  		}
  1905  	}
  1906  	return
  1907  }
  1908  
  1909  func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
  1910  	r1, _, e1 := Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
  1911  	if r1 == 0 {
  1912  		if e1 != 0 {
  1913  			err = errnoErr(e1)
  1914  		} else {
  1915  			err = EINVAL
  1916  		}
  1917  	}
  1918  	return
  1919  }
  1920  
  1921  func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) {
  1922  	r0, _, e1 := Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0)
  1923  	len = uint32(r0)
  1924  	if len == 0 {
  1925  		if e1 != 0 {
  1926  			err = errnoErr(e1)
  1927  		} else {
  1928  			err = EINVAL
  1929  		}
  1930  	}
  1931  	return
  1932  }
  1933  

View as plain text