source: code/trunk/vendor/modernc.org/libc/libc_windows.go@ 823

Last change on this file since 823 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 151.7 KB
Line 
1// Copyright 2020 The Libc Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package libc // import "modernc.org/libc"
6
7import (
8 "errors"
9 "fmt"
10 "math"
11 "os"
12 "os/exec"
13 "os/user"
14 "path/filepath"
15 "strings"
16 "sync"
17 "sync/atomic"
18 "syscall"
19 gotime "time"
20 "unicode"
21 "unicode/utf16"
22 "unsafe"
23
24 "modernc.org/libc/errno"
25 "modernc.org/libc/fcntl"
26 "modernc.org/libc/limits"
27 "modernc.org/libc/stdio"
28 "modernc.org/libc/sys/stat"
29 "modernc.org/libc/sys/types"
30 "modernc.org/libc/time"
31 "modernc.org/libc/unistd"
32)
33
34// Keep these outside of the var block otherwise go generate will miss them.
35var X__imp__environ = EnvironP()
36var X__imp__wenviron = uintptr(unsafe.Pointer(&wenviron))
37var X_imp___environ = EnvironP()
38var X_iob [stdio.X_IOB_ENTRIES]stdio.FILE
39
40var Xtimezone long // extern long timezone;
41
42var (
43 iobMap = map[uintptr]int32{} // &_iob[fd] -> fd
44 wenvValid bool
45 wenviron uintptr // &winEnviron[0]
46 winEnviron = []uintptr{0}
47)
48
49func init() {
50 for i := range X_iob {
51 iobMap[uintptr(unsafe.Pointer(&X_iob[i]))] = int32(i)
52 }
53}
54
55func winGetObject(stream uintptr) interface{} {
56 if fd, ok := iobMap[stream]; ok {
57 f, _ := fdToFile(fd)
58 return f
59 }
60
61 return getObject(stream)
62}
63
64type (
65 long = int32
66 ulong = uint32
67)
68
69var (
70 modkernel32 = syscall.NewLazyDLL("kernel32.dll")
71 //--
72 procAreFileApisANSI = modkernel32.NewProc("AreFileApisANSI")
73 procCopyFileW = modkernel32.NewProc("CopyFileW")
74 procCreateEventA = modkernel32.NewProc("CreateEventA")
75 procCreateEventW = modkernel32.NewProc("CreateEventW")
76 procCreateFileA = modkernel32.NewProc("CreateFileA")
77 procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
78 procCreateFileW = modkernel32.NewProc("CreateFileW")
79 procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
80 procCreatePipe = modkernel32.NewProc("CreatePipe")
81 procCreateProcessA = modkernel32.NewProc("CreateProcessA")
82 procCreateProcessW = modkernel32.NewProc("CreateProcessW")
83 procCreateThread = modkernel32.NewProc("CreateThread")
84 procDeleteCriticalSection = modkernel32.NewProc("DeleteCriticalSection")
85 procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
86 procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
87 procEnterCriticalSection = modkernel32.NewProc("EnterCriticalSection")
88 procFindClose = modkernel32.NewProc("FindClose")
89 procFindFirstFileExW = modkernel32.NewProc("FindFirstFileExW")
90 procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
91 procFindNextFileW = modkernel32.NewProc("FindNextFileW")
92 procFormatMessageW = modkernel32.NewProc("FormatMessageW")
93 procGetACP = modkernel32.NewProc("GetACP")
94 procGetCommState = modkernel32.NewProc("GetCommState")
95 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
96 procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
97 procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
98 procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
99 procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
100 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
101 procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
102 procGetEnvironmentVariableA = modkernel32.NewProc("GetEnvironmentVariableA")
103 procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
104 procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
105 procGetExitCodeThread = modkernel32.NewProc("GetExitCodeThread")
106 procGetFileAttributesA = modkernel32.NewProc("GetFileAttributesA")
107 procGetFileAttributesExA = modkernel32.NewProc("GetFileAttributesExA")
108 procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
109 procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
110 procGetFileSize = modkernel32.NewProc("GetFileSize")
111 procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
112 procGetLastError = modkernel32.NewProc("GetLastError")
113 procGetLogicalDriveStringsA = modkernel32.NewProc("GetLogicalDriveStringsA")
114 procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
115 procGetModuleHandleA = modkernel32.NewProc("GetModuleHandleA")
116 procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
117 procGetPrivateProfileStringA = modkernel32.NewProc("GetPrivateProfileStringA")
118 procGetProcAddress = modkernel32.NewProc("GetProcAddress")
119 procGetProcessHeap = modkernel32.NewProc("GetProcessHeap")
120 procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
121 procGetSystemTime = modkernel32.NewProc("GetSystemTime")
122 procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
123 procGetTempFileNameW = modkernel32.NewProc("GetTempFileNameW")
124 procGetTickCount = modkernel32.NewProc("GetTickCount")
125 procGetVersionExA = modkernel32.NewProc("GetVersionExA")
126 procGetVersionExW = modkernel32.NewProc("GetVersionExW")
127 procGetVolumeInformationA = modkernel32.NewProc("GetVolumeInformationA")
128 procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
129 procHeapAlloc = modkernel32.NewProc("HeapAlloc")
130 procHeapFree = modkernel32.NewProc("HeapFree")
131 procInitializeCriticalSection = modkernel32.NewProc("InitializeCriticalSection")
132 procLeaveCriticalSection = modkernel32.NewProc("LeaveCriticalSection")
133 procLockFile = modkernel32.NewProc("LockFile")
134 procLockFileEx = modkernel32.NewProc("LockFileEx")
135 procLstrlenW = modkernel32.NewProc("lstrlenW")
136 procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
137 procMoveFileW = modkernel32.NewProc("MoveFileW")
138 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
139 procOpenEventA = modkernel32.NewProc("OpenEventA")
140 procPeekConsoleInputW = modkernel32.NewProc("PeekConsoleInputW")
141 procPeekNamedPipe = modkernel32.NewProc("PeekNamedPipe")
142 procQueryPerformanceCounter = modkernel32.NewProc("QueryPerformanceCounter")
143 procQueryPerformanceFrequency = modkernel32.NewProc("QueryPerformanceFrequency")
144 procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
145 procReadFile = modkernel32.NewProc("ReadFile")
146 procResetEvent = modkernel32.NewProc("ResetEvent")
147 procSearchPathW = modkernel32.NewProc("SearchPathW")
148 procSetConsoleCtrlHandler = modkernel32.NewProc("SetConsoleCtrlHandler")
149 procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
150 procSetConsoleTextAttribute = modkernel32.NewProc("SetConsoleTextAttribute")
151 procSetEvent = modkernel32.NewProc("SetEvent")
152 procSetFilePointer = modkernel32.NewProc("SetFilePointer")
153 procSleepEx = modkernel32.NewProc("SleepEx")
154 procSystemTimeToFileTime = modkernel32.NewProc("SystemTimeToFileTime")
155 procTerminateThread = modkernel32.NewProc("TerminateThread")
156 procUnlockFile = modkernel32.NewProc("UnlockFile")
157 procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
158 procWaitForSingleObjectEx = modkernel32.NewProc("WaitForSingleObjectEx")
159 procWideCharToMultiByte = modkernel32.NewProc("WideCharToMultiByte")
160 procWriteConsoleA = modkernel32.NewProc("WriteConsoleA")
161 procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
162 procWriteFile = modkernel32.NewProc("WriteFile")
163
164 // procSetConsoleCP = modkernel32.NewProc("SetConsoleCP")
165 // procSetThreadPriority = modkernel32.NewProc("SetThreadPriority")
166 //--
167
168 modadvapi = syscall.NewLazyDLL("advapi32.dll")
169 //--
170 procAccessCheck = modadvapi.NewProc("AccessCheck")
171 procGetAclInformation = modadvapi.NewProc("GetAclInformation")
172 procGetFileSecurityA = modadvapi.NewProc("GetFileSecurityA")
173 procGetFileSecurityW = modadvapi.NewProc("GetFileSecurityW")
174 procGetSecurityDescriptorDacl = modadvapi.NewProc("GetSecurityDescriptorDacl")
175 procGetSecurityDescriptorOwner = modadvapi.NewProc("GetSecurityDescriptorOwner")
176 procGetSidIdentifierAuthority = modadvapi.NewProc("GetSidIdentifierAuthority")
177 procGetSidLengthRequired = modadvapi.NewProc("GetSidLengthRequired")
178 procGetSidSubAuthority = modadvapi.NewProc("GetSidSubAuthority")
179 procImpersonateSelf = modadvapi.NewProc("ImpersonateSelf")
180 procInitializeSid = modadvapi.NewProc("InitializeSid")
181 procOpenThreadToken = modadvapi.NewProc("OpenThreadToken")
182 procRevertToSelf = modadvapi.NewProc("RevertToSelf")
183 //--
184
185 modws2_32 = syscall.NewLazyDLL("ws2_32.dll")
186 //--
187 procWSAStartup = modws2_32.NewProc("WSAStartup")
188 //--
189
190 moduser32 = syscall.NewLazyDLL("user32.dll")
191 //--
192 procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
193 procMsgWaitForMultipleObjectsEx = moduser32.NewProc("MsgWaitForMultipleObjectsEx")
194 procPeekMessageW = moduser32.NewProc("PeekMessageW")
195 procRegisterClassW = moduser32.NewProc("RegisterClassW")
196 procUnregisterClassW = moduser32.NewProc("UnregisterClassW")
197 procWaitForInputIdle = moduser32.NewProc("WaitForInputIdle")
198 //--
199
200 netapi = syscall.NewLazyDLL("netapi32.dll")
201 procNetGetDCName = netapi.NewProc("NetGetDCName")
202 procNetUserGetInfo = netapi.NewProc("NetUserGetInfo")
203
204 userenvapi = syscall.NewLazyDLL("userenv.dll")
205 procGetProfilesDirectoryW = userenvapi.NewProc("GetProfilesDirectoryW")
206)
207
208var (
209 threadCallback uintptr
210)
211
212func init() {
213 isWindows = true
214 threadCallback = syscall.NewCallback(ThreadProc)
215}
216
217// ---------------------------------
218// Windows filehandle-to-fd mapping
219// so the lib-c interface contract looks
220// like normal fds being passed around
221// but we're mapping them back and forth to
222// native windows file handles (syscall.Handle)
223//
224
225var EBADF = errors.New("EBADF")
226
227var w_nextFd int32 = 42
228var w_fdLock sync.Mutex
229var w_fd_to_file = map[int32]*file{}
230
231type file struct {
232 _fd int32
233 hadErr bool
234 t uintptr
235 syscall.Handle
236}
237
238func addFile(hdl syscall.Handle, fd int32) uintptr {
239 var f = file{_fd: fd, Handle: hdl}
240 w_fdLock.Lock()
241 defer w_fdLock.Unlock()
242 w_fd_to_file[fd] = &f
243 f.t = addObject(&f)
244 return f.t
245}
246
247func remFile(f *file) {
248 removeObject(f.t)
249 w_fdLock.Lock()
250 defer w_fdLock.Unlock()
251 delete(w_fd_to_file, f._fd)
252}
253
254func fdToFile(fd int32) (*file, bool) {
255 w_fdLock.Lock()
256 defer w_fdLock.Unlock()
257 f, ok := w_fd_to_file[fd]
258 return f, ok
259}
260
261// Wrap the windows handle up tied to a unique fd
262func wrapFdHandle(hdl syscall.Handle) (uintptr, int32) {
263 newFd := atomic.AddInt32(&w_nextFd, 1)
264 return addFile(hdl, newFd), newFd
265}
266
267func (f *file) err() bool {
268 return f.hadErr
269}
270
271func (f *file) setErr() {
272 f.hadErr = true
273}
274
275// -----------------------------------
276// On windows we have to fetch these
277//
278// stdout, stdin, sterr
279//
280// Using the windows specific GetStdHandle
281// they're mapped to the standard fds (0,1,2)
282// Note: it's possible they don't exist
283// if the app has been built for a GUI only
284// target in windows. If that's the case
285// panic seems like the only reasonable option
286// ------------------------------
287
288func newFile(t *TLS, fd int32) uintptr {
289
290 if fd == unistd.STDIN_FILENO {
291 h, err := syscall.GetStdHandle(syscall.STD_INPUT_HANDLE)
292 if err != nil {
293 panic("no console")
294 }
295 return addFile(h, fd)
296 }
297 if fd == unistd.STDOUT_FILENO {
298 h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
299 if err != nil {
300 panic("no console")
301 }
302 return addFile(h, fd)
303 }
304 if fd == unistd.STDERR_FILENO {
305 h, err := syscall.GetStdHandle(syscall.STD_ERROR_HANDLE)
306 if err != nil {
307 panic("no console")
308 }
309 return addFile(h, fd)
310 }
311
312 // should not get here -- unless newFile
313 // is being used from somewhere we don't know about
314 // to originate fds.
315
316 panic("unknown fd source")
317 return 0
318}
319
320func (f *file) close(t *TLS) int32 {
321 remFile(f)
322 err := syscall.Close(f.Handle)
323 if err != nil {
324 return (-1) // EOF
325 }
326 return 0
327}
328
329func fwrite(fd int32, b []byte) (int, error) {
330 if fd == unistd.STDOUT_FILENO {
331 return write(b)
332 }
333
334 f, ok := fdToFile(fd)
335 if !ok {
336 return -1, EBADF
337 }
338
339 if dmesgs {
340 dmesg("%v: fd %v: %s", origin(1), fd, b)
341 }
342 return syscall.Write(f.Handle, b)
343}
344
345// int fprintf(FILE *stream, const char *format, ...);
346func Xfprintf(t *TLS, stream, format, args uintptr) int32 {
347 f, ok := winGetObject(stream).(*file)
348 if !ok {
349 t.setErrno(errno.EBADF)
350 return -1
351 }
352
353 n, _ := fwrite(f._fd, printf(format, args))
354 return int32(n)
355}
356
357// int usleep(useconds_t usec);
358func Xusleep(t *TLS, usec types.Useconds_t) int32 {
359 gotime.Sleep(gotime.Microsecond * gotime.Duration(usec))
360 return 0
361}
362
363// int getrusage(int who, struct rusage *usage);
364func Xgetrusage(t *TLS, who int32, usage uintptr) int32 {
365 panic(todo(""))
366 // if _, _, err := unix.Syscall(unix.SYS_GETRUSAGE, uintptr(who), usage, 0); err != 0 {
367 // t.setErrno(err)
368 // return -1
369 // }
370
371 // return 0
372}
373
374// int lstat(const char *pathname, struct stat *statbuf);
375func Xlstat(t *TLS, pathname, statbuf uintptr) int32 {
376 return Xlstat64(t, pathname, statbuf)
377}
378
379// int stat(const char *pathname, struct stat *statbuf);
380func Xstat(t *TLS, pathname, statbuf uintptr) int32 {
381 return Xstat64(t, pathname, statbuf)
382}
383
384// int chdir(const char *path);
385func Xchdir(t *TLS, path uintptr) int32 {
386 err := syscall.Chdir(GoString(path))
387 if err != nil {
388 t.setErrno(err)
389 return -1
390 }
391
392 if dmesgs {
393 dmesg("%v: %q: ok", origin(1), GoString(path))
394 }
395 return 0
396}
397
398var localtime time.Tm
399
400// struct tm *localtime(const time_t *timep);
401func Xlocaltime(_ *TLS, timep uintptr) uintptr {
402 loc := gotime.Local
403 if r := getenv(Environ(), "TZ"); r != 0 {
404 zone, off := parseZone(GoString(r))
405 loc = gotime.FixedZone(zone, -off)
406 }
407 ut := *(*time.Time_t)(unsafe.Pointer(timep))
408 t := gotime.Unix(int64(ut), 0).In(loc)
409 localtime.Ftm_sec = int32(t.Second())
410 localtime.Ftm_min = int32(t.Minute())
411 localtime.Ftm_hour = int32(t.Hour())
412 localtime.Ftm_mday = int32(t.Day())
413 localtime.Ftm_mon = int32(t.Month() - 1)
414 localtime.Ftm_year = int32(t.Year() - 1900)
415 localtime.Ftm_wday = int32(t.Weekday())
416 localtime.Ftm_yday = int32(t.YearDay())
417 localtime.Ftm_isdst = Bool32(isTimeDST(t))
418 return uintptr(unsafe.Pointer(&localtime))
419}
420
421// struct tm *localtime(const time_t *timep);
422func X_localtime64(_ *TLS, timep uintptr) uintptr {
423 return Xlocaltime(nil, timep)
424}
425
426// struct tm *localtime_r(const time_t *timep, struct tm *result);
427func Xlocaltime_r(_ *TLS, timep, result uintptr) uintptr {
428 panic(todo(""))
429 // loc := gotime.Local
430 // if r := getenv(Environ(), "TZ"); r != 0 {
431 // zone, off := parseZone(GoString(r))
432 // loc = gotime.FixedZone(zone, -off)
433 // }
434 // ut := *(*unix.Time_t)(unsafe.Pointer(timep))
435 // t := gotime.Unix(int64(ut), 0).In(loc)
436 // (*time.Tm)(unsafe.Pointer(result)).Ftm_sec = int32(t.Second())
437 // (*time.Tm)(unsafe.Pointer(result)).Ftm_min = int32(t.Minute())
438 // (*time.Tm)(unsafe.Pointer(result)).Ftm_hour = int32(t.Hour())
439 // (*time.Tm)(unsafe.Pointer(result)).Ftm_mday = int32(t.Day())
440 // (*time.Tm)(unsafe.Pointer(result)).Ftm_mon = int32(t.Month() - 1)
441 // (*time.Tm)(unsafe.Pointer(result)).Ftm_year = int32(t.Year() - 1900)
442 // (*time.Tm)(unsafe.Pointer(result)).Ftm_wday = int32(t.Weekday())
443 // (*time.Tm)(unsafe.Pointer(result)).Ftm_yday = int32(t.YearDay())
444 // (*time.Tm)(unsafe.Pointer(result)).Ftm_isdst = Bool32(isTimeDST(t))
445 // return result
446}
447
448// int _wopen(
449//
450// const wchar_t *filename,
451// int oflag [,
452// int pmode]
453//
454// );
455func X_wopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
456 var mode types.Mode_t
457 if args != 0 {
458 mode = *(*types.Mode_t)(unsafe.Pointer(args))
459 }
460 s := goWideString(pathname)
461 h, err := syscall.Open(GoString(pathname), int(flags), uint32(mode))
462 if err != nil {
463 if dmesgs {
464 dmesg("%v: %q %#x: %v", origin(1), s, flags, err)
465 }
466
467 t.setErrno(err)
468 return 0
469 }
470
471 _, n := wrapFdHandle(h)
472 if dmesgs {
473 dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), s, flags, mode, n)
474 }
475 return n
476}
477
478// int open(const char *pathname, int flags, ...);
479func Xopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
480 return Xopen64(t, pathname, flags, args)
481}
482
483// int open(const char *pathname, int flags, ...);
484func Xopen64(t *TLS, pathname uintptr, flags int32, cmode uintptr) int32 {
485
486 var mode types.Mode_t
487 if cmode != 0 {
488 mode = (types.Mode_t)(VaUint32(&cmode))
489 }
490 // fdcwd := fcntl.AT_FDCWD
491 h, err := syscall.Open(GoString(pathname), int(flags), uint32(mode))
492 if err != nil {
493
494 if dmesgs {
495 dmesg("%v: %q %#x: %v", origin(1), GoString(pathname), flags, err)
496 }
497
498 t.setErrno(err)
499 return -1
500 }
501
502 _, n := wrapFdHandle(h)
503 if dmesgs {
504 dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), GoString(pathname), flags, mode, n)
505 }
506 return n
507}
508
509// off_t lseek(int fd, off_t offset, int whence);
510func Xlseek(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
511 return types.Off_t(Xlseek64(t, fd, offset, whence))
512}
513
514func whenceStr(whence int32) string {
515 switch whence {
516 case syscall.FILE_CURRENT:
517 return "SEEK_CUR"
518 case syscall.FILE_END:
519 return "SEEK_END"
520 case syscall.FILE_BEGIN:
521 return "SEEK_SET"
522 default:
523 return fmt.Sprintf("whence(%d)", whence)
524 }
525}
526
527var fsyncStatbuf stat.Stat
528
529// int fsync(int fd);
530func Xfsync(t *TLS, fd int32) int32 {
531
532 f, ok := fdToFile(fd)
533 if !ok {
534 t.setErrno(errno.EBADF)
535 return -1
536 }
537 err := syscall.FlushFileBuffers(f.Handle)
538 if err != nil {
539 t.setErrno(err)
540 return -1
541 }
542
543 if dmesgs {
544 dmesg("%v: %d: ok", origin(1), fd)
545 }
546 return 0
547}
548
549// long sysconf(int name);
550func Xsysconf(t *TLS, name int32) long {
551 panic(todo(""))
552 // switch name {
553 // case unistd.X_SC_PAGESIZE:
554 // return long(unix.Getpagesize())
555 // }
556
557 // panic(todo(""))
558}
559
560// int close(int fd);
561func Xclose(t *TLS, fd int32) int32 {
562
563 f, ok := fdToFile(fd)
564 if !ok {
565 t.setErrno(errno.EBADF)
566 return -1
567 }
568
569 err := syscall.Close(f.Handle)
570 if err != nil {
571 t.setErrno(err)
572 return -1
573 }
574
575 if dmesgs {
576 dmesg("%v: %d: ok", origin(1), fd)
577 }
578 return 0
579}
580
581// char *getcwd(char *buf, size_t size);
582func Xgetcwd(t *TLS, buf uintptr, size types.Size_t) uintptr {
583
584 b := make([]uint16, size)
585 n, err := syscall.GetCurrentDirectory(uint32(len(b)), &b[0])
586 if err != nil {
587 t.setErrno(err)
588 return 0
589 }
590 // to bytes
591 var wd = []byte(string(utf16.Decode(b[0:n])))
592 if types.Size_t(len(wd)) > size {
593 t.setErrno(errno.ERANGE)
594 return 0
595 }
596
597 copy((*RawMem)(unsafe.Pointer(buf))[:], wd)
598 (*RawMem)(unsafe.Pointer(buf))[len(wd)] = 0
599
600 if dmesgs {
601 dmesg("%v: %q: ok", origin(1), GoString(buf))
602 }
603 return buf
604}
605
606// int fstat(int fd, struct stat *statbuf);
607func Xfstat(t *TLS, fd int32, statbuf uintptr) int32 {
608 return Xfstat64(t, fd, statbuf)
609}
610
611// int ftruncate(int fd, off_t length);
612func Xftruncate(t *TLS, fd int32, length types.Off_t) int32 {
613 return Xftruncate64(t, fd, length)
614}
615
616// int fcntl(int fd, int cmd, ... /* arg */ );
617func Xfcntl(t *TLS, fd, cmd int32, args uintptr) int32 {
618 return Xfcntl64(t, fd, cmd, args)
619}
620
621// int _read( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/read?view=msvc-160
622//
623// int const fd,
624// void * const buffer,
625// unsigned const buffer_size
626//
627// );
628func Xread(t *TLS, fd int32, buf uintptr, count uint32) int32 {
629 f, ok := fdToFile(fd)
630 if !ok {
631 t.setErrno(errno.EBADF)
632 return -1
633 }
634
635 var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
636 n, err := syscall.Read(f.Handle, obuf)
637 if err != nil {
638 t.setErrno(err)
639 return -1
640 }
641
642 if dmesgs {
643 // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
644 dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
645 }
646 return int32(n)
647}
648
649// int _write( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/write?view=msvc-160
650//
651// int fd,
652// const void *buffer,
653// unsigned int count
654//
655// );
656func Xwrite(t *TLS, fd int32, buf uintptr, count uint32) int32 {
657 f, ok := fdToFile(fd)
658 if !ok {
659 t.setErrno(errno.EBADF)
660 return -1
661 }
662
663 var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
664 n, err := syscall.Write(f.Handle, obuf)
665 if err != nil {
666 if dmesgs {
667 dmesg("%v: fd %v, count %#x: %v", origin(1), fd, count, err)
668 }
669 t.setErrno(err)
670 return -1
671 }
672
673 if dmesgs {
674 // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
675 dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
676 }
677 return int32(n)
678}
679
680// int fchmod(int fd, mode_t mode);
681func Xfchmod(t *TLS, fd int32, mode types.Mode_t) int32 {
682 panic(todo(""))
683 // if _, _, err := unix.Syscall(unix.SYS_FCHMOD, uintptr(fd), uintptr(mode), 0); err != 0 {
684 // t.setErrno(err)
685 // return -1
686 // }
687
688 // if dmesgs {
689 // dmesg("%v: %d %#o: ok", origin(1), fd, mode)
690 // }
691 // return 0
692}
693
694// // int fchown(int fd, uid_t owner, gid_t group);
695// func Xfchown(t *TLS, fd int32, owner types.Uid_t, group types.Gid_t) int32 {
696// if _, _, err := unix.Syscall(unix.SYS_FCHOWN, uintptr(fd), uintptr(owner), uintptr(group)); err != 0 {
697// t.setErrno(err)
698// return -1
699// }
700//
701// return 0
702// }
703
704// // uid_t geteuid(void);
705// func Xgeteuid(t *TLS) types.Uid_t {
706// n, _, _ := unix.Syscall(unix.SYS_GETEUID, 0, 0, 0)
707// return types.Uid_t(n)
708// }
709
710// int munmap(void *addr, size_t length);
711func Xmunmap(t *TLS, addr uintptr, length types.Size_t) int32 {
712 panic(todo(""))
713 // if _, _, err := unix.Syscall(unix.SYS_MUNMAP, addr, uintptr(length), 0); err != 0 {
714 // t.setErrno(err)
715 // return -1
716 // }
717
718 // return 0
719}
720
721// int gettimeofday(struct timeval *tv, struct timezone *tz);
722func Xgettimeofday(t *TLS, tv, tz uintptr) int32 {
723 panic(todo(""))
724 // if tz != 0 {
725 // panic(todo(""))
726 // }
727
728 // var tvs unix.Timeval
729 // err := unix.Gettimeofday(&tvs)
730 // if err != nil {
731 // t.setErrno(err)
732 // return -1
733 // }
734
735 // *(*unix.Timeval)(unsafe.Pointer(tv)) = tvs
736 // return 0
737}
738
739// int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
740func Xgetsockopt(t *TLS, _ ...interface{}) int32 {
741 panic(todo(""))
742 // if _, _, err := unix.Syscall6(unix.SYS_GETSOCKOPT, uintptr(sockfd), uintptr(level), uintptr(optname), optval, optlen, 0); err != 0 {
743 // t.setErrno(err)
744 // return -1
745 // }
746
747 // return 0
748}
749
750// // int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
751func Xsetsockopt(t *TLS, _ ...interface{}) int32 {
752 panic(todo(""))
753}
754
755// int ioctl(int fd, unsigned long request, ...);
756func Xioctl(t *TLS, fd int32, request ulong, va uintptr) int32 {
757 panic(todo(""))
758 // var argp uintptr
759 // if va != 0 {
760 // argp = VaUintptr(&va)
761 // }
762 // n, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(request), argp)
763 // if err != 0 {
764 // t.setErrno(err)
765 // return -1
766 // }
767
768 // return int32(n)
769}
770
771// int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
772func Xselect(t *TLS, nfds int32, readfds, writefds, exceptfds, timeout uintptr) int32 {
773 panic(todo(""))
774 // n, err := unix.Select(
775 // int(nfds),
776 // (*unix.FdSet)(unsafe.Pointer(readfds)),
777 // (*unix.FdSet)(unsafe.Pointer(writefds)),
778 // (*unix.FdSet)(unsafe.Pointer(exceptfds)),
779 // (*unix.Timeval)(unsafe.Pointer(timeout)),
780 // )
781 // if err != nil {
782 // t.setErrno(err)
783 // return -1
784 // }
785
786 // return int32(n)
787}
788
789// int mkfifo(const char *pathname, mode_t mode);
790func Xmkfifo(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
791 panic(todo(""))
792 // if err := unix.Mkfifo(GoString(pathname), mode); err != nil {
793 // t.setErrno(err)
794 // return -1
795 // }
796 //
797 // return 0
798}
799
800// mode_t umask(mode_t mask);
801func Xumask(t *TLS, mask types.Mode_t) types.Mode_t {
802 panic(todo(""))
803 // n, _, _ := unix.Syscall(unix.SYS_UMASK, uintptr(mask), 0, 0)
804 // return types.Mode_t(n)
805}
806
807// int execvp(const char *file, char *const argv[]);
808func Xexecvp(t *TLS, file, argv uintptr) int32 {
809 panic(todo(""))
810 // if _, _, err := unix.Syscall(unix.SYS_EXECVE, file, argv, Environ()); err != 0 {
811 // t.setErrno(err)
812 // return -1
813 // }
814 //
815 // return 0
816}
817
818// pid_t waitpid(pid_t pid, int *wstatus, int options);
819func Xwaitpid(t *TLS, pid types.Pid_t, wstatus uintptr, optname int32) types.Pid_t {
820 panic(todo(""))
821 // n, _, err := unix.Syscall6(unix.SYS_WAIT4, uintptr(pid), wstatus, uintptr(optname), 0, 0, 0)
822 // if err != 0 {
823 // t.setErrno(err)
824 // return -1
825 // }
826 //
827 // return types.Pid_t(n)
828}
829
830// int uname(struct utsname *buf);
831func Xuname(t *TLS, buf uintptr) int32 {
832 panic(todo(""))
833 // if _, _, err := unix.Syscall(unix.SYS_UNAME, buf, 0, 0); err != 0 {
834 // t.setErrno(err)
835 // return -1
836 // }
837 //
838 // return 0
839}
840
841// int getrlimit(int resource, struct rlimit *rlim);
842func Xgetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
843 return Xgetrlimit64(t, resource, rlim)
844}
845
846// int setrlimit(int resource, const struct rlimit *rlim);
847func Xsetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
848 return Xsetrlimit64(t, resource, rlim)
849}
850
851// int setrlimit(int resource, const struct rlimit *rlim);
852func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
853 panic(todo(""))
854 // if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
855 // t.setErrno(err)
856 // return -1
857 // }
858 //
859 // return 0
860}
861
862// // uid_t getuid(void);
863// func Xgetuid(t *TLS) types.Uid_t {
864// return types.Uid_t(os.Getuid())
865// }
866
867// pid_t getpid(void);
868func Xgetpid(t *TLS) int32 {
869 return int32(os.Getpid())
870}
871
872// int system(const char *command);
873func Xsystem(t *TLS, command uintptr) int32 {
874 s := GoString(command)
875 if command == 0 {
876 panic(todo(""))
877 }
878
879 cmd := exec.Command("sh", "-c", s)
880 cmd.Stdout = os.Stdout
881 cmd.Stderr = os.Stderr
882 err := cmd.Run()
883 if err != nil {
884 ps := err.(*exec.ExitError)
885 return int32(ps.ExitCode())
886 }
887
888 return 0
889}
890
891// var staticGetpwuid pwd.Passwd
892//
893// func init() {
894// atExit = append(atExit, func() { closePasswd(&staticGetpwuid) })
895// }
896//
897// func closePasswd(p *pwd.Passwd) {
898// Xfree(nil, p.Fpw_name)
899// Xfree(nil, p.Fpw_passwd)
900// Xfree(nil, p.Fpw_gecos)
901// Xfree(nil, p.Fpw_dir)
902// Xfree(nil, p.Fpw_shell)
903// *p = pwd.Passwd{}
904// }
905
906// struct passwd *getpwuid(uid_t uid);
907func Xgetpwuid(t *TLS, uid uint32) uintptr {
908 panic(todo(""))
909 // f, err := os.Open("/etc/passwd")
910 // if err != nil {
911 // panic(todo("", err))
912 // }
913 //
914 // defer f.Close()
915 //
916 // sid := strconv.Itoa(int(uid))
917 // sc := bufio.NewScanner(f)
918 // for sc.Scan() {
919 // // eg. "root:x:0:0:root:/root:/bin/bash"
920 // a := strings.Split(sc.Text(), ":")
921 // if len(a) < 7 {
922 // panic(todo(""))
923 // }
924 //
925 // if a[2] == sid {
926 // uid, err := strconv.Atoi(a[2])
927 // if err != nil {
928 // panic(todo(""))
929 // }
930 //
931 // gid, err := strconv.Atoi(a[3])
932 // if err != nil {
933 // panic(todo(""))
934 // }
935 //
936 // closePasswd(&staticGetpwuid)
937 // gecos := a[4]
938 // if strings.Contains(gecos, ",") {
939 // a := strings.Split(gecos, ",")
940 // gecos = a[0]
941 // }
942 // initPasswd(t, &staticGetpwuid, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
943 // return uintptr(unsafe.Pointer(&staticGetpwuid))
944 // }
945 // }
946 //
947 // if sc.Err() != nil {
948 // panic(todo(""))
949 // }
950 //
951 // return 0
952}
953
954// func initPasswd(t *TLS, p *pwd.Passwd, name, pwd string, uid, gid uint32, gecos, dir, shell string) {
955// p.Fpw_name = cString(t, name)
956// p.Fpw_passwd = cString(t, pwd)
957// p.Fpw_uid = uid
958// p.Fpw_gid = gid
959// p.Fpw_gecos = cString(t, gecos)
960// p.Fpw_dir = cString(t, dir)
961// p.Fpw_shell = cString(t, shell)
962// }
963
964// int setvbuf(FILE *stream, char *buf, int mode, size_t size);
965func Xsetvbuf(t *TLS, stream, buf uintptr, mode int32, size types.Size_t) int32 {
966 return 0 //TODO
967}
968
969// int raise(int sig);
970func Xraise(t *TLS, sig int32) int32 {
971 panic(todo(""))
972}
973
974// int backtrace(void **buffer, int size);
975func Xbacktrace(t *TLS, buf uintptr, size int32) int32 {
976 panic(todo(""))
977}
978
979// void backtrace_symbols_fd(void *const *buffer, int size, int fd);
980func Xbacktrace_symbols_fd(t *TLS, buffer uintptr, size, fd int32) {
981 panic(todo(""))
982}
983
984// int fileno(FILE *stream);
985func Xfileno(t *TLS, stream uintptr) int32 {
986 if stream == 0 {
987 t.setErrno(errno.EBADF)
988 return -1
989 }
990
991 f, ok := winGetObject(stream).(*file)
992 if !ok {
993 t.setErrno(errno.EBADF)
994 return -1
995 }
996 return f._fd
997}
998
999// var staticGetpwnam pwd.Passwd
1000//
1001// func init() {
1002// atExit = append(atExit, func() { closePasswd(&staticGetpwnam) })
1003// }
1004//
1005// // struct passwd *getpwnam(const char *name);
1006// func Xgetpwnam(t *TLS, name uintptr) uintptr {
1007// f, err := os.Open("/etc/passwd")
1008// if err != nil {
1009// panic(todo("", err))
1010// }
1011//
1012// defer f.Close()
1013//
1014// sname := GoString(name)
1015// sc := bufio.NewScanner(f)
1016// for sc.Scan() {
1017// // eg. "root:x:0:0:root:/root:/bin/bash"
1018// a := strings.Split(sc.Text(), ":")
1019// if len(a) < 7 {
1020// panic(todo(""))
1021// }
1022//
1023// if a[0] == sname {
1024// uid, err := strconv.Atoi(a[2])
1025// if err != nil {
1026// panic(todo(""))
1027// }
1028//
1029// gid, err := strconv.Atoi(a[3])
1030// if err != nil {
1031// panic(todo(""))
1032// }
1033//
1034// closePasswd(&staticGetpwnam)
1035// gecos := a[4]
1036// if strings.Contains(gecos, ",") {
1037// a := strings.Split(gecos, ",")
1038// gecos = a[0]
1039// }
1040// initPasswd(t, &staticGetpwnam, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
1041// return uintptr(unsafe.Pointer(&staticGetpwnam))
1042// }
1043// }
1044//
1045// if sc.Err() != nil {
1046// panic(todo(""))
1047// }
1048//
1049// return 0
1050// }
1051//
1052// var staticGetgrnam grp.Group
1053//
1054// func init() {
1055// atExit = append(atExit, func() { closeGroup(&staticGetgrnam) })
1056// }
1057//
1058// // struct group *getgrnam(const char *name);
1059// func Xgetgrnam(t *TLS, name uintptr) uintptr {
1060// f, err := os.Open("/etc/group")
1061// if err != nil {
1062// panic(todo(""))
1063// }
1064//
1065// defer f.Close()
1066//
1067// sname := GoString(name)
1068// sc := bufio.NewScanner(f)
1069// for sc.Scan() {
1070// // eg. "root:x:0:"
1071// a := strings.Split(sc.Text(), ":")
1072// if len(a) < 4 {
1073// panic(todo(""))
1074// }
1075//
1076// if a[0] == sname {
1077// closeGroup(&staticGetgrnam)
1078// gid, err := strconv.Atoi(a[2])
1079// if err != nil {
1080// panic(todo(""))
1081// }
1082//
1083// var names []string
1084// if a[3] != "" {
1085// names = strings.Split(a[3], ",")
1086// }
1087// initGroup(t, &staticGetgrnam, a[0], a[1], uint32(gid), names)
1088// return uintptr(unsafe.Pointer(&staticGetgrnam))
1089// }
1090// }
1091//
1092// if sc.Err() != nil {
1093// panic(todo(""))
1094// }
1095//
1096// return 0
1097// }
1098//
1099// func closeGroup(p *grp.Group) {
1100// Xfree(nil, p.Fgr_name)
1101// Xfree(nil, p.Fgr_passwd)
1102// if p.Fgr_mem != 0 {
1103// panic(todo(""))
1104// }
1105//
1106// *p = grp.Group{}
1107// }
1108//
1109// func initGroup(t *TLS, p *grp.Group, name, pwd string, gid uint32, names []string) {
1110// p.Fgr_name = cString(t, name)
1111// p.Fgr_passwd = cString(t, pwd)
1112// p.Fgr_gid = gid
1113// p.Fgr_mem = 0
1114// if len(names) != 0 {
1115// panic(todo("%q %q %v %q %v", name, pwd, gid, names, len(names)))
1116// }
1117// }
1118//
1119// func init() {
1120// atExit = append(atExit, func() { closeGroup(&staticGetgrgid) })
1121// }
1122//
1123// var staticGetgrgid grp.Group
1124//
1125// // struct group *getgrgid(gid_t gid);
1126// func Xgetgrgid(t *TLS, gid uint32) uintptr {
1127// f, err := os.Open("/etc/group")
1128// if err != nil {
1129// panic(todo(""))
1130// }
1131//
1132// defer f.Close()
1133//
1134// sid := strconv.Itoa(int(gid))
1135// sc := bufio.NewScanner(f)
1136// for sc.Scan() {
1137// // eg. "root:x:0:"
1138// a := strings.Split(sc.Text(), ":")
1139// if len(a) < 4 {
1140// panic(todo(""))
1141// }
1142//
1143// if a[2] == sid {
1144// closeGroup(&staticGetgrgid)
1145// var names []string
1146// if a[3] != "" {
1147// names = strings.Split(a[3], ",")
1148// }
1149// initGroup(t, &staticGetgrgid, a[0], a[1], gid, names)
1150// return uintptr(unsafe.Pointer(&staticGetgrgid))
1151// }
1152// }
1153//
1154// if sc.Err() != nil {
1155// panic(todo(""))
1156// }
1157//
1158// return 0
1159// }
1160
1161// int mkstemps(char *template, int suffixlen);
1162func Xmkstemps(t *TLS, template uintptr, suffixlen int32) int32 {
1163 return Xmkstemps64(t, template, suffixlen)
1164}
1165
1166// int mkstemps(char *template, int suffixlen);
1167func Xmkstemps64(t *TLS, template uintptr, suffixlen int32) int32 {
1168 panic(todo(""))
1169 // len := uintptr(Xstrlen(t, template))
1170 // x := template + uintptr(len-6) - uintptr(suffixlen)
1171 // for i := uintptr(0); i < 6; i++ {
1172 // if *(*byte)(unsafe.Pointer(x + i)) != 'X' {
1173 // t.setErrno(errno.EINVAL)
1174 // return -1
1175 // }
1176 // }
1177 //
1178 // fd, err := tempFile(template, x)
1179 // if err != 0 {
1180 // t.setErrno(err)
1181 // return -1
1182 // }
1183 //
1184 // return int32(fd)
1185}
1186
1187// int mkstemp(char *template);
1188func Xmkstemp64(t *TLS, template uintptr) int32 {
1189 return Xmkstemps64(t, template, 0)
1190}
1191
1192// func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) {
1193// var statp uintptr
1194// if stat != nil {
1195// statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
1196// if statp == 0 {
1197// panic("OOM")
1198// }
1199//
1200// *(*unix.Stat_t)(unsafe.Pointer(statp)) = *stat
1201// }
1202// csp := CString(path)
1203// if csp == 0 {
1204// panic("OOM")
1205// }
1206//
1207// return &fts.FTSENT{
1208// Ffts_info: uint16(info),
1209// Ffts_path: csp,
1210// Ffts_pathlen: uint16(len(path)),
1211// Ffts_statp: statp,
1212// Ffts_errno: int32(err),
1213// }
1214// }
1215//
1216// func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) uintptr {
1217// p := Xcalloc(t, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
1218// if p == 0 {
1219// panic("OOM")
1220// }
1221//
1222// *(*fts.FTSENT)(unsafe.Pointer(p)) = *newFtsent(t, info, path, stat, err)
1223// return p
1224// }
1225//
1226// func ftsentClose(t *TLS, p uintptr) {
1227// Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_path)
1228// Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_statp)
1229// }
1230
1231type ftstream struct {
1232 s []uintptr
1233 x int
1234}
1235
1236// func (f *ftstream) close(t *TLS) {
1237// for _, p := range f.s {
1238// ftsentClose(t, p)
1239// Xfree(t, p)
1240// }
1241// *f = ftstream{}
1242// }
1243//
1244// // FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
1245// func Xfts_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
1246// return Xfts64_open(t, path_argv, options, compar)
1247// }
1248
1249// FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
1250func Xfts64_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
1251 panic(todo(""))
1252 // f := &ftstream{}
1253 //
1254 // var walk func(string)
1255 // walk = func(path string) {
1256 // var fi os.FileInfo
1257 // var err error
1258 // switch {
1259 // case options&fts.FTS_LOGICAL != 0:
1260 // fi, err = os.Stat(path)
1261 // case options&fts.FTS_PHYSICAL != 0:
1262 // fi, err = os.Lstat(path)
1263 // default:
1264 // panic(todo(""))
1265 // }
1266 //
1267 // if err != nil {
1268 // panic(todo(""))
1269 // }
1270 //
1271 // var statp *unix.Stat_t
1272 // if options&fts.FTS_NOSTAT == 0 {
1273 // var stat unix.Stat_t
1274 // switch {
1275 // case options&fts.FTS_LOGICAL != 0:
1276 // if err := unix.Stat(path, &stat); err != nil {
1277 // panic(todo(""))
1278 // }
1279 // case options&fts.FTS_PHYSICAL != 0:
1280 // if err := unix.Lstat(path, &stat); err != nil {
1281 // panic(todo(""))
1282 // }
1283 // default:
1284 // panic(todo(""))
1285 // }
1286 //
1287 // statp = &stat
1288 // }
1289 //
1290 // out:
1291 // switch {
1292 // case fi.IsDir():
1293 // f.s = append(f.s, newCFtsent(t, fts.FTS_D, path, statp, 0))
1294 // g, err := os.Open(path)
1295 // switch x := err.(type) {
1296 // case nil:
1297 // // ok
1298 // case *os.PathError:
1299 // f.s = append(f.s, newCFtsent(t, fts.FTS_DNR, path, statp, errno.EACCES))
1300 // break out
1301 // default:
1302 // panic(todo("%q: %v %T", path, x, x))
1303 // }
1304 //
1305 // names, err := g.Readdirnames(-1)
1306 // g.Close()
1307 // if err != nil {
1308 // panic(todo(""))
1309 // }
1310 //
1311 // for _, name := range names {
1312 // walk(path + "/" + name)
1313 // if f == nil {
1314 // break out
1315 // }
1316 // }
1317 //
1318 // f.s = append(f.s, newCFtsent(t, fts.FTS_DP, path, statp, 0))
1319 // default:
1320 // info := fts.FTS_F
1321 // if fi.Mode()&os.ModeSymlink != 0 {
1322 // info = fts.FTS_SL
1323 // }
1324 // switch {
1325 // case statp != nil:
1326 // f.s = append(f.s, newCFtsent(t, info, path, statp, 0))
1327 // case options&fts.FTS_NOSTAT != 0:
1328 // f.s = append(f.s, newCFtsent(t, fts.FTS_NSOK, path, nil, 0))
1329 // default:
1330 // panic(todo(""))
1331 // }
1332 // }
1333 // }
1334 //
1335 // for {
1336 // p := *(*uintptr)(unsafe.Pointer(path_argv))
1337 // if p == 0 {
1338 // if f == nil {
1339 // return 0
1340 // }
1341 //
1342 // if compar != 0 {
1343 // panic(todo(""))
1344 // }
1345 //
1346 // return addObject(f)
1347 // }
1348 //
1349 // walk(GoString(p))
1350 // path_argv += unsafe.Sizeof(uintptr(0))
1351 // }
1352}
1353
1354// FTSENT *fts_read(FTS *ftsp);
1355func Xfts_read(t *TLS, ftsp uintptr) uintptr {
1356 return Xfts64_read(t, ftsp)
1357}
1358
1359// FTSENT *fts_read(FTS *ftsp);
1360func Xfts64_read(t *TLS, ftsp uintptr) uintptr {
1361 panic(todo(""))
1362 // f := winGetObject(ftsp).(*ftstream)
1363 // if f.x == len(f.s) {
1364 // t.setErrno(0)
1365 // return 0
1366 // }
1367 //
1368 // r := f.s[f.x]
1369 // if e := (*fts.FTSENT)(unsafe.Pointer(r)).Ffts_errno; e != 0 {
1370 // t.setErrno(e)
1371 // }
1372 // f.x++
1373 // return r
1374}
1375
1376// int fts_close(FTS *ftsp);
1377func Xfts_close(t *TLS, ftsp uintptr) int32 {
1378 return Xfts64_close(t, ftsp)
1379}
1380
1381// int fts_close(FTS *ftsp);
1382func Xfts64_close(t *TLS, ftsp uintptr) int32 {
1383 panic(todo(""))
1384 // winGetObject(ftsp).(*ftstream).close(t)
1385 // removeObject(ftsp)
1386 // return 0
1387}
1388
1389// void tzset (void);
1390func Xtzset(t *TLS) {
1391 //TODO
1392}
1393
1394var strerrorBuf [256]byte
1395
1396// char *strerror(int errnum);
1397func Xstrerror(t *TLS, errnum int32) uintptr {
1398 copy((*RawMem)(unsafe.Pointer(&strerrorBuf[0]))[:len(strerrorBuf):len(strerrorBuf)], fmt.Sprintf("errno %d\x00", errnum))
1399 return uintptr(unsafe.Pointer(&strerrorBuf[0]))
1400}
1401
1402// void *dlopen(const char *filename, int flags);
1403func Xdlopen(t *TLS, filename uintptr, flags int32) uintptr {
1404 panic(todo(""))
1405}
1406
1407// char *dlerror(void);
1408func Xdlerror(t *TLS) uintptr {
1409 panic(todo(""))
1410}
1411
1412// int dlclose(void *handle);
1413func Xdlclose(t *TLS, handle uintptr) int32 {
1414 panic(todo(""))
1415}
1416
1417// void *dlsym(void *handle, const char *symbol);
1418func Xdlsym(t *TLS, handle, symbol uintptr) uintptr {
1419 panic(todo(""))
1420}
1421
1422// void perror(const char *s);
1423func Xperror(t *TLS, s uintptr) {
1424 panic(todo(""))
1425}
1426
1427// int pclose(FILE *stream);
1428func Xpclose(t *TLS, stream uintptr) int32 {
1429 panic(todo(""))
1430}
1431
1432var gai_strerrorBuf [100]byte
1433
1434// const char *gai_strerror(int errcode);
1435func Xgai_strerror(t *TLS, errcode int32) uintptr {
1436 copy(gai_strerrorBuf[:], fmt.Sprintf("gai error %d\x00", errcode))
1437 return uintptr(unsafe.Pointer(&gai_strerrorBuf))
1438}
1439
1440// int tcgetattr(int fd, struct termios *termios_p);
1441func Xtcgetattr(t *TLS, fd int32, termios_p uintptr) int32 {
1442 panic(todo(""))
1443}
1444
1445// int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
1446func Xtcsetattr(t *TLS, fd, optional_actions int32, termios_p uintptr) int32 {
1447 panic(todo(""))
1448}
1449
1450// // speed_t cfgetospeed(const struct termios *termios_p);
1451// func Xcfgetospeed(t *TLS, termios_p uintptr) termios.Speed_t {
1452// panic(todo(""))
1453// }
1454
1455// int cfsetospeed(struct termios *termios_p, speed_t speed);
1456func Xcfsetospeed(t *TLS, termios_p uintptr, speed uint32) int32 {
1457 panic(todo(""))
1458}
1459
1460// int cfsetispeed(struct termios *termios_p, speed_t speed);
1461func Xcfsetispeed(t *TLS, termios_p uintptr, speed uint32) int32 {
1462 panic(todo(""))
1463}
1464
1465// pid_t fork(void);
1466func Xfork(t *TLS) int32 {
1467 t.setErrno(errno.ENOSYS)
1468 return -1
1469}
1470
1471// char *setlocale(int category, const char *locale);
1472func Xsetlocale(t *TLS, category int32, locale uintptr) uintptr {
1473 return 0 //TODO
1474}
1475
1476// // char *nl_langinfo(nl_item item);
1477// func Xnl_langinfo(t *TLS, item langinfo.Nl_item) uintptr {
1478// panic(todo(""))
1479// }
1480
1481// FILE *popen(const char *command, const char *type);
1482func Xpopen(t *TLS, command, type1 uintptr) uintptr {
1483 panic(todo(""))
1484}
1485
1486// char *realpath(const char *path, char *resolved_path);
1487func Xrealpath(t *TLS, path, resolved_path uintptr) uintptr {
1488 s, err := filepath.EvalSymlinks(GoString(path))
1489 if err != nil {
1490 if os.IsNotExist(err) {
1491 if dmesgs {
1492 dmesg("%v: %q: %v", origin(1), GoString(path), err)
1493 }
1494 t.setErrno(errno.ENOENT)
1495 return 0
1496 }
1497
1498 panic(todo("", err))
1499 }
1500
1501 if resolved_path == 0 {
1502 panic(todo(""))
1503 }
1504
1505 if len(s) >= limits.PATH_MAX {
1506 s = s[:limits.PATH_MAX-1]
1507 }
1508
1509 copy((*RawMem)(unsafe.Pointer(resolved_path))[:len(s):len(s)], s)
1510 (*RawMem)(unsafe.Pointer(resolved_path))[len(s)] = 0
1511 return resolved_path
1512}
1513
1514// struct tm *gmtime_r(const time_t *timep, struct tm *result);
1515func Xgmtime_r(t *TLS, timep, result uintptr) uintptr {
1516 panic(todo(""))
1517}
1518
1519// // char *inet_ntoa(struct in_addr in);
1520// func Xinet_ntoa(t *TLS, in1 in.In_addr) uintptr {
1521// panic(todo(""))
1522// }
1523
1524// func X__ccgo_in6addr_anyp(t *TLS) uintptr {
1525// return uintptr(unsafe.Pointer(&in6_addr_any))
1526// }
1527
1528func Xabort(t *TLS) {
1529 panic(todo(""))
1530 // if dmesgs {
1531 // dmesg("%v:\n%s", origin(1), debug.Stack())
1532 // }
1533 // p := Xmalloc(t, types.Size_t(unsafe.Sizeof(signal.Sigaction{})))
1534 // if p == 0 {
1535 // panic("OOM")
1536 // }
1537 //
1538 // *(*signal.Sigaction)(unsafe.Pointer(p)) = signal.Sigaction{
1539 // F__sigaction_handler: struct{ Fsa_handler signal.X__sighandler_t }{Fsa_handler: signal.SIG_DFL},
1540 // }
1541 // Xsigaction(t, signal.SIGABRT, p, 0)
1542 // Xfree(t, p)
1543 // unix.Kill(unix.Getpid(), syscall.Signal(signal.SIGABRT))
1544 // panic(todo("unrechable"))
1545}
1546
1547// int fflush(FILE *stream);
1548func Xfflush(t *TLS, stream uintptr) int32 {
1549 f, ok := winGetObject(stream).(*file)
1550 if !ok {
1551 t.setErrno(errno.EBADF)
1552 return -1
1553 }
1554 err := syscall.FlushFileBuffers(f.Handle)
1555 if err != nil {
1556 t.setErrno(err)
1557 return -1
1558 }
1559 return 0
1560}
1561
1562// size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
1563func Xfread(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
1564 f, ok := winGetObject(stream).(*file)
1565 if !ok {
1566 t.setErrno(errno.EBADF)
1567 return 0
1568 }
1569
1570 var sz = size * nmemb
1571 var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
1572 n, err := syscall.Read(f.Handle, obuf)
1573 if err != nil {
1574 f.setErr()
1575 return 0
1576 }
1577
1578 if dmesgs {
1579 // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
1580 dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
1581 }
1582
1583 return types.Size_t(n) / size
1584
1585}
1586
1587// size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
1588func Xfwrite(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
1589 if ptr == 0 || size == 0 {
1590 return 0
1591 }
1592
1593 f, ok := winGetObject(stream).(*file)
1594 if !ok {
1595 t.setErrno(errno.EBADF)
1596 return 0
1597 }
1598
1599 var sz = size * nmemb
1600 var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
1601 n, err := syscall.Write(f.Handle, obuf)
1602 if err != nil {
1603 f.setErr()
1604 return 0
1605 }
1606
1607 if dmesgs {
1608 // // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
1609 dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
1610 }
1611 return types.Size_t(n) / size
1612}
1613
1614// int fclose(FILE *stream);
1615func Xfclose(t *TLS, stream uintptr) int32 {
1616 f, ok := winGetObject(stream).(*file)
1617 if !ok {
1618 t.setErrno(errno.EBADF)
1619 return -1
1620 }
1621 return f.close(t)
1622}
1623
1624// int fputc(int c, FILE *stream);
1625func Xfputc(t *TLS, c int32, stream uintptr) int32 {
1626 f, ok := winGetObject(stream).(*file)
1627 if !ok {
1628 t.setErrno(errno.EBADF)
1629 return -1
1630 }
1631 if _, err := fwrite(f._fd, []byte{byte(c)}); err != nil {
1632 return -1
1633 }
1634 return int32(byte(c))
1635}
1636
1637// int fseek(FILE *stream, long offset, int whence);
1638func Xfseek(t *TLS, stream uintptr, offset long, whence int32) int32 {
1639 f, ok := winGetObject(stream).(*file)
1640 if !ok {
1641 t.setErrno(errno.EBADF)
1642 return -1
1643 }
1644 if n := Xlseek(t, f._fd, types.Off_t(offset), whence); n < 0 {
1645 if dmesgs {
1646 dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
1647 }
1648 f.setErr()
1649 return -1
1650 }
1651
1652 if dmesgs {
1653 dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
1654 }
1655 return 0
1656}
1657
1658// long ftell(FILE *stream);
1659func Xftell(t *TLS, stream uintptr) long {
1660 f, ok := winGetObject(stream).(*file)
1661 if !ok {
1662 t.setErrno(errno.EBADF)
1663 return -1
1664 }
1665
1666 n := Xlseek(t, f._fd, 0, syscall.FILE_CURRENT)
1667 if n < 0 {
1668 f.setErr()
1669 return -1
1670 }
1671
1672 if dmesgs {
1673 dmesg("%v: fd %v, n %#x: ok %#x", origin(1), f._fd, n, long(n))
1674 }
1675 return long(n)
1676}
1677
1678// int ferror(FILE *stream);
1679func Xferror(t *TLS, stream uintptr) int32 {
1680 f, ok := winGetObject(stream).(*file)
1681 if !ok {
1682 t.setErrno(errno.EBADF)
1683 return -1
1684 }
1685
1686 return Bool32(f.err())
1687}
1688
1689// int getc(FILE *stream);
1690func Xfgetc(t *TLS, stream uintptr) int32 {
1691 f, ok := winGetObject(stream).(*file)
1692 if !ok {
1693 t.setErrno(errno.EBADF)
1694 return stdio.EOF
1695 }
1696
1697 var buf [1]byte
1698 if n, _ := syscall.Read(f.Handle, buf[:]); n != 0 {
1699 return int32(buf[0])
1700 }
1701
1702 return stdio.EOF
1703}
1704
1705// int ungetc(int c, FILE *stream);
1706func Xungetc(t *TLS, c int32, stream uintptr) int32 {
1707 panic(todo(""))
1708}
1709
1710// int fscanf(FILE *stream, const char *format, ...);
1711func Xfscanf(t *TLS, stream, format, va uintptr) int32 {
1712 panic(todo(""))
1713}
1714
1715// int fputs(const char *s, FILE *stream);
1716func Xfputs(t *TLS, s, stream uintptr) int32 {
1717 f, ok := winGetObject(stream).(*file)
1718 if !ok {
1719 t.setErrno(errno.EBADF)
1720 return -1
1721 }
1722 gS := GoString(s)
1723 if _, err := fwrite(f._fd, []byte(gS)); err != nil {
1724 return -1
1725 }
1726 return 0
1727}
1728
1729// var getservbynameStaticResult netdb.Servent
1730//
1731// // struct servent *getservbyname(const char *name, const char *proto);
1732// func Xgetservbyname(t *TLS, name, proto uintptr) uintptr {
1733// var protoent *gonetdb.Protoent
1734// if proto != 0 {
1735// protoent = gonetdb.GetProtoByName(GoString(proto))
1736// }
1737// servent := gonetdb.GetServByName(GoString(name), protoent)
1738// if servent == nil {
1739// if dmesgs {
1740// dmesg("%q %q: nil (protoent %+v)", GoString(name), GoString(proto), protoent)
1741// }
1742// return 0
1743// }
1744//
1745// Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_name)
1746// if v := (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_aliases; v != 0 {
1747// for {
1748// p := *(*uintptr)(unsafe.Pointer(v))
1749// if p == 0 {
1750// break
1751// }
1752//
1753// Xfree(t, p)
1754// v += unsafe.Sizeof(uintptr(0))
1755// }
1756// Xfree(t, v)
1757// }
1758// Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_proto)
1759// cname, err := CString(servent.Name)
1760// if err != nil {
1761// getservbynameStaticResult = netdb.Servent{}
1762// return 0
1763// }
1764//
1765// var protoname uintptr
1766// if protoent != nil {
1767// if protoname, err = CString(protoent.Name); err != nil {
1768// Xfree(t, cname)
1769// getservbynameStaticResult = netdb.Servent{}
1770// return 0
1771// }
1772// }
1773// var a []uintptr
1774// for _, v := range servent.Aliases {
1775// cs, err := CString(v)
1776// if err != nil {
1777// for _, v := range a {
1778// Xfree(t, v)
1779// }
1780// return 0
1781// }
1782//
1783// a = append(a, cs)
1784// }
1785// v := Xcalloc(t, types.Size_t(len(a)+1), types.Size_t(unsafe.Sizeof(uintptr(0))))
1786// if v == 0 {
1787// Xfree(t, cname)
1788// Xfree(t, protoname)
1789// for _, v := range a {
1790// Xfree(t, v)
1791// }
1792// getservbynameStaticResult = netdb.Servent{}
1793// return 0
1794// }
1795// for _, p := range a {
1796// *(*uintptr)(unsafe.Pointer(v)) = p
1797// v += unsafe.Sizeof(uintptr(0))
1798// }
1799//
1800// getservbynameStaticResult = netdb.Servent{
1801// Fs_name: cname,
1802// Fs_aliases: v,
1803// Fs_port: int32(servent.Port),
1804// Fs_proto: protoname,
1805// }
1806// return uintptr(unsafe.Pointer(&getservbynameStaticResult))
1807// }
1808
1809// func Xreaddir64(t *TLS, dir uintptr) uintptr {
1810// return Xreaddir(t, dir)
1811// }
1812
1813// func fcntlCmdStr(cmd int32) string {
1814// switch cmd {
1815// case fcntl.F_GETOWN:
1816// return "F_GETOWN"
1817// case fcntl.F_SETLK:
1818// return "F_SETLK"
1819// case fcntl.F_GETLK:
1820// return "F_GETLK"
1821// case fcntl.F_SETFD:
1822// return "F_SETFD"
1823// case fcntl.F_GETFD:
1824// return "F_GETFD"
1825// default:
1826// return fmt.Sprintf("cmd(%d)", cmd)
1827// }
1828// }
1829
1830// _CRTIMP extern int *__cdecl _errno(void); // /usr/share/mingw-w64/include/errno.h:17:
1831func X_errno(t *TLS) uintptr {
1832 return t.errnop
1833}
1834
1835// int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
1836func X__ms_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
1837 panic(todo(""))
1838}
1839
1840// int vsscanf(const char *str, const char *format, va_list ap);
1841func X__ms_vsscanf(t *TLS, str, format, ap uintptr) int32 {
1842 panic(todo(""))
1843}
1844
1845// int vscanf(const char *format, va_list ap);
1846func X__ms_vscanf(t *TLS, format, ap uintptr) int32 {
1847 panic(todo(""))
1848}
1849
1850// int vsnprintf(char *str, size_t size, const char *format, va_list ap);
1851func X__ms_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
1852 return Xvsnprintf(t, str, size, format, ap)
1853}
1854
1855// int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
1856func X__ms_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
1857 panic(todo(""))
1858}
1859
1860// int vwscanf(const wchar_t * restrict format, va_list arg);
1861func X__ms_vwscanf(t *TLS, format, ap uintptr) int32 {
1862 panic(todo(""))
1863}
1864
1865// int _vsnwprintf(wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr);
1866func X_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, ap uintptr) int32 {
1867 panic(todo(""))
1868}
1869
1870// int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
1871func X__ms_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
1872 panic(todo(""))
1873}
1874
1875// __acrt_iob_func
1876func X__acrt_iob_func(t *TLS, fd uint32) uintptr {
1877
1878 f, ok := fdToFile(int32(fd))
1879 if !ok {
1880 t.setErrno(EBADF)
1881 return 0
1882 }
1883 return f.t
1884}
1885
1886// BOOL SetEvent(
1887//
1888// HANDLE hEvent
1889//
1890// );
1891func XSetEvent(t *TLS, hEvent uintptr) int32 {
1892 r0, _, err := syscall.Syscall(procSetEvent.Addr(), 1, hEvent, 0, 0)
1893 if r0 == 0 {
1894 t.setErrno(err)
1895 }
1896 return int32(r0)
1897}
1898
1899// int _stricmp(
1900//
1901// const char *string1,
1902// const char *string2
1903//
1904// );
1905func X_stricmp(t *TLS, string1, string2 uintptr) int32 {
1906 var s1 = strings.ToLower(GoString(string1))
1907 var s2 = strings.ToLower(GoString(string2))
1908 return int32(strings.Compare(s1, s2))
1909}
1910
1911// BOOL HeapFree(
1912//
1913// HANDLE hHeap,
1914// DWORD dwFlags,
1915// _Frees_ptr_opt_ LPVOID lpMem
1916//
1917// );
1918func XHeapFree(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
1919 r0, _, err := syscall.Syscall(procHeapFree.Addr(), 3, hHeap, uintptr(dwFlags), lpMem)
1920 if err != 0 {
1921 t.setErrno(err)
1922 }
1923 return int32(r0)
1924}
1925
1926// HANDLE GetProcessHeap();
1927func XGetProcessHeap(t *TLS) uintptr {
1928 r0, _, err := syscall.Syscall(procGetProcessHeap.Addr(), 0, 0, 0, 0)
1929 if r0 == 0 {
1930 t.setErrno(err)
1931 }
1932 return r0
1933}
1934
1935// LPVOID HeapAlloc(
1936//
1937// HANDLE hHeap,
1938// DWORD dwFlags,
1939// SIZE_T dwBytes
1940//
1941// );
1942func XHeapAlloc(t *TLS, hHeap uintptr, dwFlags uint32, dwBytes types.Size_t) uintptr {
1943 r0, _, err := syscall.Syscall(procHeapAlloc.Addr(), 3, hHeap, uintptr(dwFlags), uintptr(dwBytes))
1944 if r0 == 0 {
1945 t.setErrno(err)
1946 }
1947 return r0
1948}
1949
1950// WCHAR * gai_strerrorW(
1951//
1952// int ecode
1953//
1954// );
1955func Xgai_strerrorW(t *TLS, _ ...interface{}) uintptr {
1956 panic(todo(""))
1957}
1958
1959// servent * getservbyname(
1960//
1961// const char *name,
1962// const char *proto
1963//
1964// );
1965func Xgetservbyname(t *TLS, _ ...interface{}) uintptr {
1966 panic(todo(""))
1967}
1968
1969// INT WSAAPI getaddrinfo(
1970//
1971// PCSTR pNodeName,
1972// PCSTR pServiceName,
1973// const ADDRINFOA *pHints,
1974// PADDRINFOA *ppResult
1975//
1976// );
1977func XWspiapiGetAddrInfo(t *TLS, _ ...interface{}) int32 {
1978 panic(todo(""))
1979}
1980
1981// int wcscmp(
1982//
1983// const wchar_t *string1,
1984// const wchar_t *string2
1985//
1986// );
1987func Xwcscmp(t *TLS, string1, string2 uintptr) int32 {
1988 var s1 = goWideString(string1)
1989 var s2 = goWideString(string2)
1990 return int32(strings.Compare(s1, s2))
1991}
1992
1993// BOOL IsDebuggerPresent();
1994func XIsDebuggerPresent(t *TLS) int32 {
1995 panic(todo(""))
1996}
1997
1998func XExitProcess(t *TLS, _ ...interface{}) int32 {
1999 panic(todo(""))
2000}
2001
2002// BOOL GetVersionExW(
2003//
2004// LPOSVERSIONINFOW lpVersionInformation
2005//
2006// );
2007func XGetVersionExW(t *TLS, lpVersionInformation uintptr) int32 {
2008 r0, _, err := syscall.Syscall(procGetVersionExW.Addr(), 1, lpVersionInformation, 0, 0)
2009 if r0 == 0 {
2010 t.setErrno(err)
2011 }
2012 return int32(r0)
2013}
2014
2015// BOOL GetVolumeNameForVolumeMountPointW(
2016//
2017// LPCWSTR lpszVolumeMountPoint,
2018// LPWSTR lpszVolumeName,
2019// DWORD cchBufferLength
2020//
2021// );
2022func XGetVolumeNameForVolumeMountPointW(t *TLS, _ ...interface{}) int32 {
2023 panic(todo(""))
2024}
2025
2026// size_t wcslen(
2027//
2028// const wchar_t *str
2029//
2030// );
2031func Xwcslen(t *TLS, str uintptr) types.Size_t {
2032 r0, _, _ := syscall.Syscall(procLstrlenW.Addr(), 1, str, 0, 0)
2033 return types.Size_t(r0)
2034}
2035
2036// HANDLE WINAPI GetStdHandle(
2037//
2038// _In_ DWORD nStdHandle
2039//
2040// );
2041func XGetStdHandle(t *TLS, nStdHandle uint32) uintptr {
2042 h, err := syscall.GetStdHandle(int(nStdHandle))
2043 if err != nil {
2044 panic("no console")
2045 }
2046 return uintptr(h)
2047}
2048
2049// BOOL CloseHandle(
2050//
2051// HANDLE hObject
2052//
2053// );
2054func XCloseHandle(t *TLS, hObject uintptr) int32 {
2055 r := syscall.CloseHandle(syscall.Handle(hObject))
2056 if r != nil {
2057 return errno.EINVAL
2058 }
2059 return 1
2060}
2061
2062// DWORD GetLastError();
2063func XGetLastError(t *TLS) uint32 {
2064 var rv = *(*int32)(unsafe.Pointer(t.errnop))
2065 return uint32(rv)
2066
2067 //r1, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
2068 //return uint32(r1)
2069}
2070
2071// DWORD SetFilePointer(
2072//
2073// HANDLE hFile,
2074// LONG lDistanceToMove,
2075// PLONG lpDistanceToMoveHigh,
2076// DWORD dwMoveMethod
2077//
2078// );
2079func XSetFilePointer(t *TLS, hFile uintptr, lDistanceToMove long, lpDistanceToMoveHigh uintptr, dwMoveMethod uint32) uint32 {
2080 r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, hFile, uintptr(lDistanceToMove), lpDistanceToMoveHigh, uintptr(dwMoveMethod), 0, 0)
2081 var uOff = uint32(r0)
2082 if uOff == 0xffffffff {
2083 if e1 != 0 {
2084 t.setErrno(e1)
2085 } else {
2086 t.setErrno(errno.EINVAL)
2087 }
2088 }
2089 return uint32(r0)
2090}
2091
2092// BOOL SetEndOfFile(
2093//
2094// HANDLE hFile
2095//
2096// );
2097func XSetEndOfFile(t *TLS, hFile uintptr) int32 {
2098 err := syscall.SetEndOfFile(syscall.Handle(hFile))
2099 if err != nil {
2100 t.setErrno(err)
2101 return 0
2102 }
2103 return 1
2104}
2105
2106// BOOL ReadFile(
2107//
2108// HANDLE hFile,
2109// LPVOID lpBuffer,
2110// DWORD nNumberOfBytesToRead,
2111// LPDWORD lpNumberOfBytesRead,
2112// LPOVERLAPPED lpOverlapped
2113//
2114// );
2115func XReadFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToRead uint32, lpNumberOfBytesRead, lpOverlapped uintptr) int32 {
2116 r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5,
2117 hFile, lpBuffer, uintptr(nNumberOfBytesToRead), uintptr(lpNumberOfBytesRead), uintptr(lpOverlapped), 0)
2118 if r1 == 0 {
2119 if e1 != 0 {
2120 t.setErrno(e1)
2121 } else {
2122 t.setErrno(errno.EINVAL)
2123 }
2124 return 0
2125 }
2126 return int32(r1)
2127}
2128
2129// BOOL WriteFile(
2130//
2131// HANDLE hFile,
2132// LPCVOID lpBuffer,
2133// DWORD nNumberOfBytesToWrite,
2134// LPDWORD lpNumberOfBytesWritten,
2135// LPOVERLAPPED lpOverlapped
2136//
2137// );
2138func XWriteFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToWrite uint32, lpNumberOfBytesWritten, lpOverlapped uintptr) int32 {
2139 r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5,
2140 hFile, lpBuffer, uintptr(nNumberOfBytesToWrite), lpNumberOfBytesWritten, lpOverlapped, 0)
2141 if r1 == 0 {
2142 if e1 != 0 {
2143 t.setErrno(e1)
2144 } else {
2145 t.setErrno(errno.EINVAL)
2146 }
2147 return 0
2148 }
2149 return int32(r1)
2150}
2151
2152// DWORD GetFileAttributesW(
2153//
2154// LPCWSTR lpFileName
2155//
2156// );
2157func XGetFileAttributesW(t *TLS, lpFileName uintptr) uint32 {
2158 attrs, err := syscall.GetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)))
2159 if attrs == syscall.INVALID_FILE_ATTRIBUTES {
2160 if err != nil {
2161 t.setErrno(err)
2162 } else {
2163 t.setErrno(errno.EINVAL)
2164 }
2165 }
2166 return attrs
2167}
2168
2169// HANDLE CreateFileW(
2170//
2171// LPCWSTR lpFileName,
2172// DWORD dwDesiredAccess,
2173// DWORD dwShareMode,
2174// LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2175// DWORD dwCreationDisposition,
2176// DWORD dwFlagsAndAttributes,
2177// HANDLE hTemplateFile
2178//
2179// );
2180func XCreateFileW(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32, lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
2181
2182 r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
2183 uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
2184 h := syscall.Handle(r0)
2185 if h == syscall.InvalidHandle {
2186 if e1 != 0 {
2187 t.setErrno(e1)
2188 } else {
2189 t.setErrno(errno.EINVAL)
2190 }
2191 return r0
2192 }
2193 return uintptr(h)
2194}
2195
2196// BOOL DuplicateHandle(
2197//
2198// HANDLE hSourceProcessHandle,
2199// HANDLE hSourceHandle,
2200// HANDLE hTargetProcessHandle,
2201// LPHANDLE lpTargetHandle,
2202// DWORD dwDesiredAccess,
2203// BOOL bInheritHandle,
2204// DWORD dwOptions
2205//
2206// );
2207func XDuplicateHandle(t *TLS, hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle uintptr, dwDesiredAccess uint32, bInheritHandle int32, dwOptions uint32) int32 {
2208 r0, _, err := syscall.Syscall9(procDuplicateHandle.Addr(), 7, hSourceProcessHandle, hSourceHandle, hTargetProcessHandle,
2209 lpTargetHandle, uintptr(dwDesiredAccess), uintptr(bInheritHandle), uintptr(dwOptions), 0, 0)
2210 if r0 == 0 {
2211 t.setErrno(err)
2212 }
2213 return int32(r0)
2214}
2215
2216// HANDLE GetCurrentProcess();
2217func XGetCurrentProcess(t *TLS) uintptr {
2218 r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
2219 if r0 == 0 {
2220 if e1 != 0 {
2221 t.setErrno(e1)
2222 } else {
2223 t.setErrno(errno.EINVAL)
2224 }
2225 }
2226 return r0
2227}
2228
2229// BOOL FlushFileBuffers(
2230//
2231// HANDLE hFile
2232//
2233// );
2234func XFlushFileBuffers(t *TLS, hFile uintptr) int32 {
2235 err := syscall.FlushFileBuffers(syscall.Handle(hFile))
2236 if err != nil {
2237 t.setErrno(err)
2238 return -1
2239 }
2240 return 1
2241
2242}
2243
2244// DWORD GetFileType(
2245//
2246// HANDLE hFile
2247//
2248// );
2249func XGetFileType(t *TLS, hFile uintptr) uint32 {
2250 n, err := syscall.GetFileType(syscall.Handle(hFile))
2251 if err != nil {
2252 t.setErrno(err)
2253 }
2254 return n
2255}
2256
2257// BOOL WINAPI GetConsoleMode(
2258//
2259// _In_ HANDLE hConsoleHandle,
2260// _Out_ LPDWORD lpMode
2261//
2262// );
2263func XGetConsoleMode(t *TLS, hConsoleHandle, lpMode uintptr) int32 {
2264 err := syscall.GetConsoleMode(syscall.Handle(hConsoleHandle), (*uint32)(unsafe.Pointer(lpMode)))
2265 if err != nil {
2266 t.setErrno(err)
2267 return 0
2268 }
2269 return 1
2270}
2271
2272// BOOL GetCommState(
2273//
2274// HANDLE hFile,
2275// LPDCB lpDCB
2276//
2277// );
2278func XGetCommState(t *TLS, hFile, lpDCB uintptr) int32 {
2279 r1, _, err := syscall.Syscall(procGetCommState.Addr(), 2, hFile, lpDCB, 0)
2280 if r1 == 0 {
2281 t.setErrno(err)
2282 return 0
2283 }
2284 return int32(r1)
2285}
2286
2287// int _wcsnicmp(
2288//
2289// const wchar_t *string1,
2290// const wchar_t *string2,
2291// size_t count
2292//
2293// );
2294func X_wcsnicmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
2295
2296 var s1 = strings.ToLower(goWideString(string1))
2297 var l1 = len(s1)
2298 var s2 = strings.ToLower(goWideString(string2))
2299 var l2 = len(s2)
2300
2301 // shorter is lesser
2302 if l1 < l2 {
2303 return -1
2304 }
2305 if l2 > l1 {
2306 return 1
2307 }
2308
2309 // compare at most count
2310 var cmpLen = count
2311 if types.Size_t(l1) < cmpLen {
2312 cmpLen = types.Size_t(l1)
2313 }
2314 return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
2315}
2316
2317// BOOL WINAPI ReadConsole(
2318//
2319// _In_ HANDLE hConsoleInput,
2320// _Out_ LPVOID lpBuffer,
2321// _In_ DWORD nNumberOfCharsToRead,
2322// _Out_ LPDWORD lpNumberOfCharsRead,
2323// _In_opt_ LPVOID pInputControl
2324//
2325// );
2326func XReadConsoleW(t *TLS, hConsoleInput, lpBuffer uintptr, nNumberOfCharsToRead uint32, lpNumberOfCharsRead, pInputControl uintptr) int32 {
2327
2328 rv, _, err := syscall.Syscall6(procReadConsoleW.Addr(), 5, hConsoleInput,
2329 lpBuffer, uintptr(nNumberOfCharsToRead), lpNumberOfCharsRead, pInputControl, 0)
2330 if rv == 0 {
2331 t.setErrno(err)
2332 }
2333
2334 return int32(rv)
2335}
2336
2337// BOOL WINAPI WriteConsoleW(
2338//
2339// _In_ HANDLE hConsoleOutput,
2340// _In_ const VOID *lpBuffer,
2341// _In_ DWORD nNumberOfCharsToWrite,
2342// _Out_opt_ LPDWORD lpNumberOfCharsWritten,
2343// _Reserved_ LPVOID lpReserved
2344//
2345// );
2346func XWriteConsoleW(t *TLS, hConsoleOutput, lpBuffer uintptr, nNumberOfCharsToWrite uint32, lpNumberOfCharsWritten, lpReserved uintptr) int32 {
2347 rv, _, err := syscall.Syscall6(procWriteConsoleW.Addr(), 5, hConsoleOutput,
2348 lpBuffer, uintptr(nNumberOfCharsToWrite), lpNumberOfCharsWritten, lpReserved, 0)
2349 if rv == 0 {
2350 t.setErrno(err)
2351 }
2352 return int32(rv)
2353}
2354
2355// DWORD WaitForSingleObject(
2356//
2357// HANDLE hHandle,
2358// DWORD dwMilliseconds
2359//
2360// );
2361func XWaitForSingleObject(t *TLS, hHandle uintptr, dwMilliseconds uint32) uint32 {
2362 rv, err := syscall.WaitForSingleObject(syscall.Handle(hHandle), dwMilliseconds)
2363 if err != nil {
2364 t.setErrno(err)
2365 }
2366 return rv
2367}
2368
2369// BOOL ResetEvent(
2370//
2371// HANDLE hEvent
2372//
2373// );
2374func XResetEvent(t *TLS, hEvent uintptr) int32 {
2375 rv, _, err := syscall.Syscall(procResetEvent.Addr(), 1, hEvent, 0, 0)
2376 if rv == 0 {
2377 t.setErrno(err)
2378 }
2379 return int32(rv)
2380}
2381
2382// BOOL WINAPI PeekConsoleInput(
2383//
2384// _In_ HANDLE hConsoleInput,
2385// _Out_ PINPUT_RECORD lpBuffer,
2386// _In_ DWORD nLength,
2387// _Out_ LPDWORD lpNumberOfEventsRead
2388//
2389// );
2390func XPeekConsoleInputW(t *TLS, hConsoleInput, lpBuffer uintptr, nLength uint32, lpNumberOfEventsRead uintptr) int32 {
2391 r0, _, err := syscall.Syscall6(procPeekConsoleInputW.Addr(), 4, hConsoleInput, lpBuffer, uintptr(nLength), lpNumberOfEventsRead, 0, 0)
2392 if r0 == 0 {
2393 t.setErrno(err)
2394 }
2395 return int32(r0)
2396}
2397
2398// int WINAPIV wsprintfA(
2399//
2400// LPSTR ,
2401// LPCSTR ,
2402// ...
2403//
2404// );
2405func XwsprintfA(t *TLS, buf, format, args uintptr) int32 {
2406 return Xsprintf(t, buf, format, args)
2407}
2408
2409// UINT WINAPI GetConsoleCP(void);
2410func XGetConsoleCP(t *TLS) uint32 {
2411 r0, _, err := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0)
2412 if r0 == 0 {
2413 t.setErrno(err)
2414 }
2415 return uint32(r0)
2416}
2417
2418// UINT WINAPI SetConsoleCP(UNIT);
2419//func setConsoleCP(cp uint32) uint32 {
2420//
2421// r0, _, _ := syscall.Syscall(procSetConsoleCP.Addr(), 1, uintptr(cp), 0, 0)
2422// if r0 == 0 {
2423// panic("setcp failed")
2424// }
2425// return uint32(r0)
2426//}
2427
2428// HANDLE CreateEventW(
2429//
2430// LPSECURITY_ATTRIBUTES lpEventAttributes,
2431// BOOL bManualReset,
2432// BOOL bInitialState,
2433// LPCWSTR lpName
2434//
2435// );
2436func XCreateEventW(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
2437 r0, _, err := syscall.Syscall6(procCreateEventW.Addr(), 4, lpEventAttributes, uintptr(bManualReset),
2438 uintptr(bInitialState), lpName, 0, 0)
2439 if r0 == 0 {
2440 t.setErrno(err)
2441 }
2442 return r0
2443}
2444
2445type ThreadAdapter struct {
2446 token uintptr
2447 tls *TLS
2448 param uintptr
2449 threadFunc func(*TLS, uintptr) uint32
2450}
2451
2452func (ta *ThreadAdapter) run() uintptr {
2453 r := ta.threadFunc(ta.tls, ta.param)
2454 ta.tls.Close()
2455 removeObject(ta.token)
2456 return uintptr(r)
2457}
2458
2459func ThreadProc(p uintptr) uintptr {
2460 adp, ok := winGetObject(p).(*ThreadAdapter)
2461 if !ok {
2462 panic("invalid thread")
2463 }
2464 return adp.run()
2465}
2466
2467// HANDLE CreateThread(
2468//
2469// LPSECURITY_ATTRIBUTES lpThreadAttributes,
2470// SIZE_T dwStackSize,
2471// LPTHREAD_START_ROUTINE lpStartAddress,
2472// __drv_aliasesMem LPVOID lpParameter,
2473// DWORD dwCreationFlags,
2474// LPDWORD lpThreadId
2475//
2476// );
2477func XCreateThread(t *TLS, lpThreadAttributes uintptr, dwStackSize types.Size_t, lpStartAddress, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) uintptr {
2478 f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{lpStartAddress})).f
2479 var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: lpParameter}
2480 tAdp.token = addObject(&tAdp)
2481
2482 r0, _, err := syscall.Syscall6(procCreateThread.Addr(), 6, lpThreadAttributes, uintptr(dwStackSize),
2483 threadCallback, tAdp.token, uintptr(dwCreationFlags), lpThreadId)
2484 if r0 == 0 {
2485 t.setErrno(err)
2486 }
2487 return r0
2488}
2489
2490// BOOL SetThreadPriority(
2491//
2492// HANDLE hThread,
2493// int nPriority
2494//
2495// );
2496func XSetThreadPriority(t *TLS, hThread uintptr, nPriority int32) int32 {
2497
2498 //r0, _, err := syscall.Syscall(procSetThreadPriority.Addr(), 2, hThread, uintptr(nPriority), 0)
2499 //if r0 == 0 {
2500 // t.setErrno(err)
2501 //}
2502 //return int32(r0)
2503 return 1
2504}
2505
2506// BOOL WINAPI SetConsoleMode(
2507//
2508// _In_ HANDLE hConsoleHandle,
2509// _In_ DWORD dwMode
2510//
2511// );
2512func XSetConsoleMode(t *TLS, hConsoleHandle uintptr, dwMode uint32) int32 {
2513 rv, _, err := syscall.Syscall(procSetConsoleMode.Addr(), 2, hConsoleHandle, uintptr(dwMode), 0)
2514 if rv == 0 {
2515 t.setErrno(err)
2516 }
2517 return int32(rv)
2518}
2519
2520func XPurgeComm(t *TLS, _ ...interface{}) int32 {
2521 panic(todo(""))
2522}
2523
2524func XClearCommError(t *TLS, _ ...interface{}) int32 {
2525 panic(todo(""))
2526}
2527
2528// void DeleteCriticalSection(
2529//
2530// LPCRITICAL_SECTION lpCriticalSection
2531//
2532// );
2533func XDeleteCriticalSection(t *TLS, lpCriticalSection uintptr) {
2534 syscall.Syscall(procDeleteCriticalSection.Addr(), 1, lpCriticalSection, 0, 0)
2535}
2536
2537// void EnterCriticalSection(
2538//
2539// LPCRITICAL_SECTION lpCriticalSection
2540//
2541// );
2542func XEnterCriticalSection(t *TLS, lpCriticalSection uintptr) {
2543 syscall.Syscall(procEnterCriticalSection.Addr(), 1, lpCriticalSection, 0, 0)
2544}
2545
2546// void LeaveCriticalSection(
2547//
2548// LPCRITICAL_SECTION lpCriticalSection
2549//
2550// );
2551func XLeaveCriticalSection(t *TLS, lpCriticalSection uintptr) {
2552 syscall.Syscall(procLeaveCriticalSection.Addr(), 1, lpCriticalSection, 0, 0)
2553}
2554
2555func XGetOverlappedResult(t *TLS, _ ...interface{}) int32 {
2556 panic(todo(""))
2557}
2558
2559func XSetupComm(t *TLS, _ ...interface{}) int32 {
2560 panic(todo(""))
2561}
2562
2563func XSetCommTimeouts(t *TLS, _ ...interface{}) int32 {
2564 panic(todo(""))
2565}
2566
2567// void InitializeCriticalSection(
2568//
2569// LPCRITICAL_SECTION lpCriticalSection
2570//
2571// );
2572func XInitializeCriticalSection(t *TLS, lpCriticalSection uintptr) {
2573 // InitializeCriticalSection always succeeds, even in low memory situations.
2574 syscall.Syscall(procInitializeCriticalSection.Addr(), 1, lpCriticalSection, 0, 0)
2575}
2576
2577func XBuildCommDCBW(t *TLS, _ ...interface{}) int32 {
2578 panic(todo(""))
2579}
2580
2581func XSetCommState(t *TLS, _ ...interface{}) int32 {
2582 panic(todo(""))
2583}
2584
2585func X_strnicmp(t *TLS, _ ...interface{}) int32 {
2586 panic(todo(""))
2587}
2588
2589func XEscapeCommFunction(t *TLS, _ ...interface{}) int32 {
2590 panic(todo(""))
2591}
2592
2593func XGetCommModemStatus(t *TLS, _ ...interface{}) int32 {
2594 panic(todo(""))
2595}
2596
2597// BOOL MoveFileW(
2598//
2599// LPCWSTR lpExistingFileName,
2600// LPCWSTR lpNewFileName
2601//
2602// );
2603func XMoveFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr) int32 {
2604 r0, _, err := syscall.Syscall(procMoveFileW.Addr(), 2, lpExistingFileName, lpNewFileName, 0)
2605 if err != 0 {
2606 t.setErrno(err)
2607 }
2608 return int32(r0)
2609}
2610
2611// DWORD GetFullPathNameW(
2612//
2613// LPCWSTR lpFileName,
2614// DWORD nBufferLength,
2615// LPWSTR lpBuffer,
2616// LPWSTR *lpFilePart
2617//
2618// );
2619func XGetFullPathNameW(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
2620 r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, lpFileName, uintptr(nBufferLength), uintptr(lpBuffer), uintptr(lpFilePart), 0, 0)
2621 n := uint32(r0)
2622 if n == 0 {
2623 if e1 != 0 {
2624 t.setErrno(e1)
2625 } else {
2626 t.setErrno(errno.EINVAL)
2627 }
2628 }
2629 return n
2630}
2631
2632// LPWSTR CharLowerW(
2633//
2634// LPWSTR lpsz
2635//
2636// );
2637func XCharLowerW(t *TLS, lpsz uintptr) uintptr {
2638 panic(todo(""))
2639}
2640
2641// BOOL CreateDirectoryW(
2642//
2643// LPCWSTR lpPathName,
2644// LPSECURITY_ATTRIBUTES lpSecurityAttributes
2645//
2646// );
2647func XCreateDirectoryW(t *TLS, lpPathName, lpSecurityAttributes uintptr) int32 {
2648 err := syscall.CreateDirectory((*uint16)(unsafe.Pointer(lpPathName)),
2649 (*syscall.SecurityAttributes)(unsafe.Pointer(lpSecurityAttributes)))
2650 if err != nil {
2651 t.setErrno(err)
2652 return 0
2653 }
2654 return 1
2655}
2656
2657// BOOL SetFileAttributesW(
2658//
2659// LPCWSTR lpFileName,
2660// DWORD dwFileAttributes
2661//
2662// );
2663func XSetFileAttributesW(t *TLS, lpFileName uintptr, dwFileAttributes uint32) int32 {
2664 err := syscall.SetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)), dwFileAttributes)
2665 if err != nil {
2666 t.setErrno(err)
2667 return 0
2668 }
2669 return 1
2670}
2671
2672// UINT GetTempFileNameW(
2673//
2674// LPCWSTR lpPathName,
2675// LPCWSTR lpPrefixString,
2676// UINT uUnique,
2677// LPWSTR lpTempFileName
2678//
2679// );
2680func XGetTempFileNameW(t *TLS, lpPathName, lpPrefixString uintptr, uUnique uint32, lpTempFileName uintptr) uint32 {
2681 r0, _, e1 := syscall.Syscall6(procGetTempFileNameW.Addr(), 4, lpPathName, lpPrefixString, uintptr(uUnique), lpTempFileName, 0, 0)
2682 if r0 == 0 {
2683 t.setErrno(e1)
2684 }
2685 return uint32(r0)
2686}
2687
2688// BOOL CopyFileW(
2689//
2690// LPCWSTR lpExistingFileName,
2691// LPCWSTR lpNewFileName,
2692// BOOL bFailIfExists
2693//
2694// );
2695func XCopyFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr, bFailIfExists int32) int32 {
2696 r0, _, e1 := syscall.Syscall(procCopyFileW.Addr(), 3, lpExistingFileName, lpNewFileName, uintptr(bFailIfExists))
2697 if r0 == 0 {
2698 t.setErrno(e1)
2699 }
2700 return int32(r0)
2701}
2702
2703// BOOL DeleteFileW(
2704//
2705// LPCWSTR lpFileName
2706//
2707// );
2708func XDeleteFileW(t *TLS, lpFileName uintptr) int32 {
2709 err := syscall.DeleteFile((*uint16)(unsafe.Pointer(lpFileName)))
2710 if err != nil {
2711 t.setErrno(err)
2712 return 0
2713 }
2714 return 1
2715}
2716
2717// BOOL RemoveDirectoryW(
2718//
2719// LPCWSTR lpPathName
2720//
2721// );
2722func XRemoveDirectoryW(t *TLS, lpPathName uintptr) int32 {
2723 err := syscall.RemoveDirectory((*uint16)(unsafe.Pointer(lpPathName)))
2724 if err != nil {
2725 t.setErrno(err)
2726 return 0
2727 }
2728 return 1
2729}
2730
2731// HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
2732func XFindFirstFileW(t *TLS, lpFileName, lpFindFileData uintptr) uintptr {
2733 r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, lpFileName, lpFindFileData, 0)
2734 handle := syscall.Handle(r0)
2735 if handle == syscall.InvalidHandle {
2736 if e1 != 0 {
2737 t.setErrno(e1)
2738 } else {
2739 t.setErrno(errno.EINVAL)
2740 }
2741 }
2742 return r0
2743}
2744
2745// HANDLE FindFirstFileExW(
2746//
2747// LPCWSTR lpFileName,
2748// FINDEX_INFO_LEVELS fInfoLevelId,
2749// LPVOID lpFindFileData,
2750// FINDEX_SEARCH_OPS fSearchOp,
2751// LPVOID lpSearchFilter,
2752// DWORD dwAdditionalFlags
2753//
2754// );
2755func XFindFirstFileExW(t *TLS, lpFileName uintptr, fInfoLevelId int32, lpFindFileData uintptr, fSearchOp int32, lpSearchFilter uintptr, dwAdditionalFlags uint32) uintptr {
2756 r0, _, e1 := syscall.Syscall6(procFindFirstFileExW.Addr(), 6, lpFileName, uintptr(fInfoLevelId), lpFindFileData, uintptr(fSearchOp), lpSearchFilter, uintptr(dwAdditionalFlags))
2757 handle := syscall.Handle(r0)
2758 if handle == syscall.InvalidHandle {
2759 if e1 != 0 {
2760 t.setErrno(e1)
2761 } else {
2762 t.setErrno(errno.EINVAL)
2763 }
2764 }
2765 return r0
2766}
2767
2768// BOOL FindClose(HANDLE hFindFile);
2769func XFindClose(t *TLS, hFindFile uintptr) int32 {
2770 r0, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, hFindFile, 0, 0)
2771 if r0 == 0 {
2772 if e1 != 0 {
2773 t.setErrno(e1)
2774 } else {
2775 t.setErrno(errno.EINVAL)
2776 }
2777 }
2778 return int32(r0)
2779}
2780
2781// BOOL FindNextFileW(
2782//
2783// HANDLE hFindFile,
2784// LPWIN32_FIND_DATAW lpFindFileData
2785//
2786// );
2787func XFindNextFileW(t *TLS, hFindFile, lpFindFileData uintptr) int32 {
2788 r0, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, hFindFile, lpFindFileData, 0)
2789 if r0 == 0 {
2790 if e1 != 0 {
2791 t.setErrno(e1)
2792 } else {
2793 t.setErrno(errno.EINVAL)
2794 }
2795 }
2796 return int32(r0)
2797}
2798
2799// DWORD GetLogicalDriveStringsA(
2800//
2801// DWORD nBufferLength,
2802// LPSTR lpBuffer
2803//
2804// );
2805func XGetLogicalDriveStringsA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
2806 r0, _, err := syscall.Syscall(procGetLogicalDriveStringsA.Addr(), 2, uintptr(nBufferLength), lpBuffer, 0)
2807 if err != 0 {
2808 t.setErrno(err)
2809 }
2810 return uint32(r0)
2811}
2812
2813// BOOL GetVolumeInformationA(
2814//
2815// LPCSTR lpRootPathName,
2816// LPSTR lpVolumeNameBuffer,
2817// DWORD nVolumeNameSize,
2818// LPDWORD lpVolumeSerialNumber,
2819// LPDWORD lpMaximumComponentLength,
2820// LPDWORD lpFileSystemFlags,
2821// LPSTR lpFileSystemNameBuffer,
2822// DWORD nFileSystemNameSize
2823//
2824// );
2825func XGetVolumeInformationA(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
2826 r0, _, err := syscall.Syscall9(procGetVolumeInformationA.Addr(), 8,
2827 lpRootPathName,
2828 lpVolumeNameBuffer,
2829 uintptr(nVolumeNameSize),
2830 lpVolumeSerialNumber,
2831 lpMaximumComponentLength,
2832 lpFileSystemFlags,
2833 lpFileSystemNameBuffer,
2834 uintptr(nFileSystemNameSize),
2835 0,
2836 )
2837 if err != 0 {
2838 t.setErrno(err)
2839 }
2840 return int32(r0)
2841}
2842
2843// BOOL CreateHardLinkW(
2844//
2845// LPCWSTR lpFileName,
2846// LPCWSTR lpExistingFileName,
2847// LPSECURITY_ATTRIBUTES lpSecurityAttributes
2848//
2849// );
2850func XCreateHardLinkW(t *TLS, lpFileName, lpExistingFileName, lpSecurityAttributes uintptr) int32 {
2851 r0, _, err := syscall.Syscall(procCreateHardLinkW.Addr(), 1, lpFileName, lpExistingFileName, lpSecurityAttributes)
2852 if err != 0 {
2853 t.setErrno(err)
2854 }
2855 return int32(r0)
2856}
2857
2858// BOOL DeviceIoControl(
2859//
2860// HANDLE hDevice,
2861// DWORD dwIoControlCode,
2862// LPVOID lpInBuffer,
2863// DWORD nInBufferSize,
2864// LPVOID lpOutBuffer,
2865// DWORD nOutBufferSize,
2866// LPDWORD lpBytesReturned,
2867// LPOVERLAPPED lpOverlapped
2868//
2869// );
2870func XDeviceIoControl(t *TLS, hDevice uintptr, dwIoControlCode uint32, lpInBuffer uintptr, nInBufferSize uint32, lpOutBuffer uintptr, nOutBufferSize uint32, lpBytesReturned, lpOverlapped uintptr) int32 {
2871 r0, _, err := syscall.Syscall9(procDeviceIoControl.Addr(), 8, hDevice, uintptr(dwIoControlCode), lpInBuffer,
2872 uintptr(nInBufferSize), lpOutBuffer, uintptr(nOutBufferSize), lpBytesReturned, lpOverlapped, 0)
2873 if r0 == 0 {
2874 t.setErrno(err)
2875 }
2876 return int32(r0)
2877}
2878
2879// int wcsncmp(
2880//
2881// const wchar_t *string1,
2882// const wchar_t *string2,
2883// size_t count
2884//
2885// );
2886func Xwcsncmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
2887 var s1 = goWideString(string1)
2888 var l1 = len(s1)
2889 var s2 = goWideString(string2)
2890 var l2 = len(s2)
2891
2892 // shorter is lesser
2893 if l1 < l2 {
2894 return -1
2895 }
2896 if l2 > l1 {
2897 return 1
2898 }
2899
2900 // compare at most count
2901 var cmpLen = count
2902 if types.Size_t(l1) < cmpLen {
2903 cmpLen = types.Size_t(l1)
2904 }
2905 return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
2906}
2907
2908// int MultiByteToWideChar(
2909//
2910// UINT CodePage,
2911// DWORD dwFlags,
2912// _In_NLS_string_(cbMultiByte)LPCCH lpMultiByteStr,
2913// int cbMultiByte,
2914// LPWSTR lpWideCharStr,
2915// int cchWideChar
2916//
2917// );
2918func XMultiByteToWideChar(t *TLS, CodePage uint32, dwFlags uint32, lpMultiByteStr uintptr, cbMultiByte int32, lpWideCharStr uintptr, cchWideChar int32) int32 {
2919 r1, _, _ := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6,
2920 uintptr(CodePage), uintptr(dwFlags), uintptr(lpMultiByteStr),
2921 uintptr(cbMultiByte), uintptr(lpWideCharStr), uintptr(cchWideChar))
2922 return (int32(r1))
2923}
2924
2925// void OutputDebugStringW(
2926//
2927// LPCWSTR lpOutputString
2928//
2929// );
2930func XOutputDebugStringW(t *TLS, lpOutputString uintptr) {
2931 panic(todo(""))
2932}
2933
2934func XMessageBeep(t *TLS, _ ...interface{}) int32 {
2935 panic(todo(""))
2936}
2937
2938//====
2939
2940// long _InterlockedCompareExchange(
2941//
2942// long volatile * Destination,
2943// long Exchange,
2944// long Comparand
2945//
2946// );
2947func X_InterlockedCompareExchange(t *TLS, Destination uintptr, Exchange, Comparand long) long {
2948
2949 // The function returns the initial value of the Destination parameter.
2950 var v = *(*int32)(unsafe.Pointer(Destination))
2951 _ = atomic.CompareAndSwapInt32((*int32)(unsafe.Pointer(Destination)), Comparand, Exchange)
2952 return long(v)
2953}
2954
2955// int rename(const char *oldpath, const char *newpath);
2956func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
2957 panic(todo(""))
2958}
2959
2960// BOOL AreFileApisANSI();
2961func XAreFileApisANSI(t *TLS) int32 {
2962
2963 r0, _, _ := syscall.Syscall(procAreFileApisANSI.Addr(), 0, 0, 0, 0)
2964 return int32(r0)
2965}
2966
2967// HANDLE CreateFileA(
2968//
2969// LPCSTR lpFileName,
2970// DWORD dwDesiredAccess,
2971// DWORD dwShareMode,
2972// LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2973// DWORD dwCreationDisposition,
2974// DWORD dwFlagsAndAttributes,
2975// HANDLE hTemplateFile
2976//
2977// );
2978func XCreateFileA(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32,
2979 lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
2980
2981 r0, _, e1 := syscall.Syscall9(procCreateFileA.Addr(), 7, lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
2982 uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
2983 h := syscall.Handle(r0)
2984 if h == syscall.InvalidHandle {
2985 if e1 != 0 {
2986 t.setErrno(e1)
2987 } else {
2988 t.setErrno(errno.EINVAL)
2989 }
2990 return r0
2991 }
2992 return uintptr(h)
2993
2994}
2995
2996// HANDLE CreateFileMappingA(
2997//
2998// HANDLE hFile,
2999// LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
3000// DWORD flProtect,
3001// DWORD dwMaximumSizeHigh,
3002// DWORD dwMaximumSizeLow,
3003// LPCSTR lpName
3004//
3005// );
3006func XCreateFileMappingA(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
3007 panic(todo(""))
3008}
3009
3010// HANDLE CreateFileMappingW(
3011//
3012// HANDLE hFile,
3013// LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
3014// DWORD flProtect,
3015// DWORD dwMaximumSizeHigh,
3016// DWORD dwMaximumSizeLow,
3017// LPCWSTR lpName
3018//
3019// );
3020func XCreateFileMappingW(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
3021 h, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, hFile, lpFileMappingAttributes, uintptr(flProtect),
3022 uintptr(dwMaximumSizeHigh), uintptr(dwMaximumSizeLow), lpName)
3023 if h == 0 {
3024 if e1 != 0 {
3025 t.setErrno(e1)
3026 } else {
3027 t.setErrno(errno.EINVAL)
3028 }
3029 }
3030 return h
3031}
3032
3033// HANDLE CreateMutexW(
3034//
3035// LPSECURITY_ATTRIBUTES lpMutexAttributes,
3036// BOOL bInitialOwner,
3037// LPCWSTR lpName
3038//
3039// );
3040func XCreateMutexW(t *TLS, lpMutexAttributes uintptr, bInitialOwner int32, lpName uintptr) uintptr {
3041 panic(todo(""))
3042}
3043
3044// BOOL DeleteFileA(
3045//
3046// LPCSTR lpFileName
3047//
3048// );
3049func XDeleteFileA(t *TLS, lpFileName uintptr) int32 {
3050 panic(todo(""))
3051}
3052
3053// DWORD FormatMessageA(
3054//
3055// DWORD dwFlags,
3056// LPCVOID lpSource,
3057// DWORD dwMessageId,
3058// DWORD dwLanguageId,
3059// LPSTR lpBuffer,
3060// DWORD nSize,
3061// va_list *Arguments
3062//
3063// );
3064func XFormatMessageA(t *TLS, dwFlagsAndAttributes uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
3065 panic(todo(""))
3066}
3067
3068// DWORD FormatMessageW(
3069//
3070// DWORD dwFlags,
3071// LPCVOID lpSource,
3072// DWORD dwMessageId,
3073// DWORD dwLanguageId,
3074// LPWSTR lpBuffer,
3075// DWORD nSize,
3076// va_list *Arguments
3077//
3078// );
3079func XFormatMessageW(t *TLS, dwFlags uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
3080 r0, _, e1 := syscall.Syscall9(procFormatMessageW.Addr(), 7,
3081 uintptr(dwFlags), lpSource, uintptr(dwMessageId), uintptr(dwLanguageId),
3082 lpBuffer, uintptr(nSize), Arguments, 0, 0)
3083 n := uint32(r0)
3084 if n == 0 {
3085 if e1 != 0 {
3086 t.setErrno(e1)
3087 } else {
3088 t.setErrno(errno.EINVAL)
3089 }
3090 }
3091 return n
3092}
3093
3094// BOOL FreeLibrary(HMODULE hLibModule);
3095func XFreeLibrary(t *TLS, hLibModule uintptr) int32 {
3096 panic(todo(""))
3097}
3098
3099// DWORD GetCurrentProcessId();
3100func XGetCurrentProcessId(t *TLS) uint32 {
3101 r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
3102 pid := uint32(r0)
3103 return pid
3104}
3105
3106// BOOL GetDiskFreeSpaceA(
3107//
3108// LPCSTR lpRootPathName,
3109// LPDWORD lpSectorsPerCluster,
3110// LPDWORD lpBytesPerSector,
3111// LPDWORD lpNumberOfFreeClusters,
3112// LPDWORD lpTotalNumberOfClusters
3113//
3114// );
3115func XGetDiskFreeSpaceA(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
3116 panic(todo(""))
3117}
3118
3119// BOOL GetDiskFreeSpaceW(
3120//
3121// LPCWSTR lpRootPathName,
3122// LPDWORD lpSectorsPerCluster,
3123// LPDWORD lpBytesPerSector,
3124// LPDWORD lpNumberOfFreeClusters,
3125// LPDWORD lpTotalNumberOfClusters
3126//
3127// );
3128func XGetDiskFreeSpaceW(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
3129 panic(todo(""))
3130}
3131
3132// DWORD GetFileAttributesA(
3133//
3134// LPCSTR lpFileName
3135//
3136// );
3137func XGetFileAttributesA(t *TLS, lpFileName uintptr) uint32 {
3138 r0, _, err := syscall.Syscall(procGetFileAttributesA.Addr(), 1, lpFileName, 0, 0)
3139 if err != 0 {
3140 t.setErrno(err)
3141 }
3142 return uint32(r0)
3143}
3144
3145// BOOL GetFileAttributesExW(
3146//
3147// LPCWSTR lpFileName,
3148// GET_FILEEX_INFO_LEVELS fInfoLevelId,
3149// LPVOID lpFileInformation
3150//
3151// );
3152func XGetFileAttributesExW(t *TLS, lpFileName uintptr, fInfoLevelId uint32, lpFileInformation uintptr) int32 {
3153 r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, lpFileName, uintptr(fInfoLevelId), lpFileInformation)
3154 if r1 == 0 {
3155 if e1 != 0 {
3156 t.setErrno(e1)
3157 } else {
3158 t.setErrno(errno.EINVAL)
3159 }
3160 return 0
3161 }
3162 return int32(r1)
3163}
3164
3165// DWORD GetFileSize(
3166//
3167// HANDLE hFile,
3168// LPDWORD lpFileSizeHigh
3169//
3170// );
3171func XGetFileSize(t *TLS, hFile, lpFileSizeHigh uintptr) uint32 {
3172 r1, _, e1 := syscall.Syscall(procGetFileSize.Addr(), 2, hFile, lpFileSizeHigh, 0)
3173 if r1 == math.MaxUint32 {
3174 if lpFileSizeHigh == 0 {
3175 // If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE.
3176 // Note that if the return value is INVALID_FILE_SIZE (0xffffffff),
3177 // an application must call GetLastError to determine whether the function has succeeded or failed.
3178 t.setErrno(e1)
3179 return math.MaxUint32
3180 } else {
3181 // If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE
3182 // and GetLastError will return a value other than NO_ERROR.
3183 t.setErrno(e1)
3184 return math.MaxUint32
3185 }
3186 }
3187 return uint32(r1)
3188}
3189
3190// DWORD GetFullPathNameA(
3191//
3192// LPCSTR lpFileName,
3193// DWORD nBufferLength,
3194// LPSTR lpBuffer,
3195// LPSTR *lpFilePart
3196//
3197// );
3198func XGetFullPathNameA(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
3199 panic(todo(""))
3200}
3201
3202// FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
3203func XGetProcAddress(t *TLS, hModule, lpProcName uintptr) uintptr {
3204
3205 return 0
3206
3207 //panic(todo(GoString(lpProcName)))
3208 //
3209 //r0, _, err := syscall.Syscall(procGetProcAddress.Addr(), 2, hModule, lpProcName, 0)
3210 //if r0 == 0 {
3211 // t.setErrno(err)
3212 //}
3213 //return r0
3214}
3215
3216// NTSYSAPI NTSTATUS RtlGetVersion( // ntdll.dll
3217//
3218// PRTL_OSVERSIONINFOW lpVersionInformation
3219//
3220// );
3221func XRtlGetVersion(t *TLS, lpVersionInformation uintptr) uintptr {
3222 panic(todo(""))
3223}
3224
3225// void GetSystemInfo(
3226//
3227// LPSYSTEM_INFO lpSystemInfo
3228//
3229// );
3230func XGetSystemInfo(t *TLS, lpSystemInfo uintptr) {
3231 syscall.Syscall(procGetSystemInfo.Addr(), 1, lpSystemInfo, 0, 0)
3232}
3233
3234// void GetSystemTime(LPSYSTEMTIME lpSystemTime);
3235func XGetSystemTime(t *TLS, lpSystemTime uintptr) {
3236 syscall.Syscall(procGetSystemTime.Addr(), 1, lpSystemTime, 0, 0)
3237}
3238
3239// void GetSystemTimeAsFileTime(
3240//
3241// LPFILETIME lpSystemTimeAsFileTime
3242//
3243// );
3244func XGetSystemTimeAsFileTime(t *TLS, lpSystemTimeAsFileTime uintptr) {
3245 syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, lpSystemTimeAsFileTime, 0, 0)
3246}
3247
3248// DWORD GetTempPathA(
3249//
3250// DWORD nBufferLength,
3251// LPSTR lpBuffer
3252//
3253// );
3254func XGetTempPathA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
3255 panic(todo(""))
3256}
3257
3258// DWORD GetTempPathW(
3259//
3260// DWORD nBufferLength,
3261// LPWSTR lpBuffer
3262//
3263// );
3264func XGetTempPathW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
3265 rv, err := syscall.GetTempPath(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
3266 if err != nil {
3267 t.setErrno(err)
3268 }
3269 return rv
3270}
3271
3272// DWORD GetTickCount();
3273func XGetTickCount(t *TLS) uint32 {
3274 r0, _, _ := syscall.Syscall(procGetTickCount.Addr(), 0, 0, 0, 0)
3275 return uint32(r0)
3276}
3277
3278// BOOL GetVersionExA(
3279//
3280// LPOSVERSIONINFOA lpVersionInformation
3281//
3282// );
3283func XGetVersionExA(t *TLS, lpVersionInformation uintptr) int32 {
3284 r0, _, err := syscall.Syscall(procGetVersionExA.Addr(), 1, lpVersionInformation, 0, 0)
3285 if r0 == 0 {
3286 t.setErrno(err)
3287 }
3288 return int32(r0)
3289}
3290
3291// HANDLE HeapCreate(
3292//
3293// DWORD flOptions,
3294// SIZE_T dwInitialSize,
3295// SIZE_T dwMaximumSize
3296//
3297// );
3298func XHeapCreate(t *TLS, flOptions uint32, dwInitialSize, dwMaximumSize types.Size_t) uintptr {
3299 panic(todo(""))
3300}
3301
3302// BOOL HeapDestroy(
3303//
3304// HANDLE hHeap
3305//
3306// );
3307func XHeapDestroy(t *TLS, hHeap uintptr) int32 {
3308 panic(todo(""))
3309}
3310
3311// LPVOID HeapReAlloc(
3312//
3313// HANDLE hHeap,
3314// DWORD dwFlags,
3315// _Frees_ptr_opt_ LPVOID lpMem,
3316// SIZE_T dwBytes
3317//
3318// );
3319func XHeapReAlloc(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr, dwBytes types.Size_t) uintptr {
3320 panic(todo(""))
3321}
3322
3323// SIZE_T HeapSize(
3324//
3325// HANDLE hHeap,
3326// DWORD dwFlags,
3327// LPCVOID lpMem
3328//
3329// );
3330func XHeapSize(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) types.Size_t {
3331 panic(todo(""))
3332}
3333
3334// BOOL HeapValidate(
3335//
3336// HANDLE hHeap,
3337// DWORD dwFlags,
3338// LPCVOID lpMem
3339//
3340// );
3341func XHeapValidate(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
3342 panic(todo(""))
3343}
3344
3345// SIZE_T HeapCompact(
3346//
3347// HANDLE hHeap,
3348// DWORD dwFlags
3349//
3350// );
3351func XHeapCompact(t *TLS, hHeap uintptr, dwFlags uint32) types.Size_t {
3352 panic(todo(""))
3353}
3354
3355// HMODULE LoadLibraryA(LPCSTR lpLibFileName);
3356func XLoadLibraryA(t *TLS, lpLibFileName uintptr) uintptr {
3357 panic(todo(""))
3358}
3359
3360// HMODULE LoadLibraryW(
3361//
3362// LPCWSTR lpLibFileName
3363//
3364// );
3365func XLoadLibraryW(t *TLS, lpLibFileName uintptr) uintptr {
3366 panic(todo(""))
3367}
3368
3369// HLOCAL LocalFree(
3370//
3371// HLOCAL hMem
3372//
3373// );
3374func XLocalFree(t *TLS, hMem uintptr) uintptr {
3375 h, err := syscall.LocalFree(syscall.Handle(hMem))
3376 if h != 0 {
3377 if err != nil {
3378 t.setErrno(err)
3379 } else {
3380 t.setErrno(errno.EINVAL)
3381 }
3382 return uintptr(h)
3383 }
3384 return 0
3385}
3386
3387// BOOL LockFile(
3388//
3389// HANDLE hFile,
3390// DWORD dwFileOffsetLow,
3391// DWORD dwFileOffsetHigh,
3392// DWORD nNumberOfBytesToLockLow,
3393// DWORD nNumberOfBytesToLockHigh
3394//
3395// );
3396func XLockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32) int32 {
3397
3398 r1, _, e1 := syscall.Syscall6(procLockFile.Addr(), 5,
3399 hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), 0)
3400 if r1 == 0 {
3401 if e1 != 0 {
3402 t.setErrno(e1)
3403 } else {
3404 t.setErrno(errno.EINVAL)
3405 }
3406 return 0
3407 }
3408 return int32(r1)
3409
3410}
3411
3412// BOOL LockFileEx(
3413//
3414// HANDLE hFile,
3415// DWORD dwFlags,
3416// DWORD dwReserved,
3417// DWORD nNumberOfBytesToLockLow,
3418// DWORD nNumberOfBytesToLockHigh,
3419// LPOVERLAPPED lpOverlapped
3420//
3421// );
3422func XLockFileEx(t *TLS, hFile uintptr, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32, lpOverlapped uintptr) int32 {
3423 r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6,
3424 hFile, uintptr(dwFlags), uintptr(dwReserved), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), lpOverlapped)
3425 if r1 == 0 {
3426 if e1 != 0 {
3427 t.setErrno(e1)
3428 } else {
3429 t.setErrno(errno.EINVAL)
3430 }
3431 return 0
3432 }
3433 return int32(r1)
3434}
3435
3436// LPVOID MapViewOfFile(
3437//
3438// HANDLE hFileMappingObject,
3439// DWORD dwDesiredAccess,
3440// DWORD dwFileOffsetHigh,
3441// DWORD dwFileOffsetLow,
3442// SIZE_T dwNumberOfBytesToMap
3443//
3444// );
3445func XMapViewOfFile(t *TLS, hFileMappingObject uintptr, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow uint32, dwNumberOfBytesToMap types.Size_t) uintptr {
3446 h, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, hFileMappingObject, uintptr(dwDesiredAccess),
3447 uintptr(dwFileOffsetHigh), uintptr(dwFileOffsetLow), uintptr(dwNumberOfBytesToMap), 0)
3448 if h == 0 {
3449 if e1 != 0 {
3450 t.setErrno(e1)
3451 } else {
3452 t.setErrno(errno.EINVAL)
3453 }
3454 }
3455 return h
3456}
3457
3458// BOOL QueryPerformanceCounter(
3459//
3460// LARGE_INTEGER *lpPerformanceCount
3461//
3462// );
3463func XQueryPerformanceCounter(t *TLS, lpPerformanceCount uintptr) int32 {
3464 r0, _, _ := syscall.Syscall(procQueryPerformanceCounter.Addr(), 1, lpPerformanceCount, 0, 0)
3465 return int32(r0)
3466}
3467
3468// void Sleep(
3469//
3470// DWORD dwMilliseconds
3471//
3472// );
3473func XSleep(t *TLS, dwMilliseconds uint32) {
3474 gotime.Sleep(gotime.Duration(dwMilliseconds) * gotime.Millisecond)
3475}
3476
3477// BOOL SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime);
3478func XSystemTimeToFileTime(t *TLS, lpSystemTime, lpFileTime uintptr) int32 {
3479 r0, _, _ := syscall.Syscall(procSystemTimeToFileTime.Addr(), 2, lpSystemTime, lpFileTime, 0)
3480 return int32(r0)
3481}
3482
3483// BOOL UnlockFile(
3484//
3485// HANDLE hFile,
3486// DWORD dwFileOffsetLow,
3487// DWORD dwFileOffsetHigh,
3488// DWORD nNumberOfBytesToUnlockLow,
3489// DWORD nNumberOfBytesToUnlockHigh
3490//
3491// );
3492func XUnlockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32) int32 {
3493 r1, _, e1 := syscall.Syscall6(procUnlockFile.Addr(), 5,
3494 hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), 0)
3495 if r1 == 0 {
3496 if e1 != 0 {
3497 t.setErrno(e1)
3498 } else {
3499 t.setErrno(errno.EINVAL)
3500 }
3501 return 0
3502 }
3503 return int32(r1)
3504}
3505
3506// BOOL UnlockFileEx(
3507//
3508// HANDLE hFile,
3509// DWORD dwReserved,
3510// DWORD nNumberOfBytesToUnlockLow,
3511// DWORD nNumberOfBytesToUnlockHigh,
3512// LPOVERLAPPED lpOverlapped
3513//
3514// );
3515func XUnlockFileEx(t *TLS, hFile uintptr, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32, lpOverlapped uintptr) int32 {
3516 r1, _, e1 := syscall.Syscall6(procUnlockFileEx.Addr(), 5,
3517 hFile, uintptr(dwReserved), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), lpOverlapped, 0)
3518 if r1 == 0 {
3519 if e1 != 0 {
3520 t.setErrno(e1)
3521 } else {
3522 t.setErrno(errno.EINVAL)
3523 }
3524 return 0
3525 }
3526 return int32(r1)
3527}
3528
3529// BOOL UnmapViewOfFile(
3530//
3531// LPCVOID lpBaseAddress
3532//
3533// );
3534func XUnmapViewOfFile(t *TLS, lpBaseAddress uintptr) int32 {
3535 err := syscall.UnmapViewOfFile(lpBaseAddress)
3536 if err != nil {
3537 t.setErrno(err)
3538 return 0
3539 }
3540 return 1
3541}
3542
3543// int WideCharToMultiByte(
3544//
3545// UINT CodePage,
3546// DWORD dwFlags,
3547// _In_NLS_string_(cchWideChar)LPCWCH lpWideCharStr,
3548// int cchWideChar,
3549// LPSTR lpMultiByteStr,
3550// int cbMultiByte,
3551// LPCCH lpDefaultChar,
3552// LPBOOL lpUsedDefaultChar
3553//
3554// );
3555func XWideCharToMultiByte(t *TLS, CodePage uint32, dwFlags uint32, lpWideCharStr uintptr, cchWideChar int32, lpMultiByteStr uintptr, cbMultiByte int32, lpDefaultChar, lpUsedDefaultChar uintptr) int32 {
3556 r1, _, _ := syscall.Syscall9(procWideCharToMultiByte.Addr(), 8,
3557 uintptr(CodePage), uintptr(dwFlags), lpWideCharStr,
3558 uintptr(cchWideChar), lpMultiByteStr, uintptr(cbMultiByte),
3559 lpDefaultChar, lpUsedDefaultChar, 0)
3560 return (int32(r1))
3561}
3562
3563// void OutputDebugStringA(
3564//
3565// LPCSTR lpOutputString
3566//
3567// )
3568func XOutputDebugStringA(t *TLS, lpOutputString uintptr) {
3569 panic(todo(""))
3570}
3571
3572// BOOL FlushViewOfFile(
3573//
3574// LPCVOID lpBaseAddress,
3575// SIZE_T dwNumberOfBytesToFlush
3576//
3577// );
3578func XFlushViewOfFile(t *TLS, lpBaseAddress uintptr, dwNumberOfBytesToFlush types.Size_t) int32 {
3579 err := syscall.FlushViewOfFile(lpBaseAddress, uintptr(dwNumberOfBytesToFlush))
3580 if err != nil {
3581 t.setErrno(err)
3582 return 0
3583 }
3584 return 1
3585}
3586
3587type _ino_t = uint16 /* types.h:43:24 */
3588type _dev_t = uint32 /* types.h:51:22 */
3589type _stat64 = struct {
3590 Fst_dev _dev_t
3591 Fst_ino _ino_t
3592 Fst_mode uint16
3593 Fst_nlink int16
3594 Fst_uid int16
3595 Fst_gid int16
3596 _ [2]byte
3597 Fst_rdev _dev_t
3598 _ [4]byte
3599 Fst_size int64
3600 Fst_atime int64
3601 Fst_mtime int64
3602 Fst_ctime int64
3603} /* _mingw_stat64.h:83:3 */
3604
3605var (
3606 Windows_Tick int64 = 10000000
3607 SecToUnixEpoch int64 = 11644473600
3608)
3609
3610func WindowsTickToUnixSeconds(windowsTicks int64) int64 {
3611 return (windowsTicks/Windows_Tick - SecToUnixEpoch)
3612}
3613
3614// int _stat64(const char *path, struct __stat64 *buffer);
3615func X_stat64(t *TLS, path, buffer uintptr) int32 {
3616
3617 var fa syscall.Win32FileAttributeData
3618 r1, _, e1 := syscall.Syscall(procGetFileAttributesExA.Addr(), 3, path, syscall.GetFileExInfoStandard, (uintptr)(unsafe.Pointer(&fa)))
3619 if r1 == 0 {
3620 if e1 != 0 {
3621 t.setErrno(e1)
3622 } else {
3623 t.setErrno(errno.EINVAL)
3624 }
3625 return -1
3626 }
3627
3628 var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
3629 var accessTime = int64(fa.LastAccessTime.HighDateTime)<<32 + int64(fa.LastAccessTime.LowDateTime)
3630 bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
3631 var modTime = int64(fa.LastWriteTime.HighDateTime)<<32 + int64(fa.LastWriteTime.LowDateTime)
3632 bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
3633 var crTime = int64(fa.CreationTime.HighDateTime)<<32 + int64(fa.CreationTime.LowDateTime)
3634 bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
3635 var fSz = int64(fa.FileSizeHigh)<<32 + int64(fa.FileSizeLow)
3636 bStat64.Fst_size = fSz
3637 bStat64.Fst_mode = WindowsAttrbiutesToStat(fa.FileAttributes)
3638
3639 return 0
3640}
3641
3642func WindowsAttrbiutesToStat(fa uint32) uint16 {
3643 var src_mode = fa & 0xff
3644 var st_mode uint16
3645 if (src_mode & syscall.FILE_ATTRIBUTE_DIRECTORY) != 0 {
3646 st_mode = syscall.S_IFDIR
3647 } else {
3648 st_mode = syscall.S_IFREG
3649 }
3650
3651 if src_mode&syscall.FILE_ATTRIBUTE_READONLY != 0 {
3652 st_mode = st_mode | syscall.S_IRUSR
3653 } else {
3654 st_mode = st_mode | syscall.S_IRUSR | syscall.S_IWUSR
3655 }
3656 // fill group fields
3657 st_mode = st_mode | (st_mode&0x700)>>3
3658 st_mode = st_mode | (st_mode&0x700)>>6
3659 return st_mode
3660}
3661
3662// int _chsize(
3663//
3664// int fd,
3665// long size
3666//
3667// );
3668func X_chsize(t *TLS, fd int32, size long) int32 {
3669
3670 f, ok := fdToFile(fd)
3671 if !ok {
3672 t.setErrno(EBADF)
3673 return -1
3674 }
3675
3676 err := syscall.Ftruncate(f.Handle, int64(size))
3677 if err != nil {
3678 t.setErrno(err)
3679 return -1
3680 }
3681
3682 return 0
3683}
3684
3685// int _snprintf(char *str, size_t size, const char *format, ...);
3686func X_snprintf(t *TLS, str uintptr, size types.Size_t, format, args uintptr) int32 {
3687 return Xsnprintf(t, str, size, format, args)
3688}
3689
3690const wErr_ERROR_INSUFFICIENT_BUFFER = 122
3691
3692func win32FindDataToFileInfo(t *TLS, fdata *stat.X_finddata64i32_t, wfd *syscall.Win32finddata) int32 {
3693 // t64 = 64-bit time value
3694 var accessTime = int64(wfd.LastAccessTime.HighDateTime)<<32 + int64(wfd.LastAccessTime.LowDateTime)
3695 fdata.Ftime_access = WindowsTickToUnixSeconds(accessTime)
3696 var modTime = int64(wfd.LastWriteTime.HighDateTime)<<32 + int64(wfd.LastWriteTime.LowDateTime)
3697 fdata.Ftime_write = WindowsTickToUnixSeconds(modTime)
3698 var crTime = int64(wfd.CreationTime.HighDateTime)<<32 + int64(wfd.CreationTime.LowDateTime)
3699 fdata.Ftime_create = WindowsTickToUnixSeconds(crTime)
3700 // i32 = 32-bit size
3701 fdata.Fsize = wfd.FileSizeLow
3702 fdata.Fattrib = wfd.FileAttributes
3703
3704 var cp = XGetConsoleCP(t)
3705 var wcFn = (uintptr)(unsafe.Pointer(&wfd.FileName[0]))
3706 var mbcsFn = (uintptr)(unsafe.Pointer(&fdata.Fname[0]))
3707 rv := XWideCharToMultiByte(t, cp, 0, wcFn, -1, mbcsFn, 260, 0, 0)
3708 if rv == wErr_ERROR_INSUFFICIENT_BUFFER {
3709 t.setErrno(errno.ENOMEM)
3710 return -1
3711 }
3712 return 0
3713}
3714
3715// intptr_t _findfirst64i32(
3716//
3717// const char *filespec,
3718// struct _finddata64i32_t *fileinfo
3719//
3720// );
3721func X_findfirst64i32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
3722
3723 // Note: this is the 'narrow' character findfirst -- expects output
3724 // as mbcs -- conversion below -- via ToFileInfo
3725
3726 var gsFileSpec = GoString(filespec)
3727 namep, err := syscall.UTF16PtrFromString(gsFileSpec)
3728 if err != nil {
3729 t.setErrno(err)
3730 return types.Intptr_t(-1)
3731 }
3732
3733 var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
3734 var wfd syscall.Win32finddata
3735 h, err := syscall.FindFirstFile((*uint16)(unsafe.Pointer(namep)), &wfd)
3736 if err != nil {
3737 t.setErrno(err)
3738 return types.Intptr_t(-1)
3739 }
3740 rv := win32FindDataToFileInfo(t, fdata, &wfd)
3741 if rv != 0 {
3742 if h != 0 {
3743 syscall.FindClose(h)
3744 }
3745 return types.Intptr_t(-1)
3746 }
3747 return types.Intptr_t(h)
3748}
3749
3750// int _findnext64i32(
3751//
3752// intptr_t handle,
3753// struct _finddata64i32_t *fileinfo
3754//
3755// );
3756func X_findnext64i32(t *TLS, handle types.Intptr_t, fileinfo uintptr) int32 {
3757
3758 var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
3759 var wfd syscall.Win32finddata
3760
3761 err := syscall.FindNextFile(syscall.Handle(handle), &wfd)
3762 if err != nil {
3763 t.setErrno(err)
3764 return -1
3765 }
3766
3767 rv := win32FindDataToFileInfo(t, fdata, &wfd)
3768 if rv != 0 {
3769 return -1
3770 }
3771 return 0
3772}
3773
3774// int _findclose(
3775//
3776// intptr_t handle
3777//
3778// );
3779func X_findclose(t *TLS, handle types.Intptr_t) int32 {
3780
3781 err := syscall.FindClose(syscall.Handle(handle))
3782 if err != nil {
3783 t.setErrno(err)
3784 return -1
3785 }
3786 return 0
3787}
3788
3789// DWORD GetEnvironmentVariableA(
3790//
3791// LPCSTR lpName,
3792// LPSTR lpBuffer,
3793// DWORD nSize
3794//
3795// );
3796func XGetEnvironmentVariableA(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
3797 r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableA.Addr(), 3, lpName, lpBuffer, uintptr(nSize))
3798 n := uint32(r0)
3799 if n == 0 {
3800 if e1 != 0 {
3801 t.setErrno(e1)
3802 } else {
3803 t.setErrno(errno.EINVAL)
3804 }
3805 }
3806 return n
3807}
3808
3809// int _fstat64(
3810//
3811// int fd,
3812// struct __stat64 *buffer
3813//
3814// );
3815func X_fstat64(t *TLS, fd int32, buffer uintptr) int32 {
3816
3817 f, ok := fdToFile(fd)
3818 if !ok {
3819 t.setErrno(EBADF)
3820 return -1
3821 }
3822
3823 var d syscall.ByHandleFileInformation
3824 err := syscall.GetFileInformationByHandle(f.Handle, &d)
3825 if err != nil {
3826 t.setErrno(EBADF)
3827 return -1
3828 }
3829
3830 var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
3831 var accessTime = int64(d.LastAccessTime.HighDateTime)<<32 + int64(d.LastAccessTime.LowDateTime)
3832 bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
3833 var modTime = int64(d.LastWriteTime.HighDateTime)<<32 + int64(d.LastWriteTime.LowDateTime)
3834 bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
3835 var crTime = int64(d.CreationTime.HighDateTime)<<32 + int64(d.CreationTime.LowDateTime)
3836 bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
3837 var fSz = int64(d.FileSizeHigh)<<32 + int64(d.FileSizeLow)
3838 bStat64.Fst_size = fSz
3839 bStat64.Fst_mode = WindowsAttrbiutesToStat(d.FileAttributes)
3840
3841 return 0
3842}
3843
3844// HANDLE CreateEventA(
3845//
3846// LPSECURITY_ATTRIBUTES lpEventAttributes,
3847// BOOL bManualReset,
3848// BOOL bInitialState,
3849// LPCSTR lpName
3850//
3851// );
3852func XCreateEventA(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
3853 r0, _, err := syscall.Syscall6(procCreateEventA.Addr(), 4, lpEventAttributes, uintptr(bManualReset),
3854 uintptr(bInitialState), lpName, 0, 0)
3855 if r0 == 0 {
3856 t.setErrno(err)
3857 }
3858 return r0
3859}
3860
3861// BOOL WINAPI CancelSynchronousIo(
3862//
3863// _In_ HANDLE hThread
3864//
3865// );
3866func XCancelSynchronousIo(t *TLS, hThread uintptr) int32 {
3867 panic(todo(""))
3868}
3869
3870func X_endthreadex(t *TLS, _ ...interface{}) {
3871 // NOOP
3872}
3873
3874// The calling convention for beginthread is cdecl -- but in this
3875// case we're just intercepting it and sending it through CreateThread which expects stdcall
3876// and gets that via the go callback. This is safe because the thread is calling into go
3877// not a cdecl function which would expect the stack setup of cdecl.
3878func X_beginthread(t *TLS, procAddr uintptr, stack_sz uint32, args uintptr) int32 {
3879 f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
3880 var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
3881 tAdp.token = addObject(&tAdp)
3882
3883 r0, _, err := syscall.Syscall6(procCreateThread.Addr(), 6, 0, uintptr(stack_sz),
3884 threadCallback, tAdp.token, 0, 0)
3885 if r0 == 0 {
3886 t.setErrno(err)
3887 }
3888 return int32(r0)
3889}
3890
3891// uintptr_t _beginthreadex( // NATIVE CODE
3892//
3893// void *security,
3894// unsigned stack_size,
3895// unsigned ( __stdcall *start_address )( void * ),
3896// void *arglist,
3897// unsigned initflag,
3898// unsigned *thrdaddr
3899//
3900// );
3901func X_beginthreadex(t *TLS, _ uintptr, stack_sz uint32, procAddr uintptr, args uintptr, initf uint32, thAddr uintptr) int32 {
3902 f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
3903 var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
3904 tAdp.token = addObject(&tAdp)
3905
3906 r0, _, err := syscall.Syscall6(procCreateThread.Addr(), 6, 0, uintptr(stack_sz),
3907 threadCallback, tAdp.token, uintptr(initf), thAddr)
3908 if r0 == 0 {
3909 t.setErrno(err)
3910 }
3911 return int32(r0)
3912}
3913
3914// DWORD GetCurrentThreadId();
3915func XGetCurrentThreadId(t *TLS) uint32 {
3916 r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
3917 return uint32(r0)
3918 //return uint32(t.ID)
3919}
3920
3921// BOOL GetExitCodeThread(
3922//
3923// HANDLE hThread,
3924// LPDWORD lpExitCode
3925//
3926// );
3927func XGetExitCodeThread(t *TLS, hThread, lpExitCode uintptr) int32 {
3928 r0, _, _ := syscall.Syscall(procGetExitCodeThread.Addr(), 2, hThread, lpExitCode, 0)
3929 return int32(r0)
3930}
3931
3932// DWORD WaitForSingleObjectEx(
3933//
3934// HANDLE hHandle,
3935// DWORD dwMilliseconds,
3936// BOOL bAlertable
3937//
3938// );
3939func XWaitForSingleObjectEx(t *TLS, hHandle uintptr, dwMilliseconds uint32, bAlertable int32) uint32 {
3940 rv, _, _ := syscall.Syscall(procWaitForSingleObjectEx.Addr(), 3, hHandle, uintptr(dwMilliseconds), uintptr(bAlertable))
3941 return uint32(rv)
3942}
3943
3944// DWORD MsgWaitForMultipleObjectsEx(
3945//
3946// DWORD nCount,
3947// const HANDLE *pHandles,
3948// DWORD dwMilliseconds,
3949// DWORD dwWakeMask,
3950// DWORD dwFlags
3951//
3952// );
3953func XMsgWaitForMultipleObjectsEx(t *TLS, nCount uint32, pHandles uintptr, dwMilliseconds, dwWakeMask, dwFlags uint32) uint32 {
3954 r0, _, err := syscall.Syscall6(procMsgWaitForMultipleObjectsEx.Addr(), 5,
3955 uintptr(nCount),
3956 pHandles,
3957 uintptr(dwMilliseconds),
3958 uintptr(dwWakeMask),
3959 uintptr(dwFlags),
3960 0,
3961 )
3962 if err != 0 {
3963 t.setErrno(err)
3964 }
3965 return uint32(r0)
3966}
3967
3968func XMessageBoxW(t *TLS, _ ...interface{}) int32 {
3969 panic(todo(""))
3970}
3971
3972// DWORD GetModuleFileNameW(
3973//
3974// HMODULE hModule,
3975// LPWSTR lpFileName,
3976// DWORD nSize
3977//
3978// );
3979func XGetModuleFileNameW(t *TLS, hModule, lpFileName uintptr, nSize uint32) uint32 {
3980 r0, _, err := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, hModule, lpFileName, uintptr(nSize))
3981 if r0 == 0 {
3982 t.setErrno(err)
3983 }
3984 return uint32(r0)
3985}
3986
3987// NET_API_STATUS NET_API_FUNCTION NetGetDCName(
3988//
3989// LPCWSTR ServerName,
3990// LPCWSTR DomainName,
3991// LPBYTE *Buffer
3992//
3993// );
3994func XNetGetDCName(t *TLS, ServerName, DomainName, Buffer uintptr) int32 {
3995 r0, _, err := syscall.Syscall(procNetGetDCName.Addr(), 3, ServerName, DomainName, Buffer)
3996 if err != 0 {
3997 t.setErrno(err)
3998 }
3999 return int32(r0)
4000}
4001
4002// NET_API_STATUS NET_API_FUNCTION NetUserGetInfo(
4003//
4004// LPCWSTR servername,
4005// LPCWSTR username,
4006// DWORD level,
4007// LPBYTE *bufptr
4008//
4009// );
4010func XNetUserGetInfo(t *TLS, servername, username uintptr, level uint32, bufptr uintptr) uint32 {
4011 r0, _, err := syscall.Syscall6(procNetUserGetInfo.Addr(), 4,
4012 servername,
4013 username,
4014 uintptr(level),
4015 bufptr,
4016 0,
4017 0,
4018 )
4019 if err != 0 {
4020 t.setErrno(err)
4021 }
4022 return uint32(r0)
4023}
4024
4025func XlstrlenW(t *TLS, _ ...interface{}) int32 {
4026 panic(todo(""))
4027}
4028
4029// USERENVAPI BOOL GetProfilesDirectoryW(
4030//
4031// [out] LPWSTR lpProfileDir,
4032// [in, out] LPDWORD lpcchSize
4033//
4034// );
4035func XGetProfilesDirectoryW(t *TLS, lpProfileDir, lpcchSize uintptr) int32 {
4036 r0, _, err := syscall.Syscall(procGetProfilesDirectoryW.Addr(), 2, lpProfileDir, lpcchSize, 0)
4037 if err != 0 {
4038 t.setErrno(err)
4039 }
4040 return int32(r0)
4041}
4042
4043func XNetApiBufferFree(t *TLS, _ ...interface{}) int32 {
4044 panic(todo(""))
4045}
4046
4047// DWORD GetPrivateProfileStringA(
4048//
4049// LPCSTR lpAppName,
4050// LPCSTR lpKeyName,
4051// LPCSTR lpDefault,
4052// LPSTR lpReturnedString,
4053// DWORD nSize,
4054// LPCSTR lpFileName
4055//
4056// );
4057func XGetPrivateProfileStringA(t *TLS, lpAppName, lpKeyName, lpDefault, lpReturnedString uintptr, nSize uint32, lpFileName uintptr) uint32 {
4058 r0, _, err := syscall.Syscall6(procGetPrivateProfileStringA.Addr(), 4,
4059 lpAppName,
4060 lpKeyName,
4061 lpDefault,
4062 lpReturnedString,
4063 uintptr(nSize),
4064 lpFileName,
4065 )
4066 if err != 0 {
4067 t.setErrno(0x02)
4068 }
4069 return uint32(r0)
4070}
4071
4072func XGetWindowsDirectoryA(t *TLS, _ ...interface{}) int32 {
4073 panic(todo(""))
4074}
4075
4076// BOOL GetFileSecurityW(
4077//
4078// LPCSTR lpFileName,
4079// SECURITY_INFORMATION RequestedInformation,
4080// PSECURITY_DESCRIPTOR pSecurityDescriptor,
4081// DWORD nLength,
4082// LPDWORD lpnLengthNeeded
4083//
4084// );
4085func XGetFileSecurityW(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
4086 r0, _, err := syscall.Syscall6(procGetFileSecurityW.Addr(), 5, lpFileName, uintptr(RequestedInformation), pSecurityDescriptor, uintptr(nLength), lpnLengthNeeded, 0)
4087 if err != 0 {
4088 t.setErrno(err)
4089 }
4090 return int32(r0)
4091}
4092
4093// BOOL GetSecurityDescriptorOwner(
4094//
4095// PSECURITY_DESCRIPTOR pSecurityDescriptor,
4096// PSID *pOwner,
4097// LPBOOL lpbOwnerDefaulted
4098//
4099// );
4100func XGetSecurityDescriptorOwner(t *TLS, pSecurityDescriptor, pOwner, lpbOwnerDefaulted uintptr) int32 {
4101 r0, _, err := syscall.Syscall(procGetSecurityDescriptorOwner.Addr(), 3, pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
4102 if err != 0 {
4103 t.setErrno(err)
4104 }
4105 return int32(r0)
4106
4107}
4108
4109// PSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority(
4110//
4111// PSID pSid
4112//
4113// );
4114func XGetSidIdentifierAuthority(t *TLS, pSid uintptr) uintptr {
4115 r0, _, err := syscall.Syscall(procGetSidIdentifierAuthority.Addr(), 1, pSid, 0, 0)
4116 if err != 0 {
4117 t.setErrno(err)
4118 }
4119 return r0
4120}
4121
4122// BOOL ImpersonateSelf(
4123//
4124// SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
4125//
4126// );
4127func XImpersonateSelf(t *TLS, ImpersonationLevel int32) int32 {
4128 r0, _, err := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(ImpersonationLevel), 0, 0)
4129 if err != 0 {
4130 t.setErrno(err)
4131 }
4132 return int32(r0)
4133}
4134
4135// BOOL OpenThreadToken(
4136//
4137// HANDLE ThreadHandle,
4138// DWORD DesiredAccess,
4139// BOOL OpenAsSelf,
4140// PHANDLE TokenHandle
4141//
4142// );
4143func XOpenThreadToken(t *TLS, ThreadHandle uintptr, DesiredAccess uint32, OpenAsSelf int32, TokenHandle uintptr) int32 {
4144 r0, _, err := syscall.Syscall6(procOpenThreadToken.Addr(), 4, ThreadHandle, uintptr(DesiredAccess), uintptr(OpenAsSelf), TokenHandle, 0, 0)
4145 if err != 0 {
4146 t.setErrno(err)
4147 }
4148 return int32(r0)
4149}
4150
4151// HANDLE GetCurrentThread();
4152func XGetCurrentThread(t *TLS) uintptr {
4153 r0, _, err := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
4154 if err != 0 {
4155 t.setErrno(err)
4156 }
4157 return r0
4158}
4159
4160// BOOL RevertToSelf();
4161func XRevertToSelf(t *TLS) int32 {
4162 r0, _, err := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
4163 if err != 0 {
4164 t.setErrno(err)
4165 }
4166 return int32(r0)
4167}
4168
4169// BOOL AccessCheck(
4170//
4171// PSECURITY_DESCRIPTOR pSecurityDescriptor,
4172// HANDLE ClientToken,
4173// DWORD DesiredAccess,
4174// PGENERIC_MAPPING GenericMapping,
4175// PPRIVILEGE_SET PrivilegeSet,
4176// LPDWORD PrivilegeSetLength,
4177// LPDWORD GrantedAccess,
4178// LPBOOL AccessStatus
4179//
4180// );
4181func XAccessCheck(t *TLS, pSecurityDescriptor, ClientToken uintptr, DesiredAccess uint32, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus uintptr) int32 {
4182 r0, _, err := syscall.Syscall9(procAccessCheck.Addr(), 8,
4183 pSecurityDescriptor,
4184 ClientToken,
4185 uintptr(DesiredAccess),
4186 GenericMapping,
4187 PrivilegeSet,
4188 PrivilegeSetLength,
4189 GrantedAccess,
4190 AccessStatus,
4191 0,
4192 )
4193 if err != 0 {
4194 t.setErrno(err)
4195 }
4196 return int32(r0)
4197}
4198
4199// int _wcsicmp(
4200//
4201// const wchar_t *string1,
4202// const wchar_t *string2
4203//
4204// );
4205func Xwcsicmp(t *TLS, string1, string2 uintptr) int32 {
4206 var s1 = strings.ToLower(goWideString(string1))
4207 var s2 = strings.ToLower(goWideString(string2))
4208 return int32(strings.Compare(s1, s2))
4209}
4210
4211// BOOL SetCurrentDirectoryW(
4212//
4213// LPCTSTR lpPathName
4214//
4215// );
4216func XSetCurrentDirectoryW(t *TLS, lpPathName uintptr) int32 {
4217 err := syscall.SetCurrentDirectory((*uint16)(unsafe.Pointer(lpPathName)))
4218 if err != nil {
4219 t.setErrno(err)
4220 return 0
4221 }
4222 return 1
4223}
4224
4225// DWORD GetCurrentDirectory(
4226//
4227// DWORD nBufferLength,
4228// LPWTSTR lpBuffer
4229//
4230// );
4231func XGetCurrentDirectoryW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
4232 n, err := syscall.GetCurrentDirectory(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
4233 if err != nil {
4234 t.setErrno(err)
4235 }
4236 return n
4237}
4238
4239// BOOL GetFileInformationByHandle(
4240//
4241// HANDLE hFile,
4242// LPBY_HANDLE_FILE_INFORMATION lpFileInformation
4243//
4244// );
4245func XGetFileInformationByHandle(t *TLS, hFile, lpFileInformation uintptr) int32 {
4246 r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, hFile, lpFileInformation, 0)
4247 if r1 == 0 {
4248 if e1 != 0 {
4249 t.setErrno(e1)
4250 } else {
4251 t.setErrno(errno.EINVAL)
4252 }
4253 }
4254 return int32(r1)
4255}
4256
4257// BOOL GetVolumeInformationW(
4258//
4259// LPCWSTR lpRootPathName,
4260// LPWSTR lpVolumeNameBuffer,
4261// DWORD nVolumeNameSize,
4262// LPDWORD lpVolumeSerialNumber,
4263// LPDWORD lpMaximumComponentLength,
4264// LPDWORD lpFileSystemFlags,
4265// LPWSTR lpFileSystemNameBuffer,
4266// DWORD nFileSystemNameSize
4267//
4268// );
4269func XGetVolumeInformationW(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
4270 r0, _, err := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8,
4271 lpRootPathName,
4272 lpVolumeNameBuffer,
4273 uintptr(nVolumeNameSize),
4274 lpVolumeSerialNumber,
4275 lpMaximumComponentLength,
4276 lpFileSystemFlags,
4277 lpFileSystemNameBuffer,
4278 uintptr(nFileSystemNameSize),
4279 0,
4280 )
4281 if err != 0 {
4282 t.setErrno(err)
4283 }
4284 return int32(r0)
4285}
4286
4287// wchar_t *wcschr(
4288//
4289// const wchar_t *str,
4290// wchar_t c
4291//
4292// );
4293func Xwcschr(t *TLS, str uintptr, c wchar_t) uintptr {
4294 var source = str
4295 for {
4296 var buf = *(*uint16)(unsafe.Pointer(source))
4297 if buf == 0 {
4298 return 0
4299 }
4300 if buf == c {
4301 return source
4302 }
4303 // wchar_t = 2 bytes
4304 source++
4305 source++
4306 }
4307}
4308
4309// BOOL SetFileTime(
4310//
4311// HANDLE hFile,
4312// const FILETIME *lpCreationTime,
4313// const FILETIME *lpLastAccessTime,
4314// const FILETIME *lpLastWriteTime
4315//
4316// );
4317func XSetFileTime(t *TLS, hFile uintptr, lpCreationTime, lpLastAccessTime, lpLastWriteTime uintptr) int32 {
4318 panic(todo(""))
4319}
4320
4321// DWORD GetNamedSecurityInfoW(
4322//
4323// LPCWSTR pObjectName,
4324// SE_OBJECT_TYPE ObjectType,
4325// SECURITY_INFORMATION SecurityInfo,
4326// PSID *ppsidOwner,
4327// PSID *ppsidGroup,
4328// PACL *ppDacl,
4329// PACL *ppSacl,
4330// PSECURITY_DESCRIPTOR *ppSecurityDescriptor
4331//
4332// );
4333func XGetNamedSecurityInfoW(t *TLS, pObjectName uintptr, ObjectType, SecurityInfo uint32, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor uintptr) uint32 {
4334 panic(todo(""))
4335}
4336
4337// BOOL OpenProcessToken(
4338//
4339// HANDLE ProcessHandle,
4340// DWORD DesiredAccess,
4341// PHANDLE TokenHandle
4342//
4343// );
4344func XOpenProcessToken(t *TLS, ProcessHandle uintptr, DesiredAccess uint32, TokenHandle uintptr) int32 {
4345 panic(todo(""))
4346}
4347
4348// BOOL GetTokenInformation(
4349//
4350// HANDLE TokenHandle,
4351// TOKEN_INFORMATION_CLASS TokenInformationClass,
4352// LPVOID TokenInformation,
4353// DWORD TokenInformationLength,
4354// PDWORD ReturnLength
4355//
4356// );
4357func XGetTokenInformation(t *TLS, TokenHandle uintptr, TokenInformationClass uint32, TokenInformation uintptr, TokenInformationLength uint32, ReturnLength uintptr) int32 {
4358 panic(todo(""))
4359}
4360
4361// BOOL EqualSid(
4362//
4363// PSID pSid1,
4364// PSID pSid2
4365//
4366// );
4367func XEqualSid(t *TLS, pSid1, pSid2 uintptr) int32 {
4368 panic(todo(""))
4369}
4370
4371// int WSAStartup(
4372//
4373// WORD wVersionRequired,
4374// LPWSADATA lpWSAData
4375//
4376// );
4377func XWSAStartup(t *TLS, wVersionRequired uint16, lpWSAData uintptr) int32 {
4378 r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(wVersionRequired), lpWSAData, 0)
4379 if r0 != 0 {
4380 t.setErrno(r0)
4381 }
4382 return int32(r0)
4383}
4384
4385// HMODULE GetModuleHandleA(LPCSTR lpModuleName);
4386func XGetModuleHandleA(t *TLS, lpModuleName uintptr) uintptr {
4387 r0, _, err := syscall.Syscall(procGetModuleHandleA.Addr(), 1, lpModuleName, 0, 0)
4388 if r0 == 0 {
4389 t.setErrno(err)
4390 }
4391 return r0
4392}
4393
4394// HMODULE GetModuleHandleW(
4395//
4396// LPCWSTR lpModuleName
4397//
4398// );
4399func XGetModuleHandleW(t *TLS, lpModuleName uintptr) uintptr {
4400 r0, _, err := syscall.Syscall(procGetModuleHandleW.Addr(), 1, lpModuleName, 0, 0)
4401 if r0 == 0 {
4402 t.setErrno(err)
4403 }
4404 return r0
4405}
4406
4407// DWORD GetEnvironmentVariableW(
4408//
4409// LPCWSTR lpName,
4410// LPWSTR lpBuffer,
4411// DWORD nSize
4412//
4413// );
4414func XGetEnvironmentVariableW(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
4415 r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, lpName, lpBuffer, uintptr(nSize))
4416 n := uint32(r0)
4417 if n == 0 {
4418 if e1 != 0 {
4419 t.setErrno(e1)
4420 } else {
4421 t.setErrno(errno.EINVAL)
4422 }
4423 }
4424 return n
4425}
4426
4427// int lstrcmpiA(
4428//
4429// LPCSTR lpString1,
4430// LPCSTR lpString2
4431//
4432// );
4433func XlstrcmpiA(t *TLS, lpString1, lpString2 uintptr) int32 {
4434 var s1 = strings.ToLower(GoString(lpString1))
4435 var s2 = strings.ToLower(GoString(lpString2))
4436 return int32(strings.Compare(s1, s2))
4437}
4438
4439func XGetModuleFileNameA(t *TLS, _ ...interface{}) int32 {
4440 panic(todo(""))
4441}
4442
4443// UINT GetACP();
4444func XGetACP(t *TLS) uint32 {
4445 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
4446 return uint32(r0)
4447}
4448
4449// BOOL GetUserNameW(
4450//
4451// LPWSTR lpBuffer,
4452// LPDWORD pcbBuffer
4453//
4454// );
4455func XGetUserNameW(t *TLS, lpBuffer, pcbBuffer uintptr) int32 {
4456 u, err := user.Current()
4457 if err != nil {
4458 panic(todo(""))
4459 return 0
4460 }
4461
4462 wcnt := *(*uint16)(unsafe.Pointer(pcbBuffer))
4463 s := utf16.Encode([]rune(u.Username))
4464 if len(s)+1 > int(wcnt) {
4465 panic(todo(""))
4466 }
4467
4468 *(*uint16)(unsafe.Pointer(pcbBuffer)) = uint16(len(s) + 1)
4469 for _, v := range s {
4470 *(*uint16)(unsafe.Pointer(lpBuffer)) = v
4471 lpBuffer += 2
4472 }
4473 return 1
4474}
4475
4476// HMODULE LoadLibraryExW(
4477//
4478// LPCWSTR lpLibFileName,
4479// HANDLE hFile,
4480// DWORD dwFlags
4481//
4482// );
4483func XLoadLibraryExW(t *TLS, lpLibFileName, hFile uintptr, dwFlags uint32) uintptr {
4484 return 0 // If the function fails, the return value is NULL.
4485}
4486
4487// wchar_t *wcscpy(
4488//
4489// wchar_t *strDestination,
4490// const wchar_t *strSource
4491//
4492// );
4493func Xwcscpy(t *TLS, strDestination, strSource uintptr) uintptr {
4494 if strSource == 0 {
4495 return 0
4496 }
4497
4498 d := strDestination
4499 for {
4500 c := *(*uint16)(unsafe.Pointer(strSource))
4501 strSource += 2
4502 *(*uint16)(unsafe.Pointer(d)) = c
4503 d += 2
4504 if c == 0 {
4505 return strDestination
4506 }
4507 }
4508}
4509
4510func XwsprintfW(t *TLS, _ ...interface{}) int32 {
4511 panic(todo(""))
4512}
4513
4514// ATOM RegisterClassW(
4515//
4516// const WNDCLASSW *lpWndClass
4517//
4518// );
4519func XRegisterClassW(t *TLS, lpWndClass uintptr) int32 {
4520 r0, _, err := syscall.Syscall(procRegisterClassW.Addr(), 1, lpWndClass, 0, 0)
4521 if r0 == 0 {
4522 t.setErrno(err)
4523 }
4524 return int32(r0)
4525}
4526
4527func XKillTimer(t *TLS, _ ...interface{}) int32 {
4528 panic(todo(""))
4529}
4530
4531func XDestroyWindow(t *TLS, _ ...interface{}) int32 {
4532 panic(todo(""))
4533}
4534
4535// BOOL UnregisterClassW(
4536//
4537// LPCWSTR lpClassName,
4538// HINSTANCE hInstance
4539//
4540// );
4541func XUnregisterClassW(t *TLS, lpClassName, hInstance uintptr) int32 {
4542 r0, _, err := syscall.Syscall(procUnregisterClassW.Addr(), 2, lpClassName, hInstance, 0)
4543 if r0 == 0 {
4544 t.setErrno(err)
4545 }
4546 return int32(r0)
4547}
4548
4549func XPostMessageW(t *TLS, _ ...interface{}) int32 {
4550 panic(todo(""))
4551}
4552
4553func XSetTimer(t *TLS, _ ...interface{}) int32 {
4554 panic(todo(""))
4555}
4556
4557// HWND CreateWindowExW(
4558//
4559// DWORD dwExStyle,
4560// LPCWSTR lpClassName,
4561// LPCWSTR lpWindowName,
4562// DWORD dwStyle,
4563// int X,
4564// int Y,
4565// int nWidth,
4566// int nHeight,
4567// HWND hWndParent,
4568// HMENU hMenu,
4569// HINSTANCE hInstance,
4570// LPVOID lpParam
4571//
4572// );
4573func XCreateWindowExW(t *TLS, dwExStyle uint32, lpClassName, lpWindowName uintptr, dwStyle uint32, x, y, nWidth, nHeight int32, hWndParent, hMenu, hInstance, lpParam uintptr) uintptr {
4574 r0, _, err := syscall.Syscall12(procCreateWindowExW.Addr(), 12,
4575 uintptr(dwExStyle),
4576 lpClassName,
4577 lpWindowName,
4578 uintptr(dwStyle),
4579 uintptr(x),
4580 uintptr(y),
4581 uintptr(nWidth),
4582 uintptr(nHeight),
4583 hWndParent,
4584 hMenu,
4585 hInstance,
4586 lpParam,
4587 )
4588 if err != 0 {
4589 t.setErrno(err)
4590 }
4591 return r0
4592}
4593
4594// BOOL PeekMessageW(
4595//
4596// LPMSG lpMsg,
4597// HWND hWnd,
4598// UINT wMsgFilterMin,
4599// UINT wMsgFilterMax,
4600// UINT wRemoveMsg
4601//
4602// );
4603func XPeekMessageW(t *TLS, lpMsg, hWnd uintptr, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) int32 {
4604 r0, _, err := syscall.Syscall6(procPeekMessageW.Addr(), 5,
4605 lpMsg,
4606 hWnd,
4607 uintptr(wMsgFilterMin),
4608 uintptr(wMsgFilterMax),
4609 uintptr(wRemoveMsg),
4610 0,
4611 )
4612 if err != 0 {
4613 t.setErrno(err)
4614 }
4615 return int32(r0)
4616}
4617
4618func XGetMessageW(t *TLS, _ ...interface{}) int32 {
4619 panic(todo(""))
4620}
4621
4622func XPostQuitMessage(t *TLS, _ ...interface{}) int32 {
4623 panic(todo(""))
4624}
4625
4626func XTranslateMessage(t *TLS, _ ...interface{}) int32 {
4627 panic(todo(""))
4628}
4629
4630func XDispatchMessageW(t *TLS, _ ...interface{}) int32 {
4631 panic(todo(""))
4632}
4633
4634// DWORD SleepEx(
4635//
4636// DWORD dwMilliseconds,
4637// BOOL bAlertable
4638//
4639// );
4640func XSleepEx(t *TLS, dwMilliseconds uint32, bAlertable int32) uint32 {
4641 r0, _, _ := syscall.Syscall(procSleepEx.Addr(), 2, uintptr(dwMilliseconds), uintptr(bAlertable), 0)
4642 return uint32(r0)
4643}
4644
4645// BOOL CreatePipe(
4646//
4647// PHANDLE hReadPipe,
4648// PHANDLE hWritePipe,
4649// LPSECURITY_ATTRIBUTES lpPipeAttributes,
4650// DWORD nSize
4651//
4652// );
4653func XCreatePipe(t *TLS, hReadPipe, hWritePipe, lpPipeAttributes uintptr, nSize uint32) int32 {
4654 r0, _, err := syscall.Syscall6(procCreatePipe.Addr(), 4, hReadPipe, hWritePipe, lpPipeAttributes, uintptr(nSize), 0, 0)
4655 if r0 == 0 {
4656 t.setErrno(err)
4657 }
4658 return int32(r0)
4659}
4660
4661// BOOL CreateProcessW(
4662//
4663// LPCWSTR lpApplicationName,
4664// LPWSTR lpCommandLine,
4665// LPSECURITY_ATTRIBUTES lpProcessAttributes,
4666// LPSECURITY_ATTRIBUTES lpThreadAttributes,
4667// BOOL bInheritHandles,
4668// DWORD dwCreationFlags,
4669// LPVOID lpEnvironment,
4670// LPCWSTR lpCurrentDirectory,
4671// LPSTARTUPINFOW lpStartupInfo,
4672// LPPROCESS_INFORMATION lpProcessInformation
4673//
4674// );
4675func XCreateProcessW(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32, dwCreationFlags uint32,
4676 lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
4677
4678 r1, _, e1 := syscall.Syscall12(procCreateProcessW.Addr(), 10, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
4679 uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
4680 if r1 == 0 {
4681 if e1 != 0 {
4682 t.setErrno(e1)
4683 } else {
4684 t.setErrno(errno.EINVAL)
4685 }
4686 }
4687
4688 return int32(r1)
4689}
4690
4691// DWORD WaitForInputIdle(
4692//
4693// HANDLE hProcess,
4694// DWORD dwMilliseconds
4695//
4696// );
4697func XWaitForInputIdle(t *TLS, hProcess uintptr, dwMilliseconds uint32) int32 {
4698 r0, _, _ := syscall.Syscall(procWaitForInputIdle.Addr(), 2, hProcess, uintptr(dwMilliseconds), 0)
4699 return int32(r0)
4700}
4701
4702// DWORD SearchPathW(
4703//
4704// LPCWSTR lpPath,
4705// LPCWSTR lpFileName,
4706// LPCWSTR lpExtension,
4707// DWORD nBufferLength,
4708// LPWSTR lpBuffer,
4709// LPWSTR *lpFilePart
4710//
4711// );
4712func XSearchPathW(t *TLS, lpPath, lpFileName, lpExtension uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) int32 {
4713 r0, _, err := syscall.Syscall6(procSearchPathW.Addr(), 6, lpPath, lpFileName, lpExtension, uintptr(nBufferLength), lpBuffer, lpFilePart)
4714 if r0 == 0 {
4715 t.setErrno(err)
4716 }
4717 return int32(r0)
4718}
4719
4720func XGetShortPathNameW(t *TLS, _ ...interface{}) int32 {
4721 panic(todo(""))
4722}
4723
4724// BOOL GetExitCodeProcess(
4725//
4726// HANDLE hProcess,
4727// LPDWORD lpExitCode
4728//
4729// );
4730func XGetExitCodeProcess(t *TLS, hProcess, lpExitCode uintptr) int32 {
4731 r0, _, err := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, hProcess, lpExitCode, 0)
4732 if r0 == 0 {
4733 t.setErrno(err)
4734 }
4735 return int32(r0)
4736}
4737
4738// BOOL PeekNamedPipe(
4739//
4740// HANDLE hNamedPipe,
4741// LPVOID lpBuffer,
4742// DWORD nBufferSize,
4743// LPDWORD lpBytesRead,
4744// LPDWORD lpTotalBytesAvail,
4745// LPDWORD lpBytesLeftThisMessage
4746//
4747// );
4748func XPeekNamedPipe(t *TLS, hNamedPipe, lpBuffer uintptr, nBufferSize uint32, lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage uintptr) int32 {
4749 r0, _, err := syscall.Syscall6(procPeekNamedPipe.Addr(), 6, hNamedPipe, lpBuffer, uintptr(nBufferSize), lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage)
4750 if r0 == 0 {
4751 t.setErrno(err)
4752 }
4753 return int32(r0)
4754}
4755
4756// long _InterlockedExchange(
4757//
4758// long volatile * Target,
4759// long Value
4760//
4761// );
4762func X_InterlockedExchange(t *TLS, Target uintptr, Value long) long {
4763 old := atomic.SwapInt32((*int32)(unsafe.Pointer(Target)), Value)
4764 return old
4765}
4766
4767// BOOL TerminateThread(
4768//
4769// [in, out] HANDLE hThread,
4770// [in] DWORD dwExitCode
4771//
4772// );
4773func XTerminateThread(t *TLS, hThread uintptr, dwExitCode uint32) int32 {
4774 r0, _, err := syscall.Syscall(procTerminateThread.Addr(), 2, hThread, uintptr(dwExitCode), 0)
4775 if err != 0 {
4776 t.setErrno(err)
4777 }
4778 return int32(r0)
4779}
4780
4781// BOOL GetComputerNameW(
4782//
4783// LPWSTR lpBuffer,
4784// LPDWORD nSize
4785//
4786// );
4787func XGetComputerNameW(t *TLS, lpBuffer, nSize uintptr) int32 {
4788 panic(todo(""))
4789}
4790
4791func Xgethostname(t *TLS, _ ...interface{}) int32 {
4792 panic(todo(""))
4793}
4794
4795func XSendMessageW(t *TLS, _ ...interface{}) int32 {
4796 panic(todo(""))
4797}
4798
4799func XWSAGetLastError(t *TLS, _ ...interface{}) int32 {
4800 panic(todo(""))
4801}
4802
4803func Xclosesocket(t *TLS, _ ...interface{}) int32 {
4804 panic(todo(""))
4805}
4806
4807func XWspiapiFreeAddrInfo(t *TLS, _ ...interface{}) int32 {
4808 panic(todo(""))
4809}
4810
4811func XWspiapiGetNameInfo(t *TLS, _ ...interface{}) int32 {
4812 panic(todo(""))
4813}
4814
4815func XIN6_ADDR_EQUAL(t *TLS, _ ...interface{}) int32 {
4816 panic(todo(""))
4817}
4818
4819func X__ccgo_in6addr_anyp(t *TLS, _ ...interface{}) int32 {
4820 panic(todo(""))
4821}
4822
4823func XIN6_IS_ADDR_V4MAPPED(t *TLS, _ ...interface{}) int32 {
4824 panic(todo(""))
4825}
4826
4827func XSetHandleInformation(t *TLS, _ ...interface{}) int32 {
4828 panic(todo(""))
4829}
4830
4831func Xioctlsocket(t *TLS, _ ...interface{}) int32 {
4832 panic(todo(""))
4833}
4834
4835func XGetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
4836 panic(todo(""))
4837}
4838
4839func XSetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
4840 panic(todo(""))
4841}
4842
4843func XWSAAsyncSelect(t *TLS, _ ...interface{}) int32 {
4844 panic(todo(""))
4845}
4846
4847func Xinet_ntoa(t *TLS, _ ...interface{}) uintptr {
4848 panic(todo(""))
4849}
4850
4851func X_controlfp(t *TLS, _ ...interface{}) uint32 {
4852 panic(todo(""))
4853}
4854
4855// BOOL QueryPerformanceFrequency(
4856//
4857// LARGE_INTEGER *lpFrequency
4858//
4859// );
4860func XQueryPerformanceFrequency(t *TLS, lpFrequency uintptr) int32 {
4861
4862 r1, _, err := syscall.Syscall(procQueryPerformanceFrequency.Addr(), 1, lpFrequency, 0, 0)
4863 if r1 == 0 {
4864 t.setErrno(err)
4865 return 0
4866 }
4867 return int32(r1)
4868}
4869
4870func inDST(t gotime.Time) bool {
4871
4872 jan1st := gotime.Date(t.Year(), 1, 1, 0, 0, 0, 0, t.Location()) // January 1st is always outside DST window
4873
4874 _, off1 := t.Zone()
4875 _, off2 := jan1st.Zone()
4876
4877 return off1 != off2
4878}
4879
4880// void _ftime( struct _timeb *timeptr );
4881func X_ftime(t *TLS, timeptr uintptr) {
4882 var tm = gotime.Now()
4883 var tPtr = (*time.X__timeb64)(unsafe.Pointer(timeptr))
4884 tPtr.Ftime = tm.Unix()
4885 tPtr.Fmillitm = uint16(gotime.Duration(tm.Nanosecond()) / gotime.Millisecond)
4886 if inDST(tm) {
4887 tPtr.Fdstflag = 1
4888 }
4889 _, offset := tm.Zone()
4890 tPtr.Ftimezone = int16(offset)
4891}
4892
4893func Xgmtime(t *TLS, _ ...interface{}) uintptr {
4894 panic(todo(""))
4895}
4896
4897func XDdeInitializeW(t *TLS, _ ...interface{}) uint32 {
4898 panic(todo(""))
4899}
4900
4901func XDdeCreateStringHandleW(t *TLS, _ ...interface{}) uintptr {
4902 panic(todo(""))
4903}
4904
4905func XDdeNameService(t *TLS, _ ...interface{}) int32 {
4906 panic(todo(""))
4907}
4908
4909func X_snwprintf(t *TLS, _ ...interface{}) int32 {
4910 panic(todo(""))
4911}
4912
4913func XDdeQueryStringW(t *TLS, _ ...interface{}) int32 {
4914 panic(todo(""))
4915}
4916
4917// int _wcsicmp(
4918//
4919// const wchar_t *string1,
4920// const wchar_t *string2
4921//
4922// );
4923func X_wcsicmp(t *TLS, string1, string2 uintptr) int32 {
4924 return Xwcsicmp(t, string1, string2)
4925}
4926
4927func XDdeCreateDataHandle(t *TLS, _ ...interface{}) uintptr {
4928 panic(todo(""))
4929}
4930
4931func XDdeAccessData(t *TLS, _ ...interface{}) uintptr {
4932 panic(todo(""))
4933}
4934
4935func XDdeUnaccessData(t *TLS, _ ...interface{}) int32 {
4936 panic(todo(""))
4937}
4938
4939func XDdeUninitialize(t *TLS, _ ...interface{}) int32 {
4940 panic(todo(""))
4941}
4942
4943func XDdeConnect(t *TLS, _ ...interface{}) uintptr {
4944 panic(todo(""))
4945}
4946
4947func XDdeFreeStringHandle(t *TLS, _ ...interface{}) int32 {
4948 panic(todo(""))
4949}
4950
4951func XRegisterClassExW(t *TLS, _ ...interface{}) int32 {
4952 panic(todo(""))
4953}
4954
4955func XGlobalGetAtomNameW(t *TLS, _ ...interface{}) int32 {
4956 panic(todo(""))
4957}
4958
4959func XGlobalAddAtomW(t *TLS, _ ...interface{}) uint16 {
4960 panic(todo(""))
4961}
4962
4963func XEnumWindows(t *TLS, _ ...interface{}) int32 {
4964 panic(todo(""))
4965}
4966
4967func XIsWindow(t *TLS, _ ...interface{}) int32 {
4968 panic(todo(""))
4969}
4970
4971func XGlobalDeleteAtom(t *TLS, _ ...interface{}) int32 {
4972 panic(todo(""))
4973}
4974
4975func XDdeGetLastError(t *TLS, _ ...interface{}) uint32 {
4976 panic(todo(""))
4977}
4978
4979// HDDEDATA DdeClientTransaction(
4980//
4981// LPBYTE pData,
4982// DWORD cbData,
4983// HCONV hConv,
4984// HSZ hszItem,
4985// UINT wFmt,
4986// UINT wType,
4987// DWORD dwTimeout,
4988// LPDWORD pdwResult
4989//
4990// );
4991func XDdeClientTransaction(t *TLS, pData uintptr, cbData uint32, hConv uintptr, hszItem uintptr, wFmt, wType, dwTimeout uint32, pdwResult uintptr) uintptr {
4992 panic(todo(""))
4993}
4994
4995func XDdeAbandonTransaction(t *TLS, _ ...interface{}) int32 {
4996 panic(todo(""))
4997}
4998
4999func XDdeFreeDataHandle(t *TLS, _ ...interface{}) int32 {
5000 panic(todo(""))
5001}
5002
5003func XDdeGetData(t *TLS, _ ...interface{}) int32 {
5004 panic(todo(""))
5005}
5006
5007func XDdeDisconnect(t *TLS, _ ...interface{}) int32 {
5008 panic(todo(""))
5009}
5010
5011func XRegCloseKey(t *TLS, _ ...interface{}) int32 {
5012 panic(todo(""))
5013}
5014
5015func XRegDeleteValueW(t *TLS, _ ...interface{}) int32 {
5016 panic(todo(""))
5017}
5018
5019func XRegEnumKeyExW(t *TLS, _ ...interface{}) int32 {
5020 panic(todo(""))
5021}
5022
5023func XRegQueryValueExW(t *TLS, _ ...interface{}) int32 {
5024 panic(todo(""))
5025}
5026
5027func XRegEnumValueW(t *TLS, _ ...interface{}) int32 {
5028 panic(todo(""))
5029}
5030
5031func XRegConnectRegistryW(t *TLS, _ ...interface{}) int32 {
5032 panic(todo(""))
5033}
5034
5035func XRegCreateKeyExW(t *TLS, _ ...interface{}) int32 {
5036 panic(todo(""))
5037}
5038
5039func XRegOpenKeyExW(t *TLS, _ ...interface{}) int32 {
5040 panic(todo(""))
5041}
5042
5043func XRegDeleteKeyW(t *TLS, _ ...interface{}) int32 {
5044 panic(todo(""))
5045}
5046
5047func XRegSetValueExW(t *TLS, _ ...interface{}) int32 {
5048 panic(todo(""))
5049}
5050
5051// int _vsnwprintf(
5052//
5053// wchar_t *buffer,
5054// size_t count,
5055// const wchar_t *format,
5056// va_list argptr
5057//
5058// );
5059func X__mingw_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, va uintptr) int32 {
5060 panic(todo(""))
5061}
5062
5063// int vprintf(const char *format, va_list ap);
5064func X__mingw_vprintf(t *TLS, s, ap uintptr) int32 { return Xvprintf(t, s, ap) }
5065
5066// int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
5067func X__mingw_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
5068 panic(todo(""))
5069}
5070
5071// int vsscanf(const char *str, const char *format, va_list ap);
5072func X__mingw_vsscanf(t *TLS, str, format, ap uintptr) int32 {
5073 return Xsscanf(t, str, format, ap)
5074}
5075
5076// int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg);
5077func X__mingw_vfprintf(t *TLS, f uintptr, format, va uintptr) int32 {
5078 return Xvfprintf(t, f, format, va)
5079}
5080
5081// int vsprintf(char * restrict s, const char * restrict format, va_list arg);
5082func X__mingw_vsprintf(t *TLS, s, format, ap uintptr) int32 {
5083 return Xvsprintf(t, s, format, ap)
5084}
5085
5086// int vsnprintf(char *str, size_t size, const char *format, va_list ap);
5087func X__mingw_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
5088 panic(todo(""))
5089}
5090
5091// int putchar(int char)
5092func X_putchar(t *TLS, c int32) int32 {
5093 if _, err := fwrite(unistd.STDOUT_FILENO, []byte{byte(c)}); err != nil {
5094 return -1
5095 }
5096 return int32(byte(c))
5097}
5098
5099// int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
5100func X__mingw_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
5101 panic(todo(""))
5102}
5103
5104// int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
5105func X__mingw_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
5106 panic(todo(""))
5107}
5108
5109// int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg);
5110func X__mingw_vfwprintf(t *TLS, stream, format, ap uintptr) int32 {
5111 panic(todo(""))
5112}
5113
5114// int putchar(int c);
5115func Xputchar(t *TLS, c int32) int32 {
5116 panic(todo(""))
5117}
5118
5119// void _assert(
5120//
5121// char const* message,
5122// char const* filename,
5123// unsigned line
5124//
5125// );
5126func X_assert(t *TLS, message, filename uintptr, line uint32) {
5127 panic(todo(""))
5128}
5129
5130// char *strdup(const char *s);
5131func X_strdup(t *TLS, s uintptr) uintptr {
5132 panic(todo(""))
5133}
5134
5135// int _access(
5136//
5137// const char *path,
5138// int mode
5139//
5140// );
5141func X_access(t *TLS, pathname uintptr, mode int32) int32 {
5142
5143 var path = GoString(pathname)
5144
5145 info, err := os.Stat(path)
5146 if err != nil {
5147 // doesn't exist
5148 return errno.ENOENT
5149 }
5150
5151 switch mode {
5152 case 0:
5153 // exists
5154 return 0
5155 case 2:
5156 // write-only
5157 // Check if the user bit is enabled in file permission
5158 if info.Mode().Perm()&(1<<(uint(7))) == 1 {
5159 // write-able
5160 return 0
5161 }
5162 case 4:
5163 // read-only
5164 // Check if the user bit is enabled in file permission
5165 if info.Mode().Perm()&(1<<(uint(7))) == 0 {
5166 // not set, so read-only
5167 return 0
5168 }
5169 case 6:
5170 // r/w
5171 if info.Mode().Perm()&(1<<(uint(7))) == 1 {
5172 // write-able
5173 return 0
5174 }
5175 }
5176
5177 return errno.EACCES
5178
5179}
5180
5181// BOOL WINAPI SetConsoleCtrlHandler(
5182//
5183// _In_opt_ PHANDLER_ROUTINE HandlerRoutine,
5184// _In_ BOOL Add
5185//
5186// );
5187func XSetConsoleCtrlHandler(t *TLS, HandlerRoutine uintptr, Add int32) int32 {
5188
5189 //var fcc = &struct {
5190 // f func(*TLS, uint32) int32
5191 //}{}
5192 //fcc = (*struct{ f func(*TLS, uint32) int32 })(unsafe.Pointer(HandlerRoutine))
5193 //var hdlr = fcc.f
5194 //
5195 //_, _, err := procSetConsoleCtrlHandler.Call(
5196 //syscall.NewCallback(func(controlType uint) uint {
5197 // return uint( hdlr(t, uint32(controlType)) )
5198 // }), 1)
5199 //
5200 //if err != nil {
5201 // panic("failed: SetConsoleCtrlHandler")
5202 //}
5203
5204 return 0
5205}
5206
5207// DebugBreak
5208func XDebugBreak(t *TLS) {
5209 panic(todo(""))
5210}
5211
5212// int _isatty( int fd );
5213func X_isatty(t *TLS, fd int32) int32 {
5214
5215 f, ok := fdToFile(fd)
5216 if !ok {
5217 t.setErrno(errno.EBADF)
5218 return 0
5219 }
5220
5221 if fd == unistd.STDOUT_FILENO ||
5222 fd == unistd.STDIN_FILENO ||
5223 fd == unistd.STDERR_FILENO {
5224 var mode uint32
5225 err := syscall.GetConsoleMode(f.Handle, &mode)
5226 if err != nil {
5227 t.setErrno(errno.EINVAL)
5228 return 0
5229 }
5230 // is console
5231 return 1
5232 }
5233
5234 return 0
5235}
5236
5237// BOOL WINAPI SetConsoleTextAttribute(
5238//
5239// _In_ HANDLE hConsoleOutput,
5240// _In_ WORD wAttributes
5241//
5242// );
5243func XSetConsoleTextAttribute(t *TLS, hConsoleOutput uintptr, wAttributes uint16) int32 {
5244 r1, _, _ := syscall.Syscall(procSetConsoleTextAttribute.Addr(), 2, hConsoleOutput, uintptr(wAttributes), 0)
5245 return int32(r1)
5246}
5247
5248// BOOL WINAPI GetConsoleScreenBufferInfo(
5249//
5250// _In_ HANDLE hConsoleOutput,
5251// _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
5252//
5253// );
5254func XGetConsoleScreenBufferInfo(t *TLS, hConsoleOutput, lpConsoleScreenBufferInfo uintptr) int32 {
5255 r1, _, _ := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, hConsoleOutput, lpConsoleScreenBufferInfo, 0)
5256 return int32(r1)
5257}
5258
5259// FILE *_popen(
5260//
5261// const char *command,
5262// const char *mode
5263//
5264// );
5265func X_popen(t *TLS, command, mode uintptr) uintptr {
5266 panic(todo(""))
5267}
5268
5269// int _wunlink(
5270//
5271// const wchar_t *filename
5272//
5273// );
5274func X_wunlink(t *TLS, filename uintptr) int32 {
5275 panic(todo(""))
5276}
5277
5278func Xclosedir(tls *TLS, dir uintptr) int32 {
5279 panic(todo(""))
5280}
5281
5282func Xopendir(tls *TLS, name uintptr) uintptr {
5283 panic(todo(""))
5284}
5285
5286func Xreaddir(tls *TLS, dir uintptr) uintptr {
5287 panic(todo(""))
5288}
5289
5290// int _unlink(
5291//
5292// const char *filename
5293//
5294// );
5295func X_unlink(t *TLS, filename uintptr) int32 {
5296 panic(todo(""))
5297}
5298
5299// int pclose(FILE *stream);
5300func X_pclose(t *TLS, stream uintptr) int32 {
5301 panic(todo(""))
5302}
5303
5304// int setmode (int fd, int mode);
5305func Xsetmode(t *TLS, fd, mode int32) int32 {
5306 return X_setmode(t, fd, mode)
5307}
5308
5309// int _setmode (int fd, int mode);
5310func X_setmode(t *TLS, fd, mode int32) int32 {
5311
5312 _, ok := fdToFile(fd)
5313 if !ok {
5314 t.setErrno(errno.EBADF)
5315 return -1
5316 }
5317
5318 // we're always in binary mode.
5319 // at least for now.
5320
5321 if mode == fcntl.O_BINARY {
5322 return fcntl.O_BINARY
5323 } else {
5324 t.setErrno(errno.EINVAL)
5325 return -1
5326 }
5327}
5328
5329// int _mkdir(const char *dirname);
5330func X_mkdir(t *TLS, dirname uintptr) int32 {
5331 panic(todo(""))
5332}
5333
5334// int _chmod( const char *filename, int pmode );
5335func X_chmod(t *TLS, filename uintptr, pmode int32) int32 {
5336 panic(todo(""))
5337}
5338
5339// int _fileno(FILE *stream);
5340func X_fileno(t *TLS, stream uintptr) int32 {
5341 f, ok := winGetObject(stream).(*file)
5342 if !ok {
5343 t.setErrno(errno.EBADF)
5344 return -1
5345 }
5346 return f._fd
5347}
5348
5349// void rewind(FILE *stream);
5350func Xrewind(t *TLS, stream uintptr) {
5351 Xfseek(t, stream, 0, unistd.SEEK_SET)
5352}
5353
5354// __atomic_load_n
5355func X__atomic_load_n(t *TLS) {
5356 panic(todo(""))
5357}
5358
5359// __atomic_store_n
5360func X__atomic_store_n(t *TLS, _ ...interface{}) int32 {
5361 panic(todo(""))
5362}
5363
5364// __builtin_add_overflow
5365func X__builtin_add_overflow(t *TLS) {
5366 panic(todo(""))
5367}
5368
5369// __builtin_mul_overflow
5370func X__builtin_mul_overflow(t *TLS) {
5371 panic(todo(""))
5372}
5373
5374// __builtin_sub_overflow
5375func X__builtin_sub_overflow(t *TLS) {
5376 panic(todo(""))
5377}
5378
5379func goWideBytes(p uintptr, n int) []uint16 {
5380 b := GoBytes(p, 2*n)
5381 var w []uint16
5382 for i := 0; i < len(b); i += 2 {
5383 w = append(w, *(*uint16)(unsafe.Pointer(&b[i])))
5384 }
5385 return w
5386}
5387
5388// This version does include the zero terminator in the returned Go string.
5389func goWideString(p uintptr) string {
5390 if p == 0 {
5391 return ""
5392 }
5393 var w []uint16
5394 var raw = (*RawMem)(unsafe.Pointer(p))
5395 var i = 0
5396 for {
5397 wc := *(*uint16)(unsafe.Pointer(&raw[i]))
5398 w = append(w, wc)
5399 // append until U0000
5400 if wc == 0 {
5401 break
5402 }
5403 i = i + 2
5404 }
5405 s := utf16.Decode(w)
5406 return string(s)
5407}
5408
5409func goWideStringN(p uintptr, n int) string {
5410 panic(todo(""))
5411}
5412
5413// This version does not include the zero terminator in the returned Go string.
5414func goWideStringNZ(p uintptr) string {
5415 if p == 0 {
5416 return ""
5417 }
5418
5419 var w []uint16
5420 var raw = (*RawMem)(unsafe.Pointer(p))
5421 var i = 0
5422 for {
5423 wc := *(*uint16)(unsafe.Pointer(&raw[i]))
5424 if wc == 0 {
5425 break
5426 }
5427
5428 w = append(w, wc)
5429 i = i + 2
5430 }
5431 s := utf16.Decode(w)
5432 return string(s)
5433}
5434
5435// LPWSTR GetCommandLineW();
5436func XGetCommandLineW(t *TLS) uintptr {
5437 return uintptr(unsafe.Pointer(syscall.GetCommandLine()))
5438}
5439
5440// BOOL AddAccessDeniedAce(
5441//
5442// PACL pAcl,
5443// DWORD dwAceRevision,
5444// DWORD AccessMask,
5445// PSID pSid
5446//
5447// );
5448func XAddAccessDeniedAce(t *TLS, pAcl uintptr, dwAceRevision, AccessMask uint32, pSid uintptr) int32 {
5449 panic(todo(""))
5450}
5451
5452// BOOL AddAce(
5453//
5454// PACL pAcl,
5455// DWORD dwAceRevision,
5456// DWORD dwStartingAceIndex,
5457// LPVOID pAceList,
5458// DWORD nAceListLength
5459//
5460// );
5461func XAddAce(t *TLS, pAcl uintptr, dwAceRevision, dwStartingAceIndex uint32, pAceList uintptr, nAceListLength uint32) int32 {
5462 panic(todo(""))
5463}
5464
5465// BOOL GetAce(
5466//
5467// PACL pAcl,
5468// DWORD dwAceIndex,
5469// LPVOID *pAce
5470//
5471// );
5472func XGetAce(t *TLS, pAcl uintptr, dwAceIndex uint32, pAce uintptr) int32 {
5473 panic(todo(""))
5474}
5475
5476// BOOL GetAclInformation(
5477//
5478// PACL pAcl,
5479// LPVOID pAclInformation,
5480// DWORD nAclInformationLength,
5481// ACL_INFORMATION_CLASS dwAclInformationClass
5482//
5483// );
5484func XGetAclInformation(t *TLS, pAcl, pAclInformation uintptr, nAclInformationLength, dwAclInformationClass uint32) int32 {
5485 r0, _, err := syscall.Syscall6(procGetAclInformation.Addr(), 4,
5486 pAclInformation,
5487 pAclInformation,
5488 uintptr(nAclInformationLength),
5489 uintptr(dwAclInformationClass),
5490 0,
5491 0,
5492 )
5493 if err != 0 {
5494 t.setErrno(err)
5495 }
5496 return int32(r0)
5497}
5498
5499// BOOL GetFileSecurityA(
5500//
5501// LPCSTR lpFileName,
5502// SECURITY_INFORMATION RequestedInformation,
5503// PSECURITY_DESCRIPTOR pSecurityDescriptor,
5504// DWORD nLength,
5505// LPDWORD lpnLengthNeeded
5506//
5507// );
5508func XGetFileSecurityA(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
5509 r0, _, err := syscall.Syscall6(procGetFileSecurityA.Addr(), 5,
5510 lpFileName,
5511 uintptr(RequestedInformation),
5512 pSecurityDescriptor,
5513 uintptr(nLength),
5514 lpnLengthNeeded,
5515 0,
5516 )
5517 if err != 0 {
5518 t.setErrno(err)
5519 }
5520 return int32(r0)
5521}
5522
5523// DWORD GetLengthSid(
5524//
5525// PSID pSid
5526//
5527// );
5528func XGetLengthSid(t *TLS, pSid uintptr) uint32 {
5529 panic(todo(""))
5530}
5531
5532// BOOL GetSecurityDescriptorDacl(
5533//
5534// PSECURITY_DESCRIPTOR pSecurityDescriptor,
5535// LPBOOL lpbDaclPresent,
5536// PACL *pDacl,
5537// LPBOOL lpbDaclDefaulted
5538//
5539// );
5540func XGetSecurityDescriptorDacl(t *TLS, pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted uintptr) int32 {
5541 r0, _, err := syscall.Syscall6(procGetSecurityDescriptorDacl.Addr(), 4,
5542 pSecurityDescriptor,
5543 lpbDaclPresent,
5544 pDacl,
5545 lpbDaclDefaulted,
5546 0,
5547 0,
5548 )
5549 if err != 0 {
5550 t.setErrno(err)
5551 }
5552 return int32(r0)
5553}
5554
5555// DWORD GetSidLengthRequired(
5556//
5557// UCHAR nSubAuthorityCount
5558//
5559// );
5560func XGetSidLengthRequired(t *TLS, nSubAuthorityCount uint8) int32 {
5561 r0, _, err := syscall.Syscall(procGetSidLengthRequired.Addr(), 1, uintptr(nSubAuthorityCount), 0, 0)
5562 if err != 0 {
5563 t.setErrno(err)
5564 }
5565 return int32(r0)
5566}
5567
5568// PDWORD GetSidSubAuthority(
5569//
5570// PSID pSid,
5571// DWORD nSubAuthority
5572//
5573// );
5574func XGetSidSubAuthority(t *TLS, pSid uintptr, nSubAuthority uint32) uintptr {
5575 r0, _, err := syscall.Syscall(procGetSidSubAuthority.Addr(), 2, pSid, uintptr(nSubAuthority), 0)
5576 if err != 0 {
5577 t.setErrno(err)
5578 }
5579 return r0
5580}
5581
5582// BOOL InitializeAcl(
5583//
5584// PACL pAcl,
5585// DWORD nAclLength,
5586// DWORD dwAclRevision
5587//
5588// );
5589func XInitializeAcl(t *TLS, pAcl uintptr, nAclLength, dwAclRevision uint32) int32 {
5590 panic(todo(""))
5591}
5592
5593// BOOL InitializeSid(
5594//
5595// PSID Sid,
5596// PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
5597// BYTE nSubAuthorityCount
5598//
5599// );
5600func XInitializeSid(t *TLS, Sid, pIdentifierAuthority uintptr, nSubAuthorityCount uint8) int32 {
5601 r0, _, err := syscall.Syscall(procInitializeSid.Addr(), 3, Sid, pIdentifierAuthority, uintptr(nSubAuthorityCount))
5602 if err != 0 {
5603 t.setErrno(err)
5604 }
5605 return int32(r0)
5606}
5607
5608// VOID RaiseException(
5609//
5610// DWORD dwExceptionCode,
5611// DWORD dwExceptionFlags,
5612// DWORD nNumberOfArguments,
5613// const ULONG_PTR *lpArguments
5614//
5615// );
5616func XRaiseException(t *TLS, dwExceptionCode, dwExceptionFlags, nNumberOfArguments uint32, lpArguments uintptr) {
5617 panic(todo(""))
5618}
5619
5620// UINT SetErrorMode(
5621//
5622// UINT uMode
5623//
5624// );
5625func XSetErrorMode(t *TLS, uMode uint32) int32 {
5626 panic(todo(""))
5627}
5628
5629// DWORD SetNamedSecurityInfoA(
5630//
5631// LPSTR pObjectName,
5632// SE_OBJECT_TYPE ObjectType,
5633// SECURITY_INFORMATION SecurityInfo,
5634// PSID psidOwner,
5635// PSID psidGroup,
5636// PACL pDacl,
5637// PACL pSacl
5638//
5639// );
5640func XSetNamedSecurityInfoA(t *TLS, pObjectName uintptr, ObjectType, SecurityInfo uint32, psidOwner, psidGroup, pDacl, pSacl uintptr) uint32 {
5641 panic(todo(""))
5642}
5643
5644// BOOL CreateProcessA(
5645//
5646// LPCSTR lpApplicationName,
5647// LPSTR lpCommandLine,
5648// LPSECURITY_ATTRIBUTES lpProcessAttributes,
5649// LPSECURITY_ATTRIBUTES lpThreadAttributes,
5650// BOOL bInheritHandles,
5651// DWORD dwCreationFlags,
5652// LPVOID lpEnvironment,
5653// LPCSTR lpCurrentDirectory,
5654// LPSTARTUPINFOA lpStartupInfo,
5655// LPPROCESS_INFORMATION lpProcessInformation
5656//
5657// );
5658func XCreateProcessA(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32,
5659 dwCreationFlags uint32, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
5660 r1, _, err := syscall.Syscall12(procCreateProcessA.Addr(), 10, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
5661 uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
5662 if r1 == 0 {
5663 if err != 0 {
5664 t.setErrno(err)
5665 } else {
5666 t.setErrno(errno.EINVAL)
5667 }
5668 }
5669 return int32(r1)
5670}
5671
5672// unsigned int _set_abort_behavior(
5673//
5674// unsigned int flags,
5675// unsigned int mask
5676//
5677// );
5678func X_set_abort_behavior(t *TLS, _ ...interface{}) uint32 {
5679 panic(todo(""))
5680}
5681
5682// HANDLE OpenEventA(
5683//
5684// DWORD dwDesiredAccess,
5685// BOOL bInheritHandle,
5686// LPCSTR lpName
5687//
5688// );
5689func XOpenEventA(t *TLS, dwDesiredAccess uint32, bInheritHandle uint32, lpName uintptr) uintptr {
5690 r0, _, err := syscall.Syscall(procOpenEventA.Addr(), 3, uintptr(dwDesiredAccess), uintptr(bInheritHandle), lpName)
5691 if r0 == 0 {
5692 t.setErrno(err)
5693 }
5694 return r0
5695}
5696
5697// size_t _msize(
5698//
5699// void *memblock
5700//
5701// );
5702func X_msize(t *TLS, memblock uintptr) types.Size_t {
5703 return types.Size_t(UsableSize(memblock))
5704}
5705
5706// unsigned long _byteswap_ulong ( unsigned long val );
5707func X_byteswap_ulong(t *TLS, val ulong) ulong {
5708 return X__builtin_bswap32(t, val)
5709}
5710
5711// unsigned __int64 _byteswap_uint64 ( unsigned __int64 val );
5712func X_byteswap_uint64(t *TLS, val uint64) uint64 {
5713 return X__builtin_bswap64(t, val)
5714}
5715
5716// int _commit(
5717//
5718// int fd
5719//
5720// );
5721func X_commit(t *TLS, fd int32) int32 {
5722 return Xfsync(t, fd)
5723}
5724
5725// int _stati64(
5726//
5727// const char *path,
5728// struct _stati64 *buffer
5729//
5730// );
5731func X_stati64(t *TLS, path, buffer uintptr) int32 {
5732 panic(todo(""))
5733}
5734
5735// int _fstati64(
5736//
5737// int fd,
5738// struct _stati64 *buffer
5739//
5740// );
5741func X_fstati64(t *TLS, fd int32, buffer uintptr) int32 {
5742 panic(todo(""))
5743}
5744
5745// int _findnext32(
5746//
5747// intptr_t handle,
5748// struct _finddata32_t *fileinfo
5749//
5750// );
5751func X_findnext32(t *TLS, handle types.Intptr_t, buffer uintptr) int32 {
5752 panic(todo(""))
5753}
5754
5755// intptr_t _findfirst32(
5756//
5757// const char *filespec,
5758// struct _finddata32_t *fileinfo
5759//
5760// );
5761func X_findfirst32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
5762 panic(todo(""))
5763}
5764
5765/*-
5766 * Copyright (c) 1990 The Regents of the University of California.
5767 * All rights reserved.
5768 *
5769 * Redistribution and use in source and binary forms, with or without
5770 * modification, are permitted provided that the following conditions
5771 * are met:
5772 * 1. Redistributions of source code must retain the above copyright
5773 * notice, this list of conditions and the following disclaimer.
5774 * 2. Redistributions in binary form must reproduce the above copyright
5775 * notice, this list of conditions and the following disclaimer in the
5776 * documentation and/or other materials provided with the distribution.
5777 * 3. Neither the name of the University nor the names of its contributors
5778 * may be used to endorse or promote products derived from this software
5779 * without specific prior written permission.
5780 *
5781 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5782 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5783 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5784 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5785 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5786 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5787 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5788 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5789 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5790 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5791 * SUCH DAMAGE.
5792 */
5793
5794// long strtol(const char *nptr, char **endptr, int base);
5795func Xstrtol(t *TLS, nptr, endptr uintptr, base int32) long {
5796
5797 var s uintptr = nptr
5798 var acc ulong
5799 var c byte
5800 var cutoff ulong
5801 var neg int32
5802 var any int32
5803 var cutlim int32
5804
5805 /*
5806 * Skip white space and pick up leading +/- sign if any.
5807 * If base is 0, allow 0x for hex and 0 for octal, else
5808 * assume decimal; if base is already 16, allow 0x.
5809 */
5810 for {
5811 c = *(*byte)(unsafe.Pointer(s))
5812 PostIncUintptr(&s, 1)
5813 var sp = strings.TrimSpace(string(c))
5814 if len(sp) > 0 {
5815 break
5816 }
5817 }
5818
5819 if c == '-' {
5820 neg = 1
5821 c = *(*byte)(unsafe.Pointer(s))
5822 PostIncUintptr(&s, 1)
5823 } else if c == '+' {
5824 c = *(*byte)(unsafe.Pointer(s))
5825 PostIncUintptr(&s, 1)
5826 }
5827
5828 sp := *(*byte)(unsafe.Pointer(s))
5829
5830 if (base == 0 || base == 16) &&
5831 c == '0' && (sp == 'x' || sp == 'X') {
5832 PostIncUintptr(&s, 1)
5833 c = *(*byte)(unsafe.Pointer(s)) //s[1];
5834 PostIncUintptr(&s, 1)
5835 base = 16
5836 }
5837 if base == 0 {
5838 if c == '0' {
5839 base = 0
5840 } else {
5841 base = 10
5842 }
5843 }
5844 /*
5845 * Compute the cutoff value between legal numbers and illegal
5846 * numbers. That is the largest legal value, divided by the
5847 * base. An input number that is greater than this value, if
5848 * followed by a legal input character, is too big. One that
5849 * is equal to this value may be valid or not; the limit
5850 * between valid and invalid numbers is then based on the last
5851 * digit. For instance, if the range for longs is
5852 * [-2147483648..2147483647] and the input base is 10,
5853 * cutoff will be set to 214748364 and cutlim to either
5854 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
5855 * a value > 214748364, or equal but the next digit is > 7 (or 8),
5856 * the number is too big, and we will return a range error.
5857 *
5858 * Set any if any `digits' consumed; make it negative to indicate
5859 * overflow.
5860 */
5861 var ULONG_MAX ulong = 0xFFFFFFFF
5862 var LONG_MAX long = long(ULONG_MAX >> 1)
5863 var LONG_MIN long = ^LONG_MAX
5864
5865 if neg == 1 {
5866 cutoff = ulong(-1 * LONG_MIN)
5867 } else {
5868 cutoff = ulong(LONG_MAX)
5869 }
5870 cutlim = int32(cutoff % ulong(base))
5871 cutoff = cutoff / ulong(base)
5872
5873 acc = 0
5874 any = 0
5875
5876 for {
5877 var cs = string(c)
5878 if unicode.IsDigit([]rune(cs)[0]) {
5879 c -= '0'
5880 } else if unicode.IsLetter([]rune(cs)[0]) {
5881 if unicode.IsUpper([]rune(cs)[0]) {
5882 c -= 'A' - 10
5883 } else {
5884 c -= 'a' - 10
5885 }
5886 } else {
5887 break
5888 }
5889
5890 if int32(c) >= base {
5891 break
5892 }
5893 if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
5894 any = -1
5895
5896 } else {
5897 any = 1
5898 acc *= ulong(base)
5899 acc += ulong(c)
5900 }
5901
5902 c = *(*byte)(unsafe.Pointer(s))
5903 PostIncUintptr(&s, 1)
5904 }
5905
5906 if any < 0 {
5907 if neg == 1 {
5908 acc = ulong(LONG_MIN)
5909 } else {
5910 acc = ulong(LONG_MAX)
5911 }
5912 t.setErrno(errno.ERANGE)
5913 } else if neg == 1 {
5914 acc = -acc
5915 }
5916
5917 if endptr != 0 {
5918 if any == 1 {
5919 PostDecUintptr(&s, 1)
5920 AssignPtrUintptr(endptr, s)
5921 } else {
5922 AssignPtrUintptr(endptr, nptr)
5923 }
5924 }
5925 return long(acc)
5926}
5927
5928// unsigned long int strtoul(const char *nptr, char **endptr, int base);
5929func Xstrtoul(t *TLS, nptr, endptr uintptr, base int32) ulong {
5930 var s uintptr = nptr
5931 var acc ulong
5932 var c byte
5933 var cutoff ulong
5934 var neg int32
5935 var any int32
5936 var cutlim int32
5937
5938 /*
5939 * Skip white space and pick up leading +/- sign if any.
5940 * If base is 0, allow 0x for hex and 0 for octal, else
5941 * assume decimal; if base is already 16, allow 0x.
5942 */
5943 for {
5944 c = *(*byte)(unsafe.Pointer(s))
5945 PostIncUintptr(&s, 1)
5946 var sp = strings.TrimSpace(string(c))
5947 if len(sp) > 0 {
5948 break
5949 }
5950 }
5951
5952 if c == '-' {
5953 neg = 1
5954 c = *(*byte)(unsafe.Pointer(s))
5955 PostIncUintptr(&s, 1)
5956 } else if c == '+' {
5957 c = *(*byte)(unsafe.Pointer(s))
5958 PostIncUintptr(&s, 1)
5959 }
5960
5961 sp := *(*byte)(unsafe.Pointer(s))
5962
5963 if (base == 0 || base == 16) &&
5964 c == '0' && (sp == 'x' || sp == 'X') {
5965 PostIncUintptr(&s, 1)
5966 c = *(*byte)(unsafe.Pointer(s)) //s[1];
5967 PostIncUintptr(&s, 1)
5968 base = 16
5969 }
5970 if base == 0 {
5971 if c == '0' {
5972 base = 0
5973 } else {
5974 base = 10
5975 }
5976 }
5977 var ULONG_MAX ulong = 0xFFFFFFFF
5978
5979 cutoff = ULONG_MAX / ulong(base)
5980 cutlim = int32(ULONG_MAX % ulong(base))
5981
5982 acc = 0
5983 any = 0
5984
5985 for {
5986 var cs = string(c)
5987 if unicode.IsDigit([]rune(cs)[0]) {
5988 c -= '0'
5989 } else if unicode.IsLetter([]rune(cs)[0]) {
5990 if unicode.IsUpper([]rune(cs)[0]) {
5991 c -= 'A' - 10
5992 } else {
5993 c -= 'a' - 10
5994 }
5995 } else {
5996 break
5997 }
5998
5999 if int32(c) >= base {
6000 break
6001 }
6002 if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
6003 any = -1
6004
6005 } else {
6006 any = 1
6007 acc *= ulong(base)
6008 acc += ulong(c)
6009 }
6010
6011 c = *(*byte)(unsafe.Pointer(s))
6012 PostIncUintptr(&s, 1)
6013 }
6014
6015 if any < 0 {
6016 acc = ULONG_MAX
6017 t.setErrno(errno.ERANGE)
6018 } else if neg == 1 {
6019 acc = -acc
6020 }
6021
6022 if endptr != 0 {
6023 if any == 1 {
6024 PostDecUintptr(&s, 1)
6025 AssignPtrUintptr(endptr, s)
6026 } else {
6027 AssignPtrUintptr(endptr, nptr)
6028 }
6029 }
6030 return acc
6031}
6032
6033// int __isoc99_sscanf(const char *str, const char *format, ...);
6034func X__isoc99_sscanf(t *TLS, str, format, va uintptr) int32 {
6035 r := scanf(strings.NewReader(GoString(str)), format, va)
6036 // if dmesgs {
6037 // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
6038 // }
6039 return r
6040}
6041
6042// int sscanf(const char *str, const char *format, ...);
6043func Xsscanf(t *TLS, str, format, va uintptr) int32 {
6044 r := scanf(strings.NewReader(GoString(str)), format, va)
6045 // if dmesgs {
6046 // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
6047 // }
6048 return r
6049}
6050
6051func Xstrtod(tls *TLS, s uintptr, p uintptr) float64 { /* strtod.c:22:8: */
6052 panic(todo(""))
6053}
6054
6055func Xrint(tls *TLS, x float64) float64 {
6056 switch {
6057 case x == 0: // also +0 and -0
6058 return 0
6059 case math.IsInf(x, 0), math.IsNaN(x):
6060 return x
6061 case x >= math.MinInt64 && x <= math.MaxInt64 && float64(int64(x)) == x:
6062 return x
6063 case x >= 0:
6064 return math.Floor(x + 0.5)
6065 default:
6066 return math.Ceil(x - 0.5)
6067 }
6068}
6069
6070// FILE *fdopen(int fd, const char *mode);
6071func Xfdopen(t *TLS, fd int32, mode uintptr) uintptr {
6072 panic(todo(""))
6073}
6074
6075// struct tm *_gmtime64( const __time64_t *sourceTime );
6076func X_gmtime64(t *TLS, sourceTime uintptr) uintptr {
6077 panic(todo(""))
6078}
6079
6080// __time64_t _mktime64(struct tm *timeptr);
6081func X_mktime64(t *TLS, timeptr uintptr) time.X__time64_t {
6082 return time.X__time64_t(Xmktime(t, timeptr))
6083}
6084
6085// char * gai_strerrorA(int ecode);
6086func Xgai_strerrorA(t *TLS, ecode int32) uintptr {
6087 panic(todo(""))
6088}
6089
6090// https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/crt/sys/timeb.h#L69
6091//
6092// struct __timeb64 {
6093// __time64_t time;
6094// unsigned short millitm;
6095// short timezone;
6096// short dstflag;
6097// };
6098
6099type __timeb64 struct {
6100 time types.X__time64_t
6101 millitm uint32
6102 timezone int16
6103 dstflag int16
6104}
6105
6106// void _ftime64( struct __timeb64 *timeptr );
6107func X_ftime64(t *TLS, timeptr uintptr) {
6108 tm := gotime.Now()
6109 (*__timeb64)(unsafe.Pointer(timeptr)).time = types.X__time64_t(tm.Unix())
6110
6111 //TODO When Go 1.16 is no more supported
6112 // (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(tm.UnixMilli() % 1000)
6113
6114 (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(int64(tm.Nanosecond()) / 1e6)
6115}
6116
6117func X__ccgo_getMutexType(tls *TLS, m uintptr) int32 { /* pthread_mutex_lock.c:3:5: */
6118 return *(*int32)(unsafe.Pointer(m)) & 15
6119}
6120
6121func X__ccgo_pthreadAttrGetDetachState(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:3:5: */
6122 return *(*int32)(unsafe.Pointer(a))
6123}
6124
6125func X__ccgo_pthreadMutexattrGettype(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:93:5: */
6126 return *(*int32)(unsafe.Pointer(a)) & int32(3)
6127}
6128
6129func Xchmod(t *TLS, pathname uintptr, mode int32) int32 {
6130 panic(todo("%q %#o", GoString(pathname), mode))
6131}
6132
6133// typedef enum _COMPUTER_NAME_FORMAT {
6134// ComputerNameNetBIOS,
6135// ComputerNameDnsHostname,
6136// ComputerNameDnsDomain,
6137// ComputerNameDnsFullyQualified,
6138// ComputerNamePhysicalNetBIOS,
6139// ComputerNamePhysicalDnsHostname,
6140// ComputerNamePhysicalDnsDomain,
6141// ComputerNamePhysicalDnsFullyQualified,
6142// ComputerNameMax
6143// } COMPUTER_NAME_FORMAT;
6144
6145// BOOL GetComputerNameExW(
6146//
6147// [in] COMPUTER_NAME_FORMAT NameType,
6148// [out] LPWSTR lpBuffer,
6149// [in, out] LPDWORD nSize
6150//
6151// );
6152func XGetComputerNameExW(t *TLS, nameType int32, lpBuffer, nSize uintptr) int32 {
6153 r0, _, err := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameType), lpBuffer, nSize)
6154 if err != 0 {
6155 t.setErrno(err)
6156 }
6157 return int32(r0)
6158}
6159
6160// double _copysign(
6161//
6162// double x,
6163// double y
6164//
6165// );
6166func X_copysign(t *TLS, x, y float64) float64 { return Xcopysign(t, x, y) }
6167
6168// int _wtoi(
6169//
6170// const wchar_t *str
6171//
6172// );
6173func X_wtoi(t *TLS, str uintptr) int32 {
6174 panic(todo(""))
6175}
6176
6177func allocW(t *TLS, v string) (r uintptr) {
6178 s := utf16.Encode([]rune(v))
6179 p := Xcalloc(t, types.Size_t(len(s)+1), 2)
6180 if p == 0 {
6181 panic(todo(""))
6182 }
6183
6184 r = p
6185 for _, v := range s {
6186 *(*uint16)(unsafe.Pointer(p)) = v
6187 p += 2
6188 }
6189 return r
6190}
6191
6192// wchar_t *_wgetenv(
6193//
6194// const wchar_t *varname
6195//
6196// );
6197func X_wgetenv(t *TLS, varname uintptr) uintptr {
6198 if !wenvValid {
6199 bootWinEnviron(t)
6200 }
6201 k := strings.ToLower(goWideStringNZ(varname))
6202 for _, v := range winEnviron[:len(winEnviron)-1] {
6203 s := strings.ToLower(goWideStringNZ(v))
6204 x := strings.IndexByte(s, '=')
6205 if s[:x] == k {
6206 // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), goWideStringNZ(v))
6207 return v
6208 }
6209 }
6210
6211 // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), "")
6212 return 0
6213}
6214
6215// int _wputenv(
6216//
6217// const wchar_t *envstring
6218//
6219// );
6220func X_wputenv(t *TLS, envstring uintptr) int32 {
6221 if !wenvValid {
6222 bootWinEnviron(t)
6223 }
6224 s0 := goWideStringNZ(envstring)
6225 s := strings.ToLower(s0)
6226 x := strings.IndexByte(s, '=')
6227 k := s[:x]
6228 for i, v := range winEnviron[:len(winEnviron)-1] {
6229 s2 := strings.ToLower(goWideStringNZ(v))
6230 x := strings.IndexByte(s2, '=')
6231 if s2[:x] == k {
6232 Xfree(t, v)
6233 winEnviron[i] = allocW(t, s0)
6234 return 0
6235 }
6236 }
6237
6238 np := allocW(t, s0)
6239 winEnviron = winEnviron[:len(winEnviron)-1]
6240 winEnviron = append(winEnviron, np, 0)
6241 wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
6242 return 0
6243}
6244
6245func bootWinEnviron(t *TLS) {
6246 winEnviron = winEnviron[:0]
6247 p := Environ()
6248 for {
6249 q := *(*uintptr)(unsafe.Pointer(p))
6250 p += unsafe.Sizeof(uintptr(0))
6251 if q == 0 {
6252 break
6253 }
6254
6255 s := GoString(q)
6256 // trc("%v: %q", origin(1), s)
6257 r := allocW(t, s)
6258 winEnviron = append(winEnviron, r)
6259 }
6260 wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
6261 wenvValid = true
6262}
6263
6264func Xfabsl(t *TLS, x float64) float64 { return math.Abs(x) }
6265
6266func X__stdio_common_vfprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6267func X__stdio_common_vfprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
6268func X__stdio_common_vfprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6269func X__stdio_common_vfscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6270func X__stdio_common_vfwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6271func X__stdio_common_vfwscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6272func X__stdio_common_vsnprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6273func X__stdio_common_vsnwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6274func X__stdio_common_vsprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6275func X__stdio_common_vsprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
6276func X__stdio_common_vsprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6277func X__stdio_common_vsscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6278func X__stdio_common_vswprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
6279func X__stdio_common_vswprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
6280func X__stdio_common_vswscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
Note: See TracBrowser for help on using the repository browser.