source: code/trunk/vendor/modernc.org/libc/libc_windows_amd64.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: 12.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 "modernc.org/libc/errno"
9 "modernc.org/libc/sys/types"
10 "os"
11 "strings"
12 "syscall"
13 "unsafe"
14)
15
16// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
17func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
18 panic(todo(""))
19 // musl/arch/x86_64/ksigaction.h
20 //
21 // struct k_sigaction {
22 // void (*handler)(int);
23 // unsigned long flags;
24 // void (*restorer)(void);
25 // unsigned mask[2];
26 // };
27 // type k_sigaction struct {
28 // handler uintptr
29 // flags ulong
30 // restorer uintptr
31 // mask [2]uint32
32 // }
33
34 // var kact, koldact uintptr
35 // if act != 0 {
36 // kact = t.Alloc(int(unsafe.Sizeof(k_sigaction{})))
37 // defer Xfree(t, kact)
38 // *(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
39 // handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
40 // flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
41 // restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
42 // }
43 // Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
44 // }
45 // if oldact != 0 {
46 // panic(todo(""))
47 // }
48
49 // if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signal.SIGABRT), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
50 // t.setErrno(err)
51 // return -1
52 // }
53
54 // if oldact != 0 {
55 // panic(todo(""))
56 // }
57
58 // return 0
59}
60
61// int fcntl(int fd, int cmd, ... /* arg */ );
62func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
63 panic(todo(""))
64 // var arg uintptr
65 // if args != 0 {
66 // arg = *(*uintptr)(unsafe.Pointer(args))
67 // }
68 // n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
69 // if err != 0 {
70 // if dmesgs {
71 // dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
72 // }
73 // t.setErrno(err)
74 // return -1
75 // }
76
77 // if dmesgs {
78 // dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
79 // }
80 // return int32(n)
81}
82
83// int lstat(const char *pathname, struct stat *statbuf);
84func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
85 panic(todo(""))
86 // if _, _, err := unix.Syscall(unix.SYS_LSTAT, pathname, statbuf, 0); err != 0 {
87 // if dmesgs {
88 // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
89 // }
90 // t.setErrno(err)
91 // return -1
92 // }
93
94 // if dmesgs {
95 // dmesg("%v: %q: ok", origin(1), GoString(pathname))
96 // }
97 // return 0
98}
99
100// int stat(const char *pathname, struct stat *statbuf);
101func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
102 panic(todo(""))
103 // if _, _, err := unix.Syscall(unix.SYS_STAT, pathname, statbuf, 0); err != 0 {
104 // if dmesgs {
105 // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
106 // }
107 // t.setErrno(err)
108 // return -1
109 // }
110
111 // if dmesgs {
112 // dmesg("%v: %q: ok", origin(1), GoString(pathname))
113 // }
114 // return 0
115}
116
117// int fstat(int fd, struct stat *statbuf);
118func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
119 panic(todo(""))
120 // if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
121 // if dmesgs {
122 // dmesg("%v: fd %d: %v", origin(1), fd, err)
123 // }
124 // t.setErrno(err)
125 // return -1
126 // }
127
128 // if dmesgs {
129 // dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
130 // }
131 // return 0
132}
133
134func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
135 return Xmmap64(t, addr, length, prot, flags, fd, offset)
136}
137
138// void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
139func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
140 panic(todo(""))
141 // data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
142 // if err != 0 {
143 // if dmesgs {
144 // dmesg("%v: %v", origin(1), err)
145 // }
146 // t.setErrno(err)
147 // return ^uintptr(0) // (void*)-1
148 // }
149
150 // if dmesgs {
151 // dmesg("%v: %#x", origin(1), data)
152 // }
153 // return data
154}
155
156// void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
157func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
158 panic(todo(""))
159 // var arg uintptr
160 // if args != 0 {
161 // arg = *(*uintptr)(unsafe.Pointer(args))
162 // }
163 // data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
164 // if err != 0 {
165 // if dmesgs {
166 // dmesg("%v: %v", origin(1), err)
167 // }
168 // t.setErrno(err)
169 // return ^uintptr(0) // (void*)-1
170 // }
171
172 // if dmesgs {
173 // dmesg("%v: %#x", origin(1), data)
174 // }
175 // return data
176}
177
178// int ftruncate(int fd, off_t length);
179func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
180 panic(todo(""))
181 // if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
182 // if dmesgs {
183 // dmesg("%v: fd %d: %v", origin(1), fd, err)
184 // }
185 // t.setErrno(err)
186 // return -1
187 // }
188
189 // if dmesgs {
190 // dmesg("%v: %d %#x: ok", origin(1), fd, length)
191 // }
192 // return 0
193}
194
195// off64_t lseek64(int fd, off64_t offset, int whence);
196func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
197
198 f, ok := fdToFile(fd)
199 if !ok {
200 t.setErrno(errno.EBADF)
201 return -1
202 }
203
204 n, err := syscall.Seek(f.Handle, offset, int(whence))
205 if err != nil {
206 if dmesgs {
207 dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
208 }
209 t.setErrno(err)
210 return -1
211 }
212
213 if dmesgs {
214 dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
215 }
216 return n
217}
218
219// int utime(const char *filename, const struct utimbuf *times);
220func Xutime(t *TLS, filename, times uintptr) int32 {
221 panic(todo(""))
222 // if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
223 // t.setErrno(err)
224 // return -1
225 // }
226
227 // return 0
228}
229
230// unsigned int alarm(unsigned int seconds);
231func Xalarm(t *TLS, seconds uint32) uint32 {
232 panic(todo(""))
233 // n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
234 // if err != 0 {
235 // panic(todo(""))
236 // }
237
238 // return uint32(n)
239}
240
241// time_t time(time_t *tloc);
242func Xtime(t *TLS, tloc uintptr) types.Time_t {
243 panic(todo(""))
244 // n, _, err := unix.Syscall(unix.SYS_TIME, tloc, 0, 0)
245 // if err != 0 {
246 // t.setErrno(err)
247 // return types.Time_t(-1)
248 // }
249
250 // if tloc != 0 {
251 // *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
252 // }
253 // return types.Time_t(n)
254}
255
256// int getrlimit(int resource, struct rlimit *rlim);
257func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
258 panic(todo(""))
259 // if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
260 // t.setErrno(err)
261 // return -1
262 // }
263
264 // return 0
265}
266
267// int mkdir(const char *path, mode_t mode);
268func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
269 panic(todo(""))
270 // if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
271 // t.setErrno(err)
272 // return -1
273 // }
274
275 // if dmesgs {
276 // dmesg("%v: %q: ok", origin(1), GoString(path))
277 // }
278 // return 0
279}
280
281// int symlink(const char *target, const char *linkpath);
282func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
283 panic(todo(""))
284 // if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
285 // t.setErrno(err)
286 // return -1
287 // }
288
289 // if dmesgs {
290 // dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
291 // }
292 // return 0
293}
294
295// int utimes(const char *filename, const struct timeval times[2]);
296func Xutimes(t *TLS, filename, times uintptr) int32 {
297 panic(todo(""))
298 // if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
299 // t.setErrno(err)
300 // return -1
301 // }
302
303 // if dmesgs {
304 // dmesg("%v: %q: ok", origin(1), GoString(filename))
305 // }
306 // return 0
307}
308
309// int unlink(const char *pathname);
310func Xunlink(t *TLS, pathname uintptr) int32 {
311
312 err := syscall.DeleteFile((*uint16)(unsafe.Pointer(pathname)))
313 if err != nil {
314 t.setErrno(err)
315 return -1
316 }
317
318 if dmesgs {
319 dmesg("%v: %q: ok", origin(1), GoString(pathname))
320 }
321
322 return 0
323}
324
325// int access(const char *pathname, int mode);
326func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
327 panic(todo(""))
328 // if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
329 // if dmesgs {
330 // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
331 // }
332 // t.setErrno(err)
333 // return -1
334 // }
335
336 // if dmesgs {
337 // dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
338 // }
339 // return 0
340}
341
342// int rmdir(const char *pathname);
343func Xrmdir(t *TLS, pathname uintptr) int32 {
344 panic(todo(""))
345 // if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
346 // t.setErrno(err)
347 // return -1
348 // }
349
350 // if dmesgs {
351 // dmesg("%v: %q: ok", origin(1), GoString(pathname))
352 // }
353 // return 0
354}
355
356// int mknod(const char *pathname, mode_t mode, dev_t dev);
357func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
358 panic(todo(""))
359 // if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
360 // t.setErrno(err)
361 // return -1
362 // }
363
364 // return 0
365}
366
367// // int chown(const char *pathname, uid_t owner, gid_t group);
368// func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
369// panic(todo(""))
370// // if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
371// // t.setErrno(err)
372// // return -1
373// // }
374//
375// // return 0
376// }
377
378// int link(const char *oldpath, const char *newpath);
379func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
380 panic(todo(""))
381 // if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
382 // t.setErrno(err)
383 // return -1
384 // }
385
386 // return 0
387}
388
389// int pipe(int pipefd[2]);
390func Xpipe(t *TLS, pipefd uintptr) int32 {
391 panic(todo(""))
392 // if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
393 // t.setErrno(err)
394 // return -1
395 // }
396
397 // return 0
398}
399
400// int dup2(int oldfd, int newfd);
401func Xdup2(t *TLS, oldfd, newfd int32) int32 {
402 panic(todo(""))
403 // n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
404 // if err != 0 {
405 // t.setErrno(err)
406 // return -1
407 // }
408
409 // return int32(n)
410}
411
412// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
413func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
414 panic(todo(""))
415 // n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
416 // if err != 0 {
417 // t.setErrno(err)
418 // return -1
419 // }
420
421 // return types.Ssize_t(n)
422}
423
424// FILE *fopen64(const char *pathname, const char *mode);
425func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
426
427 m := strings.ReplaceAll(GoString(mode), "b", "")
428 var flags int
429 switch m {
430 case "r":
431 flags = os.O_RDONLY
432 case "r+":
433 flags = os.O_RDWR
434 case "w":
435 flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
436 case "w+":
437 flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
438 case "a":
439 flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
440 case "a+":
441 flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
442 default:
443 panic(m)
444 }
445 //TODO- flags |= fcntl.O_LARGEFILE
446 h, err := syscall.Open(GoString(pathname), int(flags), uint32(0666))
447 if err != nil {
448 t.setErrno(err)
449 return 0
450 }
451
452 p, _ := wrapFdHandle(h)
453 if p != 0 {
454 return p
455 }
456 _ = syscall.Close(h)
457 t.setErrno(errno.ENOMEM)
458 return 0
459}
460
461func Xrecv(t *TLS, sockfd uint64, buf uintptr, len, flags int32) int32 {
462 panic(todo(""))
463}
464
465func Xsend(t *TLS, sockfd uint64, buf uintptr, len, flags int32) int32 {
466 panic(todo(""))
467}
468
469func Xshutdown(t *TLS, sockfd uint64, how int32) int32 {
470 panic(todo(""))
471}
472
473func Xgetpeername(t *TLS, sockfd uint64, addr uintptr, addrlen uintptr) int32 {
474 panic(todo(""))
475}
476
477func Xgetsockname(t *TLS, sockfd uint64, addr, addrlen uintptr) int32 {
478 panic(todo(""))
479}
480
481func Xsocket(t *TLS, domain, type1, protocol int32) uint64 {
482 panic(todo(""))
483}
484
485func Xbind(t *TLS, sockfd uint64, addr uintptr, addrlen int32) int32 {
486 panic(todo(""))
487}
488
489func Xconnect(t *TLS, sockfd uint64, addr uintptr, addrlen int32) int32 {
490 panic(todo(""))
491}
492
493func Xlisten(t *TLS, sockfd uint64, backlog int32) int32 {
494 panic(todo(""))
495}
496
497func Xaccept(t *TLS, sockfd uint64, addr uintptr, addrlen uintptr) uint64 {
498 panic(todo(""))
499}
500
501// LRESULT LRESULT DefWindowProcW(
502//
503// HWND hWnd,
504// UINT Msg,
505// WPARAM wParam,
506// LPARAM lParam
507//
508// );
509func XDefWindowProcW(t *TLS, _ ...interface{}) int64 {
510 panic(todo(""))
511}
512
513func XSendMessageTimeoutW(t *TLS, _ ...interface{}) int64 {
514 panic(todo(""))
515}
Note: See TracBrowser for help on using the repository browser.