diff options
author | 2021-12-12 15:47:51 +0100 | |
---|---|---|
committer | 2021-12-12 15:47:51 +0100 | |
commit | 67ac8db190eb82a7758746fb021fa3014f4241b7 (patch) | |
tree | 4a4124ad8f0ee9ec8858b109dd0bcc2e567fc144 /vendor/modernc.org/libc/libc_windows.go | |
parent | upstep dependencies (#339) (diff) | |
download | gotosocial-67ac8db190eb82a7758746fb021fa3014f4241b7.tar.xz |
Upstep Go dependencies (#340)
* Upstep Go dependencies
* tiny linter fix
* Tidy
Diffstat (limited to 'vendor/modernc.org/libc/libc_windows.go')
-rw-r--r-- | vendor/modernc.org/libc/libc_windows.go | 546 |
1 files changed, 501 insertions, 45 deletions
diff --git a/vendor/modernc.org/libc/libc_windows.go b/vendor/modernc.org/libc/libc_windows.go index d2195b92f..aee9712b9 100644 --- a/vendor/modernc.org/libc/libc_windows.go +++ b/vendor/modernc.org/libc/libc_windows.go @@ -10,6 +10,7 @@ import ( "math" "os" "os/exec" + "os/user" "path/filepath" "strings" "sync" @@ -31,14 +32,19 @@ import ( ) // Keep these outside of the var block otherwise go generate will miss them. - var X__imp__environ = EnvironP() +var X__imp__wenviron = uintptr(unsafe.Pointer(&wenviron)) var X_imp___environ = EnvironP() var X_iob [stdio.X_IOB_ENTRIES]stdio.FILE var Xtimezone long // extern long timezone; -var iobMap = map[uintptr]int32{} // &_iob[fd] -> fd +var ( + iobMap = map[uintptr]int32{} // &_iob[fd] -> fd + wenvValid bool + wenviron uintptr // &winEnviron[0] + winEnviron = []uintptr{0} +) func init() { for i := range X_iob { @@ -70,6 +76,7 @@ var ( procCreateFileA = modkernel32.NewProc("CreateFileA") procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW") procCreateFileW = modkernel32.NewProc("CreateFileW") + procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW") procCreatePipe = modkernel32.NewProc("CreatePipe") procCreateProcessA = modkernel32.NewProc("CreateProcessA") procCreateProcessW = modkernel32.NewProc("CreateProcessW") @@ -85,24 +92,29 @@ var ( procFormatMessageW = modkernel32.NewProc("FormatMessageW") procGetACP = modkernel32.NewProc("GetACP") procGetCommState = modkernel32.NewProc("GetCommState") + procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") procGetConsoleCP = modkernel32.NewProc("GetConsoleCP") procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo") procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess") procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId") + procGetCurrentThread = modkernel32.NewProc("GetCurrentThread") procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId") procGetEnvironmentVariableA = modkernel32.NewProc("GetEnvironmentVariableA") procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW") procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess") procGetExitCodeThread = modkernel32.NewProc("GetExitCodeThread") + procGetFileAttributesA = modkernel32.NewProc("GetFileAttributesA") procGetFileAttributesExA = modkernel32.NewProc("GetFileAttributesExA") procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW") procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle") procGetFileSize = modkernel32.NewProc("GetFileSize") procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW") procGetLastError = modkernel32.NewProc("GetLastError") + procGetLogicalDriveStringsA = modkernel32.NewProc("GetLogicalDriveStringsA") procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW") procGetModuleHandleA = modkernel32.NewProc("GetModuleHandleA") procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW") + procGetPrivateProfileStringA = modkernel32.NewProc("GetPrivateProfileStringA") procGetProcAddress = modkernel32.NewProc("GetProcAddress") procGetProcessHeap = modkernel32.NewProc("GetProcessHeap") procGetSystemInfo = modkernel32.NewProc("GetSystemInfo") @@ -112,13 +124,17 @@ var ( procGetTickCount = modkernel32.NewProc("GetTickCount") procGetVersionExA = modkernel32.NewProc("GetVersionExA") procGetVersionExW = modkernel32.NewProc("GetVersionExW") + procGetVolumeInformationA = modkernel32.NewProc("GetVolumeInformationA") + procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW") procHeapAlloc = modkernel32.NewProc("HeapAlloc") + procHeapFree = modkernel32.NewProc("HeapFree") procInitializeCriticalSection = modkernel32.NewProc("InitializeCriticalSection") procLeaveCriticalSection = modkernel32.NewProc("LeaveCriticalSection") procLockFile = modkernel32.NewProc("LockFile") procLockFileEx = modkernel32.NewProc("LockFileEx") procLstrlenW = modkernel32.NewProc("lstrlenW") procMapViewOfFile = modkernel32.NewProc("MapViewOfFile") + procMoveFileW = modkernel32.NewProc("MoveFileW") procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar") procOpenEventA = modkernel32.NewProc("OpenEventA") procPeekConsoleInputW = modkernel32.NewProc("PeekConsoleInputW") @@ -136,6 +152,7 @@ var ( procSetFilePointer = modkernel32.NewProc("SetFilePointer") procSleepEx = modkernel32.NewProc("SleepEx") procSystemTimeToFileTime = modkernel32.NewProc("SystemTimeToFileTime") + procTerminateThread = modkernel32.NewProc("TerminateThread") procUnlockFile = modkernel32.NewProc("UnlockFile") procUnlockFileEx = modkernel32.NewProc("UnlockFileEx") procWaitForSingleObjectEx = modkernel32.NewProc("WaitForSingleObjectEx") @@ -150,7 +167,19 @@ var ( modadvapi = syscall.NewLazyDLL("advapi32.dll") //-- - procGetFileSecurityW = modadvapi.NewProc("GetFileSecurityW") + procAccessCheck = modadvapi.NewProc("AccessCheck") + procGetAclInformation = modadvapi.NewProc("GetAclInformation") + procGetFileSecurityA = modadvapi.NewProc("GetFileSecurityA") + procGetFileSecurityW = modadvapi.NewProc("GetFileSecurityW") + procGetSecurityDescriptorDacl = modadvapi.NewProc("GetSecurityDescriptorDacl") + procGetSecurityDescriptorOwner = modadvapi.NewProc("GetSecurityDescriptorOwner") + procGetSidIdentifierAuthority = modadvapi.NewProc("GetSidIdentifierAuthority") + procGetSidLengthRequired = modadvapi.NewProc("GetSidLengthRequired") + procGetSidSubAuthority = modadvapi.NewProc("GetSidSubAuthority") + procImpersonateSelf = modadvapi.NewProc("ImpersonateSelf") + procInitializeSid = modadvapi.NewProc("InitializeSid") + procOpenThreadToken = modadvapi.NewProc("OpenThreadToken") + procRevertToSelf = modadvapi.NewProc("RevertToSelf") //-- modws2_32 = syscall.NewLazyDLL("ws2_32.dll") @@ -160,10 +189,20 @@ var ( moduser32 = syscall.NewLazyDLL("user32.dll") //-- - procRegisterClassW = moduser32.NewProc("RegisterClassW") - procUnregisterClassW = moduser32.NewProc("UnregisterClassW") - procWaitForInputIdle = moduser32.NewProc("WaitForInputIdle") + procCreateWindowExW = moduser32.NewProc("CreateWindowExW") + procMsgWaitForMultipleObjectsEx = moduser32.NewProc("MsgWaitForMultipleObjectsEx") + procPeekMessageW = moduser32.NewProc("PeekMessageW") + procRegisterClassW = moduser32.NewProc("RegisterClassW") + procUnregisterClassW = moduser32.NewProc("UnregisterClassW") + procWaitForInputIdle = moduser32.NewProc("WaitForInputIdle") //-- + + netapi = syscall.NewLazyDLL("netapi32.dll") + procNetGetDCName = netapi.NewProc("NetGetDCName") + procNetUserGetInfo = netapi.NewProc("NetUserGetInfo") + + userenvapi = syscall.NewLazyDLL("userenv.dll") + procGetProfilesDirectoryW = userenvapi.NewProc("GetProfilesDirectoryW") ) var ( @@ -1865,7 +1904,11 @@ func X_stricmp(t *TLS, string1, string2 uintptr) int32 { // _Frees_ptr_opt_ LPVOID lpMem // ); func XHeapFree(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procHeapFree.Addr(), 3, hHeap, uintptr(dwFlags), lpMem) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // HANDLE GetProcessHeap(); @@ -2472,7 +2515,11 @@ func XGetCommModemStatus(t *TLS, _ ...interface{}) int32 { // LPCWSTR lpNewFileName // ); func XMoveFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procMoveFileW.Addr(), 2, lpExistingFileName, lpNewFileName, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // DWORD GetFullPathNameW( @@ -2648,7 +2695,11 @@ func XFindNextFileW(t *TLS, hFindFile, lpFindFileData uintptr) int32 { // LPSTR lpBuffer // ); func XGetLogicalDriveStringsA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetLogicalDriveStringsA.Addr(), 2, uintptr(nBufferLength), lpBuffer, 0) + if err != 0 { + t.setErrno(err) + } + return uint32(r0) } // BOOL GetVolumeInformationA( @@ -2662,7 +2713,21 @@ func XGetLogicalDriveStringsA(t *TLS, nBufferLength uint32, lpBuffer uintptr) ui // DWORD nFileSystemNameSize // ); func XGetVolumeInformationA(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall9(procGetVolumeInformationA.Addr(), 8, + lpRootPathName, + lpVolumeNameBuffer, + uintptr(nVolumeNameSize), + lpVolumeSerialNumber, + lpMaximumComponentLength, + lpFileSystemFlags, + lpFileSystemNameBuffer, + uintptr(nFileSystemNameSize), + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL CreateHardLinkW( @@ -2671,7 +2736,11 @@ func XGetVolumeInformationA(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, // LPSECURITY_ATTRIBUTES lpSecurityAttributes // ); func XCreateHardLinkW(t *TLS, lpFileName, lpExistingFileName, lpSecurityAttributes uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procCreateHardLinkW.Addr(), 1, lpFileName, lpExistingFileName, lpSecurityAttributes) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL DeviceIoControl( @@ -2699,7 +2768,25 @@ func XDeviceIoControl(t *TLS, hDevice uintptr, dwIoControlCode uint32, lpInBuffe // size_t count // ); func Xwcsncmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 { - panic(todo("")) + var s1 = goWideString(string1) + var l1 = len(s1) + var s2 = goWideString(string2) + var l2 = len(s2) + + // shorter is lesser + if l1 < l2 { + return -1 + } + if l2 > l1 { + return 1 + } + + // compare at most count + var cmpLen = count + if types.Size_t(l1) < cmpLen { + cmpLen = types.Size_t(l1) + } + return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen])) } // int MultiByteToWideChar( @@ -2906,7 +2993,11 @@ func XGetDiskFreeSpaceW(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerS // LPCSTR lpFileName // ); func XGetFileAttributesA(t *TLS, lpFileName uintptr) uint32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetFileAttributesA.Addr(), 1, lpFileName, 0, 0) + if err != 0 { + t.setErrno(err) + } + return uint32(r0) } // BOOL GetFileAttributesExW( @@ -3638,7 +3729,18 @@ func XWaitForSingleObjectEx(t *TLS, hHandle uintptr, dwMilliseconds uint32, bAle // DWORD dwFlags // ); func XMsgWaitForMultipleObjectsEx(t *TLS, nCount uint32, pHandles uintptr, dwMilliseconds, dwWakeMask, dwFlags uint32) uint32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procMsgWaitForMultipleObjectsEx.Addr(), 5, + uintptr(nCount), + pHandles, + uintptr(dwMilliseconds), + uintptr(dwWakeMask), + uintptr(dwFlags), + 0, + ) + if err != 0 { + t.setErrno(err) + } + return uint32(r0) } func XMessageBoxW(t *TLS, _ ...interface{}) int32 { @@ -3664,7 +3766,11 @@ func XGetModuleFileNameW(t *TLS, hModule, lpFileName uintptr, nSize uint32) uint // LPBYTE *Buffer // ); func XNetGetDCName(t *TLS, ServerName, DomainName, Buffer uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procNetGetDCName.Addr(), 3, ServerName, DomainName, Buffer) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // NET_API_STATUS NET_API_FUNCTION NetUserGetInfo( @@ -3674,15 +3780,34 @@ func XNetGetDCName(t *TLS, ServerName, DomainName, Buffer uintptr) int32 { // LPBYTE *bufptr // ); func XNetUserGetInfo(t *TLS, servername, username uintptr, level uint32, bufptr uintptr) uint32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, + servername, + username, + uintptr(level), + bufptr, + 0, + 0, + ) + if err != 0 { + t.setErrno(err) + } + return uint32(r0) } func XlstrlenW(t *TLS, _ ...interface{}) int32 { panic(todo("")) } -func XGetProfilesDirectoryW(t *TLS, _ ...interface{}) int32 { - panic(todo("")) +// USERENVAPI BOOL GetProfilesDirectoryW( +// [out] LPWSTR lpProfileDir, +// [in, out] LPDWORD lpcchSize +// ); +func XGetProfilesDirectoryW(t *TLS, lpProfileDir, lpcchSize uintptr) int32 { + r0, _, err := syscall.Syscall(procGetProfilesDirectoryW.Addr(), 2, lpProfileDir, lpcchSize, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } func XNetApiBufferFree(t *TLS, _ ...interface{}) int32 { @@ -3698,7 +3823,18 @@ func XNetApiBufferFree(t *TLS, _ ...interface{}) int32 { // LPCSTR lpFileName // ); func XGetPrivateProfileStringA(t *TLS, lpAppName, lpKeyName, lpDefault, lpReturnedString uintptr, nSize uint32, lpFileName uintptr) uint32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procGetPrivateProfileStringA.Addr(), 4, + lpAppName, + lpKeyName, + lpDefault, + lpReturnedString, + uintptr(nSize), + lpFileName, + ) + if err != 0 { + t.setErrno(0x02) + } + return uint32(r0) } func XGetWindowsDirectoryA(t *TLS, _ ...interface{}) int32 { @@ -3726,21 +3862,34 @@ func XGetFileSecurityW(t *TLS, lpFileName uintptr, RequestedInformation uint32, // LPBOOL lpbOwnerDefaulted // ); func XGetSecurityDescriptorOwner(t *TLS, pSecurityDescriptor, pOwner, lpbOwnerDefaulted uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetSecurityDescriptorOwner.Addr(), 3, pSecurityDescriptor, pOwner, lpbOwnerDefaulted) + if err != 0 { + t.setErrno(err) + } + return int32(r0) + } // PSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority( // PSID pSid // ); func XGetSidIdentifierAuthority(t *TLS, pSid uintptr) uintptr { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetSidIdentifierAuthority.Addr(), 1, pSid, 0, 0) + if err != 0 { + t.setErrno(err) + } + return r0 } // BOOL ImpersonateSelf( // SECURITY_IMPERSONATION_LEVEL ImpersonationLevel // ); func XImpersonateSelf(t *TLS, ImpersonationLevel int32) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(ImpersonationLevel), 0, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL OpenThreadToken( @@ -3750,17 +3899,29 @@ func XImpersonateSelf(t *TLS, ImpersonationLevel int32) int32 { // PHANDLE TokenHandle // ); func XOpenThreadToken(t *TLS, ThreadHandle uintptr, DesiredAccess uint32, OpenAsSelf int32, TokenHandle uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procOpenThreadToken.Addr(), 4, ThreadHandle, uintptr(DesiredAccess), uintptr(OpenAsSelf), TokenHandle, 0, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // HANDLE GetCurrentThread(); func XGetCurrentThread(t *TLS) uintptr { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0) + if err != 0 { + t.setErrno(err) + } + return r0 } // BOOL RevertToSelf(); func XRevertToSelf(t *TLS) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL AccessCheck( @@ -3774,7 +3935,21 @@ func XRevertToSelf(t *TLS) int32 { // LPBOOL AccessStatus // ); func XAccessCheck(t *TLS, pSecurityDescriptor, ClientToken uintptr, DesiredAccess uint32, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall9(procAccessCheck.Addr(), 8, + pSecurityDescriptor, + ClientToken, + uintptr(DesiredAccess), + GenericMapping, + PrivilegeSet, + PrivilegeSetLength, + GrantedAccess, + AccessStatus, + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // int _wcsicmp( @@ -3838,7 +4013,21 @@ func XGetFileInformationByHandle(t *TLS, hFile, lpFileInformation uintptr) int32 // DWORD nFileSystemNameSize // ); func XGetVolumeInformationW(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, + lpRootPathName, + lpVolumeNameBuffer, + uintptr(nVolumeNameSize), + lpVolumeSerialNumber, + lpMaximumComponentLength, + lpFileSystemFlags, + lpFileSystemNameBuffer, + uintptr(nFileSystemNameSize), + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // wchar_t *wcschr( @@ -3988,7 +4177,24 @@ func XGetACP(t *TLS) uint32 { // LPDWORD pcbBuffer // ); func XGetUserNameW(t *TLS, lpBuffer, pcbBuffer uintptr) int32 { - panic(todo("")) + u, err := user.Current() + if err != nil { + panic(todo("")) + return 0 + } + + wcnt := *(*uint16)(unsafe.Pointer(pcbBuffer)) + s := utf16.Encode([]rune(u.Username)) + if len(s)+1 > int(wcnt) { + panic(todo("")) + } + + *(*uint16)(unsafe.Pointer(pcbBuffer)) = uint16(len(s) + 1) + for _, v := range s { + *(*uint16)(unsafe.Pointer(lpBuffer)) = v + lpBuffer += 2 + } + return 1 } // HMODULE LoadLibraryExW( @@ -3997,11 +4203,28 @@ func XGetUserNameW(t *TLS, lpBuffer, pcbBuffer uintptr) int32 { // DWORD dwFlags // ); func XLoadLibraryExW(t *TLS, lpLibFileName, hFile uintptr, dwFlags uint32) uintptr { - panic(todo("")) + return 0 // If the function fails, the return value is NULL. } -func Xwcscpy(t *TLS, _ ...interface{}) int32 { - panic(todo("")) +// wchar_t *wcscpy( +// wchar_t *strDestination, +// const wchar_t *strSource +// ); +func Xwcscpy(t *TLS, strDestination, strSource uintptr) uintptr { + if strSource == 0 { + return 0 + } + + d := strDestination + for { + c := *(*uint16)(unsafe.Pointer(strSource)) + strSource += 2 + *(*uint16)(unsafe.Pointer(d)) = c + d += 2 + if c == 0 { + return strDestination + } + } } func XwsprintfW(t *TLS, _ ...interface{}) int32 { @@ -4062,7 +4285,24 @@ func XSetTimer(t *TLS, _ ...interface{}) int32 { // LPVOID lpParam // ); func XCreateWindowExW(t *TLS, dwExStyle uint32, lpClassName, lpWindowName uintptr, dwStyle uint32, x, y, nWidth, nHeight int32, hWndParent, hMenu, hInstance, lpParam uintptr) uintptr { - panic(todo("")) + r0, _, err := syscall.Syscall12(procCreateWindowExW.Addr(), 12, + uintptr(dwExStyle), + lpClassName, + lpWindowName, + uintptr(dwStyle), + uintptr(x), + uintptr(y), + uintptr(nWidth), + uintptr(nHeight), + hWndParent, + hMenu, + hInstance, + lpParam, + ) + if err != 0 { + t.setErrno(err) + } + return r0 } // BOOL PeekMessageW( @@ -4073,7 +4313,18 @@ func XCreateWindowExW(t *TLS, dwExStyle uint32, lpClassName, lpWindowName uintpt // UINT wRemoveMsg // ); func XPeekMessageW(t *TLS, lpMsg, hWnd uintptr, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procPeekMessageW.Addr(), 5, + lpMsg, + hWnd, + uintptr(wMsgFilterMin), + uintptr(wMsgFilterMax), + uintptr(wRemoveMsg), + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } func XGetMessageW(t *TLS, _ ...interface{}) int32 { @@ -4209,8 +4460,16 @@ func X_InterlockedExchange(t *TLS, Target uintptr, Value long) long { return old } -func XTerminateThread(t *TLS, _ ...interface{}) int32 { - panic(todo("")) +// BOOL TerminateThread( +// [in, out] HANDLE hThread, +// [in] DWORD dwExitCode +// ); +func XTerminateThread(t *TLS, hThread uintptr, dwExitCode uint32) int32 { + r0, _, err := syscall.Syscall(procTerminateThread.Addr(), 2, hThread, uintptr(dwExitCode), 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL GetComputerNameW( @@ -4345,8 +4604,12 @@ func XDdeQueryStringW(t *TLS, _ ...interface{}) int32 { panic(todo("")) } -func X_wcsicmp(t *TLS, _ ...interface{}) int32 { - panic(todo("")) +// int _wcsicmp( +// const wchar_t *string1, +// const wchar_t *string2 +// ); +func X_wcsicmp(t *TLS, string1, string2 uintptr) int32 { + return Xwcsicmp(t, string1, string2) } func XDdeCreateDataHandle(t *TLS, _ ...interface{}) uintptr { @@ -4790,6 +5053,7 @@ func goWideBytes(p uintptr, n int) []uint16 { return w } +// This version does include the zero terminator in the returned Go string. func goWideString(p uintptr) string { if p == 0 { return "" @@ -4814,6 +5078,28 @@ func goWideStringN(p uintptr, n int) string { panic(todo("")) } +// This version does not include the zero terminator in the returned Go string. +func goWideStringNZ(p uintptr) string { + if p == 0 { + return "" + } + + var w []uint16 + var raw = (*RawMem)(unsafe.Pointer(p)) + var i = 0 + for { + wc := *(*uint16)(unsafe.Pointer(&raw[i])) + if wc == 0 { + break + } + + w = append(w, wc) + i = i + 2 + } + s := utf16.Decode(w) + return string(s) +} + // LPWSTR GetCommandLineW(); func XGetCommandLineW(t *TLS) uintptr { return uintptr(unsafe.Pointer(syscall.GetCommandLine())) @@ -4856,7 +5142,18 @@ func XGetAce(t *TLS, pAcl uintptr, dwAceIndex uint32, pAce uintptr) int32 { // ACL_INFORMATION_CLASS dwAclInformationClass // ); func XGetAclInformation(t *TLS, pAcl, pAclInformation uintptr, nAclInformationLength, dwAclInformationClass uint32) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procGetAclInformation.Addr(), 4, + pAclInformation, + pAclInformation, + uintptr(nAclInformationLength), + uintptr(dwAclInformationClass), + 0, + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // BOOL GetFileSecurityA( @@ -4867,7 +5164,18 @@ func XGetAclInformation(t *TLS, pAcl, pAclInformation uintptr, nAclInformationLe // LPDWORD lpnLengthNeeded // ); func XGetFileSecurityA(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procGetFileSecurityA.Addr(), 5, + lpFileName, + uintptr(RequestedInformation), + pSecurityDescriptor, + uintptr(nLength), + lpnLengthNeeded, + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // DWORD GetLengthSid( @@ -4884,14 +5192,29 @@ func XGetLengthSid(t *TLS, pSid uintptr) uint32 { // LPBOOL lpbDaclDefaulted // ); func XGetSecurityDescriptorDacl(t *TLS, pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted uintptr) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall6(procGetSecurityDescriptorDacl.Addr(), 4, + pSecurityDescriptor, + lpbDaclPresent, + pDacl, + lpbDaclDefaulted, + 0, + 0, + ) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // DWORD GetSidLengthRequired( // UCHAR nSubAuthorityCount // ); func XGetSidLengthRequired(t *TLS, nSubAuthorityCount uint8) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetSidLengthRequired.Addr(), 1, uintptr(nSubAuthorityCount), 0, 0) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // PDWORD GetSidSubAuthority( @@ -4899,7 +5222,11 @@ func XGetSidLengthRequired(t *TLS, nSubAuthorityCount uint8) int32 { // DWORD nSubAuthority // ); func XGetSidSubAuthority(t *TLS, pSid uintptr, nSubAuthority uint32) uintptr { - panic(todo("")) + r0, _, err := syscall.Syscall(procGetSidSubAuthority.Addr(), 2, pSid, uintptr(nSubAuthority), 0) + if err != 0 { + t.setErrno(err) + } + return r0 } // BOOL InitializeAcl( @@ -4917,7 +5244,11 @@ func XInitializeAcl(t *TLS, pAcl uintptr, nAclLength, dwAclRevision uint32) int3 // BYTE nSubAuthorityCount // ); func XInitializeSid(t *TLS, Sid, pIdentifierAuthority uintptr, nSubAuthorityCount uint8) int32 { - panic(todo("")) + r0, _, err := syscall.Syscall(procInitializeSid.Addr(), 3, Sid, pIdentifierAuthority, uintptr(nSubAuthorityCount)) + if err != 0 { + t.setErrno(err) + } + return int32(r0) } // VOID RaiseException( @@ -5369,8 +5700,8 @@ func X_gmtime64(t *TLS, sourceTime uintptr) uintptr { } // __time64_t _mktime64(struct tm *timeptr); -func X_mktime64(t *TLS, timeptr uintptr) int64 { - panic(todo("")) +func X_mktime64(t *TLS, timeptr uintptr) time.X__time64_t { + return time.X__time64_t(Xmktime(t, timeptr)) } // char * gai_strerrorA(int ecode); @@ -5416,3 +5747,128 @@ func X__ccgo_pthreadAttrGetDetachState(tls *TLS, a uintptr) int32 { /* pthread_a func X__ccgo_pthreadMutexattrGettype(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:93:5: */ return *(*int32)(unsafe.Pointer(a)) & int32(3) } + +func Xchmod(t *TLS, pathname uintptr, mode int32) int32 { + panic(todo("%q %#o", GoString(pathname), mode)) +} + +// typedef enum _COMPUTER_NAME_FORMAT { +// ComputerNameNetBIOS, +// ComputerNameDnsHostname, +// ComputerNameDnsDomain, +// ComputerNameDnsFullyQualified, +// ComputerNamePhysicalNetBIOS, +// ComputerNamePhysicalDnsHostname, +// ComputerNamePhysicalDnsDomain, +// ComputerNamePhysicalDnsFullyQualified, +// ComputerNameMax +// } COMPUTER_NAME_FORMAT; + +// BOOL GetComputerNameExW( +// [in] COMPUTER_NAME_FORMAT NameType, +// [out] LPWSTR lpBuffer, +// [in, out] LPDWORD nSize +// ); +func XGetComputerNameExW(t *TLS, nameType int32, lpBuffer, nSize uintptr) int32 { + r0, _, err := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameType), lpBuffer, nSize) + if err != 0 { + t.setErrno(err) + } + return int32(r0) +} + +// double _copysign( +// double x, +// double y +// ); +func X_copysign(t *TLS, x, y float64) float64 { return Xcopysign(t, x, y) } + +// int _wtoi( +// const wchar_t *str +// ); +func X_wtoi(t *TLS, str uintptr) int32 { + panic(todo("")) +} + +func allocW(t *TLS, v string) (r uintptr) { + s := utf16.Encode([]rune(v)) + p := Xcalloc(t, types.Size_t(len(s)+1), 2) + if p == 0 { + panic(todo("")) + } + + r = p + for _, v := range s { + *(*uint16)(unsafe.Pointer(p)) = v + p += 2 + } + return r +} + +// wchar_t *_wgetenv( +// const wchar_t *varname +// ); +func X_wgetenv(t *TLS, varname uintptr) uintptr { + if !wenvValid { + bootWinEnviron(t) + } + k := strings.ToLower(goWideStringNZ(varname)) + for _, v := range winEnviron[:len(winEnviron)-1] { + s := strings.ToLower(goWideStringNZ(v)) + x := strings.IndexByte(s, '=') + if s[:x] == k { + // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), goWideStringNZ(v)) + return v + } + } + + // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), "") + return 0 +} + +// int _wputenv( +// const wchar_t *envstring +// ); +func X_wputenv(t *TLS, envstring uintptr) int32 { + if !wenvValid { + bootWinEnviron(t) + } + s0 := goWideStringNZ(envstring) + s := strings.ToLower(s0) + x := strings.IndexByte(s, '=') + k := s[:x] + for i, v := range winEnviron[:len(winEnviron)-1] { + s2 := strings.ToLower(goWideStringNZ(v)) + x := strings.IndexByte(s2, '=') + if s2[:x] == k { + Xfree(t, v) + winEnviron[i] = allocW(t, s0) + return 0 + } + } + + np := allocW(t, s0) + winEnviron = winEnviron[:len(winEnviron)-1] + winEnviron = append(winEnviron, np, 0) + wenviron = uintptr(unsafe.Pointer(&winEnviron[0])) + return 0 +} + +func bootWinEnviron(t *TLS) { + winEnviron = winEnviron[:0] + p := Environ() + for { + q := *(*uintptr)(unsafe.Pointer(p)) + p += unsafe.Sizeof(uintptr(0)) + if q == 0 { + break + } + + s := GoString(q) + // trc("%v: %q", origin(1), s) + r := allocW(t, s) + winEnviron = append(winEnviron, r) + } + wenviron = uintptr(unsafe.Pointer(&winEnviron[0])) + wenvValid = true +} |