2014-08-15 00:37:19 -06:00
|
|
|
// go build mksyscall_windows.go && ./mksyscall_windows syscall_windows.go security_windows.go
|
2010-03-09 16:09:09 -07:00
|
|
|
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
|
|
|
|
|
|
package syscall
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
2010-03-17 00:10:07 -06:00
|
|
|
var (
|
2011-07-31 04:07:04 -06:00
|
|
|
modkernel32 = NewLazyDLL("kernel32.dll")
|
|
|
|
modadvapi32 = NewLazyDLL("advapi32.dll")
|
|
|
|
modshell32 = NewLazyDLL("shell32.dll")
|
2011-09-08 00:32:40 -06:00
|
|
|
modmswsock = NewLazyDLL("mswsock.dll")
|
2011-10-13 20:58:19 -06:00
|
|
|
modcrypt32 = NewLazyDLL("crypt32.dll")
|
2011-07-31 04:07:04 -06:00
|
|
|
modws2_32 = NewLazyDLL("ws2_32.dll")
|
|
|
|
moddnsapi = NewLazyDLL("dnsapi.dll")
|
|
|
|
modiphlpapi = NewLazyDLL("iphlpapi.dll")
|
2012-01-30 04:59:10 -07:00
|
|
|
modsecur32 = NewLazyDLL("secur32.dll")
|
|
|
|
modnetapi32 = NewLazyDLL("netapi32.dll")
|
|
|
|
moduserenv = NewLazyDLL("userenv.dll")
|
2011-07-31 04:07:04 -06:00
|
|
|
|
2013-08-08 07:36:43 -06:00
|
|
|
procGetLastError = modkernel32.NewProc("GetLastError")
|
|
|
|
procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
|
|
|
|
procFreeLibrary = modkernel32.NewProc("FreeLibrary")
|
|
|
|
procGetProcAddress = modkernel32.NewProc("GetProcAddress")
|
|
|
|
procGetVersion = modkernel32.NewProc("GetVersion")
|
|
|
|
procFormatMessageW = modkernel32.NewProc("FormatMessageW")
|
|
|
|
procExitProcess = modkernel32.NewProc("ExitProcess")
|
|
|
|
procCreateFileW = modkernel32.NewProc("CreateFileW")
|
|
|
|
procReadFile = modkernel32.NewProc("ReadFile")
|
|
|
|
procWriteFile = modkernel32.NewProc("WriteFile")
|
|
|
|
procSetFilePointer = modkernel32.NewProc("SetFilePointer")
|
|
|
|
procCloseHandle = modkernel32.NewProc("CloseHandle")
|
|
|
|
procGetStdHandle = modkernel32.NewProc("GetStdHandle")
|
|
|
|
procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
|
|
|
|
procFindNextFileW = modkernel32.NewProc("FindNextFileW")
|
|
|
|
procFindClose = modkernel32.NewProc("FindClose")
|
|
|
|
procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
|
|
|
|
procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
|
|
|
|
procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
|
|
|
|
procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
|
|
|
|
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
|
|
|
|
procDeleteFileW = modkernel32.NewProc("DeleteFileW")
|
|
|
|
procMoveFileW = modkernel32.NewProc("MoveFileW")
|
|
|
|
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
|
|
|
procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
|
|
|
|
procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
|
|
|
|
procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
|
|
|
|
procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
|
|
|
|
procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
|
|
|
|
procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
|
|
|
|
procCancelIo = modkernel32.NewProc("CancelIo")
|
|
|
|
procCancelIoEx = modkernel32.NewProc("CancelIoEx")
|
|
|
|
procCreateProcessW = modkernel32.NewProc("CreateProcessW")
|
|
|
|
procOpenProcess = modkernel32.NewProc("OpenProcess")
|
|
|
|
procTerminateProcess = modkernel32.NewProc("TerminateProcess")
|
|
|
|
procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
|
|
|
|
procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
|
|
|
|
procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
|
|
|
|
procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
|
|
|
|
procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
|
|
|
|
procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
|
|
|
|
procGetTempPathW = modkernel32.NewProc("GetTempPathW")
|
|
|
|
procCreatePipe = modkernel32.NewProc("CreatePipe")
|
|
|
|
procGetFileType = modkernel32.NewProc("GetFileType")
|
|
|
|
procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
|
|
|
|
procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
|
|
|
|
procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
|
|
|
|
procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
|
|
|
|
procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
|
|
|
|
procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
|
|
|
|
procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
|
|
|
|
procSetFileTime = modkernel32.NewProc("SetFileTime")
|
|
|
|
procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
|
|
|
|
procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
|
|
|
|
procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
|
|
|
|
procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
|
|
|
|
procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
|
|
|
|
procLocalFree = modkernel32.NewProc("LocalFree")
|
|
|
|
procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
|
|
|
|
procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
|
|
|
|
procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
|
|
|
|
procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
|
|
|
|
procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
|
|
|
|
procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
|
|
|
|
procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
|
|
|
|
procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
|
|
|
|
procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
|
|
|
|
procVirtualLock = modkernel32.NewProc("VirtualLock")
|
|
|
|
procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
|
|
|
|
procTransmitFile = modmswsock.NewProc("TransmitFile")
|
|
|
|
procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
|
|
|
|
procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
|
|
|
|
procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
|
|
|
|
procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
|
|
|
|
procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
|
|
|
|
procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
|
|
|
|
procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
|
|
|
|
procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
|
|
|
|
procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
|
|
|
|
procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
|
|
|
|
procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
|
|
|
|
procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
|
|
|
|
procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
|
|
|
|
procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
|
|
|
|
procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
|
|
|
|
procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
|
|
|
|
procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
|
|
|
|
procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
|
|
|
|
procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
|
|
|
|
procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
|
2014-06-13 23:51:00 -06:00
|
|
|
procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
|
|
|
|
procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
|
|
|
|
procProcess32NextW = modkernel32.NewProc("Process32NextW")
|
2014-07-17 01:02:46 -06:00
|
|
|
procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
|
|
|
|
procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
|
|
|
|
procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
|
2013-08-08 07:36:43 -06:00
|
|
|
procWSAStartup = modws2_32.NewProc("WSAStartup")
|
|
|
|
procWSACleanup = modws2_32.NewProc("WSACleanup")
|
|
|
|
procWSAIoctl = modws2_32.NewProc("WSAIoctl")
|
|
|
|
procsocket = modws2_32.NewProc("socket")
|
|
|
|
procsetsockopt = modws2_32.NewProc("setsockopt")
|
|
|
|
procgetsockopt = modws2_32.NewProc("getsockopt")
|
|
|
|
procbind = modws2_32.NewProc("bind")
|
|
|
|
procconnect = modws2_32.NewProc("connect")
|
|
|
|
procgetsockname = modws2_32.NewProc("getsockname")
|
|
|
|
procgetpeername = modws2_32.NewProc("getpeername")
|
|
|
|
proclisten = modws2_32.NewProc("listen")
|
|
|
|
procshutdown = modws2_32.NewProc("shutdown")
|
|
|
|
procclosesocket = modws2_32.NewProc("closesocket")
|
|
|
|
procAcceptEx = modmswsock.NewProc("AcceptEx")
|
|
|
|
procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
|
|
|
|
procWSARecv = modws2_32.NewProc("WSARecv")
|
|
|
|
procWSASend = modws2_32.NewProc("WSASend")
|
|
|
|
procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
|
|
|
|
procWSASendTo = modws2_32.NewProc("WSASendTo")
|
|
|
|
procgethostbyname = modws2_32.NewProc("gethostbyname")
|
|
|
|
procgetservbyname = modws2_32.NewProc("getservbyname")
|
|
|
|
procntohs = modws2_32.NewProc("ntohs")
|
|
|
|
procgetprotobyname = modws2_32.NewProc("getprotobyname")
|
|
|
|
procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
|
|
|
|
procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
|
2014-08-15 00:37:19 -06:00
|
|
|
procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
|
2013-08-08 07:36:43 -06:00
|
|
|
procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
|
|
|
|
procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
|
|
|
|
procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
|
|
|
|
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
|
|
|
|
procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
|
|
|
|
procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
|
|
|
|
procTranslateNameW = modsecur32.NewProc("TranslateNameW")
|
|
|
|
procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
|
|
|
|
procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
|
|
|
|
procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
|
|
|
|
procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
|
|
|
|
procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
|
|
|
|
procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
|
|
|
|
procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
|
|
|
|
procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
|
|
|
|
procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
|
|
|
|
procCopySid = modadvapi32.NewProc("CopySid")
|
|
|
|
procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
|
|
|
|
procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
|
|
|
|
procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
|
2010-03-17 00:10:07 -06:00
|
|
|
)
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func GetLastError() (lasterr error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
lasterr = Errno(r0)
|
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func LoadLibrary(libname string) (handle Handle, err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *uint16
|
|
|
|
_p0, err = UTF16PtrFromString(libname)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, e1 := Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
2010-04-02 02:11:17 -06:00
|
|
|
if handle == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FreeLibrary(handle Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *byte
|
|
|
|
_p0, err = BytePtrFromString(procname)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(_p0)), 0)
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
2011-09-05 17:59:08 -06:00
|
|
|
proc = uintptr(r0)
|
2010-04-02 02:11:17 -06:00
|
|
|
if proc == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetVersion() (ver uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
|
2010-03-09 16:09:09 -07:00
|
|
|
ver = uint32(r0)
|
2010-04-02 02:11:17 -06:00
|
|
|
if ver == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
|
2010-03-17 00:10:07 -06:00
|
|
|
var _p0 *uint16
|
|
|
|
if len(buf) > 0 {
|
|
|
|
_p0 = &buf[0]
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2010-03-17 00:10:07 -06:00
|
|
|
n = uint32(r0)
|
2010-04-02 02:11:17 -06:00
|
|
|
if n == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExitProcess(exitcode uint32) {
|
2011-07-31 04:07:04 -06:00
|
|
|
Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
|
2010-04-02 02:11:17 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
2010-04-02 02:11:17 -06:00
|
|
|
var _p0 *byte
|
|
|
|
if len(buf) > 0 {
|
|
|
|
_p0 = &buf[0]
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
2010-04-02 02:11:17 -06:00
|
|
|
var _p0 *byte
|
|
|
|
if len(buf) > 0 {
|
|
|
|
_p0 = &buf[0]
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
|
2010-04-02 02:11:17 -06:00
|
|
|
newlowoffset = uint32(r0)
|
|
|
|
if newlowoffset == 0xffffffff {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CloseHandle(handle Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetStdHandle(stdhandle int) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-03-17 00:10:07 -06:00
|
|
|
}
|
2010-03-09 16:09:09 -07:00
|
|
|
return
|
|
|
|
}
|
2010-04-13 17:30:11 -06:00
|
|
|
|
2012-06-08 11:54:48 -06:00
|
|
|
func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-13 17:30:11 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-06-08 11:54:48 -06:00
|
|
|
func findNextFile1(handle Handle, data *win32finddata1) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-13 17:30:11 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FindClose(handle Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-13 17:30:11 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
|
2010-04-27 00:17:14 -06:00
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetCurrentDirectory(path *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func RemoveDirectory(path *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func DeleteFile(path *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func MoveFile(from *uint16, to *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetComputerName(buf *uint16, n *uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetEndOfFile(handle Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-04-27 00:17:14 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSystemTimeAsFileTime(time *Filetime) {
|
2011-07-31 04:07:04 -06:00
|
|
|
Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
|
2010-04-27 00:17:14 -06:00
|
|
|
return
|
|
|
|
}
|
2010-04-30 00:08:22 -06:00
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
|
2010-06-29 23:29:09 -06:00
|
|
|
rc = uint32(r0)
|
|
|
|
if rc == 0xffffffff {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 23:29:09 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
2010-06-29 21:23:39 -06:00
|
|
|
if handle == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
|
2011-10-18 14:09:58 -06:00
|
|
|
r1, _, e1 := Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-10-18 14:09:58 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-10-18 14:09:58 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-10-18 14:09:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CancelIo(s Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-01-19 12:49:25 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-01-19 12:49:25 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-01-19 12:49:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
net: fix connection resets when closed on windows
It is common to close network connection while another goroutine is
blocked reading on another goroutine. This sequence corresponds to
windows calls to WSARecv to start io, followed by GetQueuedCompletionStatus
that blocks until io completes, and, finally, closesocket called from
another thread. We were expecting that closesocket would unblock
GetQueuedCompletionStatus, and it does, but not always
(http://code.google.com/p/go/issues/detail?id=4170#c5). Also that sequence
results in connection is being reset.
This CL inserts CancelIo between GetQueuedCompletionStatus and closesocket,
and waits for both WSARecv and GetQueuedCompletionStatus to complete before
proceeding to closesocket. This seems to fix both connection resets and
issue 4170. It also makes windows code behave similar to unix version.
Unfortunately, CancelIo needs to be called on the same thread as WSARecv.
So we have to employ strategy we use for connections with deadlines to
every connection now. It means, there are 2 unavoidable thread switches
for every io. Some newer versions of windows have new CancelIoEx api that
doesn't have these drawbacks, and this CL uses this capability when available.
As time goes by, we should have less of CancelIo and more of CancelIoEx
systems. Computers with CancelIoEx are also not affected by issue 4195 anymore.
Fixes #3710
Fixes #3746
Fixes #4170
Partial fix for issue 4195
R=golang-dev, mikioh.mikioh, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/6604072
2012-10-30 17:24:37 -06:00
|
|
|
func CancelIoEx(s Handle, o *Overlapped) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
|
2010-07-25 17:43:35 -06:00
|
|
|
var _p0 uint32
|
|
|
|
if inheritHandles {
|
|
|
|
_p0 = 1
|
|
|
|
} else {
|
|
|
|
_p0 = 0
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-25 17:43:35 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
|
2011-02-03 20:41:26 -07:00
|
|
|
var _p0 uint32
|
|
|
|
if inheritHandle {
|
|
|
|
_p0 = 1
|
|
|
|
} else {
|
|
|
|
_p0 = 0
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
2011-02-03 20:41:26 -07:00
|
|
|
if handle == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-02-03 20:41:26 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-02-03 20:41:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func TerminateProcess(handle Handle, exitcode uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-06-06 03:53:30 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-06-06 03:53:30 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-06-06 03:53:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-02-03 20:41:26 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-02-03 20:41:26 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-02-03 20:41:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetStartupInfo(startupInfo *StartupInfo) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-25 17:43:35 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetCurrentProcess() (pseudoHandle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
pseudoHandle = Handle(r0)
|
2010-07-25 17:43:35 -06:00
|
|
|
if pseudoHandle == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-25 17:43:35 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-01 20:47:40 -07:00
|
|
|
func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
|
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-03-01 20:47:40 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
|
2010-07-25 17:43:35 -06:00
|
|
|
var _p0 uint32
|
|
|
|
if bInheritHandle {
|
|
|
|
_p0 = 1
|
|
|
|
} else {
|
|
|
|
_p0 = 0
|
|
|
|
}
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-25 17:43:35 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
|
2010-07-25 17:43:35 -06:00
|
|
|
event = uint32(r0)
|
|
|
|
if event == 0xffffffff {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-25 17:43:35 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
|
2010-06-30 14:52:34 -06:00
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-30 14:52:34 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 23:55:01 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 23:55:01 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 23:55:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetFileType(filehandle Handle) (n uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
|
2010-07-25 23:55:01 -06:00
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 23:55:01 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 23:55:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-12 17:37:53 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-12 17:37:53 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-07-12 17:37:53 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetEnvironmentStrings() (envs *uint16, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
|
2010-08-12 22:29:23 -06:00
|
|
|
envs = (*uint16)(unsafe.Pointer(r0))
|
|
|
|
if envs == nil {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-08-12 22:29:23 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-08-12 22:29:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FreeEnvironmentStrings(envs *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-08-12 22:29:23 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-08-12 22:29:23 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-08-12 22:29:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
|
2010-08-12 22:29:23 -06:00
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-08-12 22:29:23 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-08-12 22:29:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-08-12 22:29:23 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-08-12 22:29:23 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-08-12 22:29:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-09-22 20:36:52 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-09-22 20:36:52 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-09-22 20:36:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetFileAttributes(name *uint16) (attrs uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
|
2010-10-30 06:06:49 -06:00
|
|
|
attrs = uint32(r0)
|
|
|
|
if attrs == INVALID_FILE_ATTRIBUTES {
|
2010-12-15 18:18:18 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-12-15 18:18:18 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-12-15 18:18:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetFileAttributes(name *uint16, attrs uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-02-15 22:24:59 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-02-15 22:24:59 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-02-15 22:24:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
|
2011-09-05 17:59:08 -06:00
|
|
|
r1, _, e1 := Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-09-05 17:59:08 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-09-05 17:59:08 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-09-05 17:59:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-12-15 18:18:18 -07:00
|
|
|
func GetCommandLine() (cmd *uint16) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
|
2010-12-15 18:18:18 -07:00
|
|
|
cmd = (*uint16)(unsafe.Pointer(r0))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
|
2010-12-15 18:18:18 -07:00
|
|
|
argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
|
|
|
|
if argv == nil {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-12-15 18:18:18 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-12-15 18:18:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func LocalFree(hmem Handle) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
2010-12-15 18:18:18 -07:00
|
|
|
if handle != 0 {
|
2010-10-30 06:06:49 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-10-30 06:06:49 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-10-30 06:06:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-02-02 18:50:41 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-02-02 18:50:41 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-02-02 18:50:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FlushFileBuffers(handle Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-02-08 20:54:54 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-02-08 20:54:54 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-02-08 20:54:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
|
2011-03-23 18:20:28 -06:00
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-03-23 18:20:28 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-03-23 18:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-07 16:00:25 -07:00
|
|
|
func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
|
|
|
|
r0, _, e1 := Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
|
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-26 22:53:08 -06:00
|
|
|
func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
|
|
|
|
r0, _, e1 := Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
|
|
|
|
n = uint32(r0)
|
|
|
|
if n == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
2011-05-01 17:35:55 -06:00
|
|
|
if handle == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
|
2011-05-01 17:35:55 -06:00
|
|
|
addr = uintptr(r0)
|
|
|
|
if addr == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func UnmapViewOfFile(addr uintptr) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-05-01 17:35:55 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-05-01 17:35:55 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func VirtualLock(addr uintptr, length uintptr) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-05-01 17:35:55 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func VirtualUnlock(addr uintptr, length uintptr) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-05-01 17:35:55 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-05-01 17:35:55 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-05-01 17:35:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-06-10 21:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-06-10 21:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-06-10 21:24:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
|
2011-10-18 14:09:58 -06:00
|
|
|
var _p0 uint32
|
|
|
|
if watchSubTree {
|
|
|
|
_p0 = 1
|
|
|
|
} else {
|
|
|
|
_p0 = 0
|
|
|
|
}
|
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-10-18 14:09:58 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-10-18 14:09:58 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-10-18 14:09:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
|
2011-10-13 20:58:19 -06:00
|
|
|
r0, _, e1 := Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
|
|
|
|
store = Handle(r0)
|
|
|
|
if store == 0 {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-10-13 20:58:19 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-10-13 20:58:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:12:35 -07:00
|
|
|
func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
|
|
|
|
r0, _, e1 := Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
|
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-01 10:38:00 -07:00
|
|
|
func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
|
|
|
|
r0, _, e1 := Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
|
2011-10-13 20:58:19 -06:00
|
|
|
context = (*CertContext)(unsafe.Pointer(r0))
|
2011-12-01 10:38:00 -07:00
|
|
|
if context == nil {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
2011-10-13 20:58:19 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:12:35 -07:00
|
|
|
func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-03-07 11:12:35 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func CertCloseStore(store Handle, flags uint32) (err error) {
|
2011-10-13 20:58:19 -06:00
|
|
|
r1, _, e1 := Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2011-10-13 20:58:19 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-10-13 20:58:19 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-10-13 20:58:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:12:35 -07:00
|
|
|
func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
|
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-03-07 11:12:35 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CertFreeCertificateChain(ctx *CertChainContext) {
|
|
|
|
Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
|
|
|
|
r0, _, e1 := Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
|
|
|
|
context = (*CertContext)(unsafe.Pointer(r0))
|
|
|
|
if context == nil {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CertFreeCertificateContext(ctx *CertContext) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-03-07 11:12:35 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-03-07 11:12:35 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
|
2011-11-17 16:07:36 -07:00
|
|
|
r0, _, _ := Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
regerrno = Errno(r0)
|
|
|
|
}
|
2011-11-17 16:07:36 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func RegCloseKey(key Handle) (regerrno error) {
|
2011-11-17 16:07:36 -07:00
|
|
|
r0, _, _ := Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
regerrno = Errno(r0)
|
|
|
|
}
|
2011-11-17 16:07:36 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
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) {
|
2011-11-17 16:07:36 -07:00
|
|
|
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)))
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
regerrno = Errno(r0)
|
|
|
|
}
|
2011-11-17 16:07:36 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
|
2011-11-17 16:07:36 -07:00
|
|
|
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)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
regerrno = Errno(r0)
|
|
|
|
}
|
2011-11-17 16:07:36 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
|
2011-11-17 16:07:36 -07:00
|
|
|
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)))
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
regerrno = Errno(r0)
|
|
|
|
}
|
2011-11-17 16:07:36 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-06-08 12:28:29 -06:00
|
|
|
func getCurrentProcessId() (pid uint32) {
|
2012-05-22 21:05:05 -06:00
|
|
|
r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
|
|
|
|
pid = uint32(r0)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-09-11 20:04:45 -06:00
|
|
|
func GetConsoleMode(console Handle, mode *uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-09-11 20:04:45 -06:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-09-11 20:04:45 -06:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-02-25 20:18:48 -07:00
|
|
|
func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-06-13 23:51:00 -06:00
|
|
|
func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
|
|
|
|
r0, _, e1 := Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
|
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-17 01:02:46 -06:00
|
|
|
func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
|
|
|
|
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)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
|
|
|
|
if r1&0xff == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
|
|
|
|
if r1&0xff == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
sockerr = Errno(r0)
|
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSACleanup() (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2011-06-22 17:54:57 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-06-22 17:54:57 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-06-22 17:54:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, e1 := Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
|
2011-07-01 08:18:07 -06:00
|
|
|
handle = Handle(r0)
|
|
|
|
if handle == InvalidHandle {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-05-22 21:05:05 -06:00
|
|
|
func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2012-05-22 21:05:05 -06:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-04-05 20:18:01 -06:00
|
|
|
func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-04-05 20:18:01 -06:00
|
|
|
func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func listen(s Handle, backlog int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func shutdown(s Handle, how int32) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func Closesocket(s Handle) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r1, _, e1 := Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2011-01-11 21:55:17 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-01-11 21:55:17 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-01-11 21:55:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2010-06-29 21:23:39 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-07-25 18:24:48 -06:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-25 18:24:48 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-25 18:24:48 -06:00
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2010-07-28 22:58:28 -06:00
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-11-22 09:01:30 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-11-22 09:01:30 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-11-22 09:01:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
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)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == socket_error {
|
2010-11-22 09:01:30 -07:00
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-11-22 09:01:30 -07:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-11-22 09:01:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetHostByName(name string) (h *Hostent, err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *byte
|
|
|
|
_p0, err = BytePtrFromString(name)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, e1 := Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
2010-07-28 22:58:28 -06:00
|
|
|
h = (*Hostent)(unsafe.Pointer(r0))
|
|
|
|
if h == nil {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-28 22:58:28 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-28 22:58:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetServByName(name string, proto string) (s *Servent, err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *byte
|
|
|
|
_p0, err = BytePtrFromString(name)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var _p1 *byte
|
|
|
|
_p1, err = BytePtrFromString(proto)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, e1 := Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
|
|
|
use(unsafe.Pointer(_p1))
|
2010-07-28 22:58:28 -06:00
|
|
|
s = (*Servent)(unsafe.Pointer(r0))
|
|
|
|
if s == nil {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2010-07-28 22:58:28 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2010-07-28 22:58:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func Ntohs(netshort uint16) (u uint16) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
|
2010-08-02 20:04:41 -06:00
|
|
|
u = uint16(r0)
|
2010-07-28 22:58:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-13 20:44:52 -07:00
|
|
|
func GetProtoByName(name string) (p *Protoent, err error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *byte
|
|
|
|
_p0, err = BytePtrFromString(name)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, e1 := Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
2011-10-11 17:29:22 -06:00
|
|
|
p = (*Protoent)(unsafe.Pointer(r0))
|
|
|
|
if p == nil {
|
|
|
|
if e1 != 0 {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = error(e1)
|
2011-10-11 17:29:22 -06:00
|
|
|
} else {
|
2011-11-13 20:44:52 -07:00
|
|
|
err = EINVAL
|
2011-10-11 17:29:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
|
syscall: return EINVAL when string arguments have NUL characters
Since NUL usually terminates strings in underlying syscalls, allowing
it when converting string arguments is a security risk, especially
when dealing with filenames. For example, a program might reason that
filename like "/root/..\x00/" is a subdirectory or "/root/" and allow
access to it, while underlying syscall will treat "\x00" as an end of
that string and the actual filename will be "/root/..", which might
be unexpected. Returning EINVAL when string arguments have NUL in
them makes sure this attack vector is unusable.
R=golang-dev, r, bradfitz, fullung, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6458050
2012-08-05 15:24:32 -06:00
|
|
|
var _p0 *uint16
|
|
|
|
_p0, status = UTF16PtrFromString(name)
|
|
|
|
if status != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r0, _, _ := Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(_p0)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
|
2014-09-08 18:47:12 -06:00
|
|
|
use(unsafe.Pointer(_p0))
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
status = Errno(r0)
|
|
|
|
}
|
2010-07-28 22:58:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
|
2011-07-31 04:07:04 -06:00
|
|
|
Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
|
2010-07-28 22:58:28 -06:00
|
|
|
return
|
|
|
|
}
|
2011-06-22 17:54:57 -06:00
|
|
|
|
2014-08-15 00:37:19 -06:00
|
|
|
func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
|
|
|
|
r0, _, _ := Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
|
|
|
|
same = r0 != 0
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-11-06 22:58:20 -07:00
|
|
|
func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
|
|
|
|
r0, _, _ := Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
|
|
|
|
if r0 != 0 {
|
|
|
|
sockerr = Errno(r0)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func FreeAddrInfoW(addrinfo *AddrinfoW) {
|
|
|
|
Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
errcode = Errno(r0)
|
|
|
|
}
|
2011-06-22 17:54:57 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:07:21 -07:00
|
|
|
func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
|
2011-07-31 04:07:04 -06:00
|
|
|
r0, _, _ := Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
|
2011-12-07 18:07:21 -07:00
|
|
|
if r0 != 0 {
|
|
|
|
errcode = Errno(r0)
|
|
|
|
}
|
2011-06-22 17:54:57 -06:00
|
|
|
return
|
|
|
|
}
|
2012-01-30 04:59:10 -07:00
|
|
|
|
2013-08-08 07:36:43 -06:00
|
|
|
func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
|
|
|
|
if r1 == 0 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
|
|
|
|
r0, _, e1 := Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
|
|
|
|
n = int32(r0)
|
|
|
|
if n == -1 {
|
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-01-30 04:59:10 -07:00
|
|
|
func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1&0xff == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1&0xff == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
|
|
|
|
r0, _, _ := Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
|
|
|
|
if r0 != 0 {
|
|
|
|
neterr = Errno(r0)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-14 21:24:54 -06:00
|
|
|
func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
|
|
|
|
r0, _, _ := Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
|
|
|
|
if r0 != 0 {
|
|
|
|
neterr = Errno(r0)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-01-30 04:59:10 -07:00
|
|
|
func NetApiBufferFree(buf *byte) (neterr error) {
|
|
|
|
r0, _, _ := Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
|
|
|
|
if r0 != 0 {
|
|
|
|
neterr = Errno(r0)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-09-08 18:47:12 -06:00
|
|
|
func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use_ *uint32) (err error) {
|
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-09-08 18:47:12 -06:00
|
|
|
func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use_ *uint32) (err error) {
|
|
|
|
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)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetLengthSid(sid *SID) (len uint32) {
|
|
|
|
r0, _, _ := Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
|
|
|
|
len = uint32(r0)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenProcessToken(h Handle, access uint32, token *Token) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
|
|
|
|
r1, _, e1 := Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
|
2012-09-25 01:06:39 -06:00
|
|
|
if r1 == 0 {
|
2012-01-30 04:59:10 -07:00
|
|
|
if e1 != 0 {
|
|
|
|
err = error(e1)
|
|
|
|
} else {
|
|
|
|
err = EINVAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|