Import upstream version 0.0~git20220520.bc2c85a
Debian Janitor
1 year, 11 months ago
105 | 105 | |
106 | 106 | // ARM contains the supported CPU features of the current ARM (32-bit) platform. |
107 | 107 | // All feature flags are false if: |
108 | // 1. the current platform is not arm, or | |
109 | // 2. the current operating system is not Linux. | |
108 | // 1. the current platform is not arm, or | |
109 | // 2. the current operating system is not Linux. | |
110 | 110 | var ARM struct { |
111 | 111 | _ CacheLinePad |
112 | 112 | HasSWP bool // SWP instruction support |
52 | 52 | // LookPath instead returns an error. |
53 | 53 | func LookPath(file string) (string, error) { |
54 | 54 | path, err := exec.LookPath(file) |
55 | if err != nil { | |
55 | if err != nil && !isGo119ErrDot(err) { | |
56 | 56 | return "", err |
57 | 57 | } |
58 | 58 | if filepath.Base(file) == file && !filepath.IsAbs(path) { |
0 | // Copyright 2022 The Go Authors. All rights reserved. | |
1 | // Use of this source code is governed by a BSD-style | |
2 | // license that can be found in the LICENSE file. | |
3 | ||
4 | //go:build !go1.19 | |
5 | // +build !go1.19 | |
6 | ||
7 | package execabs | |
8 | ||
9 | func isGo119ErrDot(err error) bool { | |
10 | return false | |
11 | } |
0 | // Copyright 2022 The Go Authors. All rights reserved. | |
1 | // Use of this source code is governed by a BSD-style | |
2 | // license that can be found in the LICENSE file. | |
3 | ||
4 | //go:build go1.19 | |
5 | // +build go1.19 | |
6 | ||
7 | package execabs | |
8 | ||
9 | import "strings" | |
10 | ||
11 | func isGo119ErrDot(err error) bool { | |
12 | // TODO: return errors.Is(err, exec.ErrDot) | |
13 | return strings.Contains(err.Error(), "current directory") | |
14 | } |
9 | 9 | (like syscall_plan9.go) and generates system call bodies. |
10 | 10 | The prototypes are marked by lines beginning with "//sys" |
11 | 11 | and read like func declarations if //sys is replaced by func, but: |
12 | * The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | * The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | * If the return parameter is an error number, it must be named errno. | |
12 | - The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | - The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | - If the return parameter is an error number, it must be named errno. | |
17 | 17 | |
18 | 18 | A line beginning with //sysnb is like //sys, except that the |
19 | 19 | goroutine will not be suspended during the execution of the system |
112 | 112 | |
113 | 113 | // use is a no-op, but the compiler cannot see that it is. |
114 | 114 | // Calling use(p) ensures that p is kept live until that point. |
115 | // | |
115 | 116 | //go:noescape |
116 | 117 | func use(p unsafe.Pointer) |
114 | 114 | var ioSync int64 |
115 | 115 | |
116 | 116 | //sys fd2path(fd int, buf []byte) (err error) |
117 | ||
117 | 118 | func Fd2path(fd int) (path string, err error) { |
118 | 119 | var buf [512]byte |
119 | 120 | |
125 | 126 | } |
126 | 127 | |
127 | 128 | //sys pipe(p *[2]int32) (err error) |
129 | ||
128 | 130 | func Pipe(p []int) (err error) { |
129 | 131 | if len(p) != 2 { |
130 | 132 | return syscall.ErrorString("bad arg in system call") |
179 | 181 | } |
180 | 182 | |
181 | 183 | //sys await(s []byte) (n int, err error) |
184 | ||
182 | 185 | func Await(w *Waitmsg) (err error) { |
183 | 186 | var buf [512]byte |
184 | 187 | var f [5][]byte |
300 | 303 | } |
301 | 304 | |
302 | 305 | //sys open(path string, mode int) (fd int, err error) |
306 | ||
303 | 307 | func Open(path string, mode int) (fd int, err error) { |
304 | 308 | fixwd() |
305 | 309 | return open(path, mode) |
306 | 310 | } |
307 | 311 | |
308 | 312 | //sys create(path string, mode int, perm uint32) (fd int, err error) |
313 | ||
309 | 314 | func Create(path string, mode int, perm uint32) (fd int, err error) { |
310 | 315 | fixwd() |
311 | 316 | return create(path, mode, perm) |
312 | 317 | } |
313 | 318 | |
314 | 319 | //sys remove(path string) (err error) |
320 | ||
315 | 321 | func Remove(path string) error { |
316 | 322 | fixwd() |
317 | 323 | return remove(path) |
318 | 324 | } |
319 | 325 | |
320 | 326 | //sys stat(path string, edir []byte) (n int, err error) |
327 | ||
321 | 328 | func Stat(path string, edir []byte) (n int, err error) { |
322 | 329 | fixwd() |
323 | 330 | return stat(path, edir) |
324 | 331 | } |
325 | 332 | |
326 | 333 | //sys bind(name string, old string, flag int) (err error) |
334 | ||
327 | 335 | func Bind(name string, old string, flag int) (err error) { |
328 | 336 | fixwd() |
329 | 337 | return bind(name, old, flag) |
330 | 338 | } |
331 | 339 | |
332 | 340 | //sys mount(fd int, afd int, old string, flag int, aname string) (err error) |
341 | ||
333 | 342 | func Mount(fd int, afd int, old string, flag int, aname string) (err error) { |
334 | 343 | fixwd() |
335 | 344 | return mount(fd, afd, old, flag, aname) |
336 | 345 | } |
337 | 346 | |
338 | 347 | //sys wstat(path string, edir []byte) (err error) |
348 | ||
339 | 349 | func Wstat(path string, edir []byte) (err error) { |
340 | 350 | fixwd() |
341 | 351 | return wstat(path, edir) |
89 | 89 | {"mlock", libc_mlock_trampoline_addr}, |
90 | 90 | {"mlockall", libc_mlockall_trampoline_addr}, |
91 | 91 | {"mmap", libc_mmap_trampoline_addr}, |
92 | {"mount", libc_mount_trampoline_addr}, | |
92 | 93 | {"mprotect", libc_mprotect_trampoline_addr}, |
93 | 94 | {"msync", libc_msync_trampoline_addr}, |
94 | 95 | {"munlock", libc_munlock_trampoline_addr}, |
89 | 89 | {"mlock", libc_mlock_trampoline_addr}, |
90 | 90 | {"mlockall", libc_mlockall_trampoline_addr}, |
91 | 91 | {"mmap", libc_mmap_trampoline_addr}, |
92 | {"mount", libc_mount_trampoline_addr}, | |
92 | 93 | {"mprotect", libc_mprotect_trampoline_addr}, |
93 | 94 | {"msync", libc_msync_trampoline_addr}, |
94 | 95 | {"munlock", libc_munlock_trampoline_addr}, |
7 | 7 | package unix |
8 | 8 | |
9 | 9 | import ( |
10 | "bytes" | |
11 | 10 | "unsafe" |
12 | 11 | ) |
13 | 12 | |
44 | 43 | |
45 | 44 | // Name returns the interface name associated with the Ifreq. |
46 | 45 | func (ifr *Ifreq) Name() string { |
47 | // BytePtrToString requires a NULL terminator or the program may crash. If | |
48 | // one is not present, just return the empty string. | |
49 | if !bytes.Contains(ifr.raw.Ifrn[:], []byte{0x00}) { | |
50 | return "" | |
51 | } | |
52 | ||
53 | return BytePtrToString(&ifr.raw.Ifrn[0]) | |
46 | return ByteSliceToString(ifr.raw.Ifrn[:]) | |
54 | 47 | } |
55 | 48 | |
56 | 49 | // According to netdevice(7), only AF_INET addresses are returned for numerous |
38 | 38 | } |
39 | 39 | |
40 | 40 | func TestIfreqName(t *testing.T) { |
41 | // Invalid ifreq (no NULL terminator), so expect empty string. | |
42 | var name [IFNAMSIZ]byte | |
43 | for i := range name { | |
44 | name[i] = 0xff | |
45 | } | |
46 | ||
47 | bad := &Ifreq{raw: ifreq{Ifrn: name}} | |
48 | if got := bad.Name(); got != "" { | |
49 | t.Fatalf("expected empty ifreq name, but got: %q", got) | |
50 | } | |
51 | ||
52 | 41 | // Valid ifreq, expect the hard-coded testIfreq name. |
53 | 42 | ifr := testIfreq(t) |
54 | 43 | if want, got := ifreqName, ifr.Name(); want != got { |
5 | 5 | // consts, funcs, and types into a common source file, per GOOS. |
6 | 6 | // |
7 | 7 | // Usage: |
8 | // $ mkmerge -out MERGED FILE [FILE ...] | |
8 | // | |
9 | // $ mkmerge -out MERGED FILE [FILE ...] | |
9 | 10 | // |
10 | 11 | // Example: |
11 | // # Remove all common consts, funcs, and types from zerrors_linux_*.go | |
12 | // # and write the common code into zerrors_linux.go | |
13 | // $ mkmerge -out zerrors_linux.go zerrors_linux_*.go | |
12 | // | |
13 | // # Remove all common consts, funcs, and types from zerrors_linux_*.go | |
14 | // # and write the common code into zerrors_linux.go | |
15 | // $ mkmerge -out zerrors_linux.go zerrors_linux_*.go | |
14 | 16 | // |
15 | 17 | // mkmerge performs the merge in the following steps: |
16 | // 1. Construct the set of common code that is identical in all | |
17 | // architecture-specific files. | |
18 | // 2. Write this common code to the merged file. | |
19 | // 3. Remove the common code from all architecture-specific files. | |
18 | // 1. Construct the set of common code that is identical in all | |
19 | // architecture-specific files. | |
20 | // 2. Write this common code to the merged file. | |
21 | // 3. Remove the common code from all architecture-specific files. | |
20 | 22 | package main |
21 | 23 | |
22 | 24 | import ( |
57 | 57 | && apt-get clean \ |
58 | 58 | && rm -rf /var/lib/apt/lists/* |
59 | 59 | |
60 | # Only for loong64, add patch and build golang | |
61 | RUN git clone https://go.googlesource.com/go --branch go1.18 /git/go \ | |
62 | && cd /git/loong64-patches && git checkout go-v1.18 && cd /git/go && git am /git/loong64-patches/*.patch \ | |
63 | && rm -rf /git/loong64-patches && cd /git/go/src && ./make.bash | |
60 | # Only for loong64, build Go from master until 1.19 is released | |
61 | RUN git clone https://go.googlesource.com/go --branch master /git/go \ | |
62 | && cd /git/go/src && ./make.bash | |
64 | 63 | |
65 | 64 | ENV PATH /git/go/bin:$PATH |
66 | 65 |
5 | 5 | // +build ignore |
6 | 6 | |
7 | 7 | // mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go. |
8 | //This program must be run after mksyscall.go. | |
8 | // This program must be run after mksyscall.go. | |
9 | 9 | package main |
10 | 10 | |
11 | 11 | import ( |
100 | 100 | convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`) |
101 | 101 | b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte")) |
102 | 102 | |
103 | // Convert [n]int8 to [n]byte in Statvfs_t members to simplify | |
103 | // Convert [n]int8 to [n]byte in Statvfs_t and Statfs_t members to simplify | |
104 | 104 | // conversion to string. |
105 | convertStatvfsRegex := regexp.MustCompile(`((Fstype|Mnton|Mntfrom)name)(\s+)\[(\d+)\]int8`) | |
105 | convertStatvfsRegex := regexp.MustCompile(`(([Ff]stype|[Mm]nton|[Mm]ntfrom)name|mntfromspec)(\s+)\[(\d+)\]int8`) | |
106 | 106 | b = convertStatvfsRegex.ReplaceAll(b, []byte("$1$3[$4]byte")) |
107 | 107 | |
108 | 108 | // Convert []int8 to []byte in device mapper ioctl interface |
9 | 9 | (like syscall_darwin.go) and generates system call bodies. |
10 | 10 | The prototypes are marked by lines beginning with "//sys" |
11 | 11 | and read like func declarations if //sys is replaced by func, but: |
12 | * The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | * The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | * If the return parameter is an error number, it must be named errno. | |
12 | - The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | - The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | - If the return parameter is an error number, it must be named errno. | |
17 | 17 | |
18 | 18 | A line beginning with //sysnb is like //sys, except that the |
19 | 19 | goroutine will not be suspended during the execution of the system |
9 | 9 | (like syscall_aix.go) and generates system call bodies. |
10 | 10 | The prototypes are marked by lines beginning with "//sys" |
11 | 11 | and read like func declarations if //sys is replaced by func, but: |
12 | * The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | * The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | * If the return parameter is an error number, it must be named err. | |
17 | * If go func name needs to be different than its libc name, | |
18 | * or the function is not in libc, name could be specified | |
19 | * at the end, after "=" sign, like | |
20 | //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt | |
12 | - The parameter lists must give a name for each argument. | |
13 | This includes return parameters. | |
14 | - The parameter lists must give a type for each argument: | |
15 | the (x, y, z int) shorthand is not allowed. | |
16 | - If the return parameter is an error number, it must be named err. | |
17 | - If go func name needs to be different than its libc name, | |
18 | - or the function is not in libc, name could be specified | |
19 | - at the end, after "=" sign, like | |
20 | //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt | |
21 | 21 | */ |
22 | 22 | package main |
23 | 23 |
36 | 36 | } |
37 | 37 | |
38 | 38 | //sys utimes(path string, times *[2]Timeval) (err error) |
39 | ||
39 | 40 | func Utimes(path string, tv []Timeval) error { |
40 | 41 | if len(tv) != 2 { |
41 | 42 | return EINVAL |
44 | 45 | } |
45 | 46 | |
46 | 47 | //sys utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error) |
48 | ||
47 | 49 | func UtimesNano(path string, ts []Timespec) error { |
48 | 50 | if len(ts) != 2 { |
49 | 51 | return EINVAL |
299 | 301 | } |
300 | 302 | |
301 | 303 | //sys getdirent(fd int, buf []byte) (n int, err error) |
304 | ||
302 | 305 | func Getdents(fd int, buf []byte) (n int, err error) { |
303 | 306 | return getdirent(fd, buf) |
304 | 307 | } |
305 | 308 | |
306 | 309 | //sys wait4(pid Pid_t, status *_C_int, options int, rusage *Rusage) (wpid Pid_t, err error) |
310 | ||
307 | 311 | func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) { |
308 | 312 | var status _C_int |
309 | 313 | var r Pid_t |
371 | 375 | //sys fcntl(fd int, cmd int, arg int) (val int, err error) |
372 | 376 | |
373 | 377 | //sys fsyncRange(fd int, how int, start int64, length int64) (err error) = fsync_range |
378 | ||
374 | 379 | func Fsync(fd int) error { |
375 | 380 | return fsyncRange(fd, O_SYNC, 0, 0) |
376 | 381 | } |
535 | 540 | //sys Getsystemcfg(label int) (n uint64) |
536 | 541 | |
537 | 542 | //sys umount(target string) (err error) |
543 | ||
538 | 544 | func Unmount(target string, flags int) (err error) { |
539 | 545 | if flags != 0 { |
540 | 546 | // AIX doesn't have any flags for umount. |
503 | 503 | //sys Mkdirat(dirfd int, path string, mode uint32) (err error) |
504 | 504 | //sys Mkfifo(path string, mode uint32) (err error) |
505 | 505 | //sys Mknod(path string, mode uint32, dev int) (err error) |
506 | //sys Mount(fsType string, dir string, flags int, data unsafe.Pointer) (err error) | |
506 | 507 | //sys Open(path string, mode int, perm uint32) (fd int, err error) |
507 | 508 | //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) |
508 | 509 | //sys Pathconf(path string, name int) (val int, err error) |
571 | 572 | // Nfssvc |
572 | 573 | // Getfh |
573 | 574 | // Quotactl |
574 | // Mount | |
575 | 575 | // Csops |
576 | 576 | // Waitid |
577 | 577 | // Add_profil |
124 | 124 | } |
125 | 125 | |
126 | 126 | //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) |
127 | ||
127 | 128 | func pread(fd int, p []byte, offset int64) (n int, err error) { |
128 | 129 | return extpread(fd, p, 0, offset) |
129 | 130 | } |
130 | 131 | |
131 | 132 | //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) |
133 | ||
132 | 134 | func pwrite(fd int, p []byte, offset int64) (n int, err error) { |
133 | 135 | return extpwrite(fd, p, 0, offset) |
134 | 136 | } |
511 | 511 | // |
512 | 512 | // Server example: |
513 | 513 | // |
514 | // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM) | |
515 | // _ = unix.Bind(fd, &unix.SockaddrRFCOMM{ | |
516 | // Channel: 1, | |
517 | // Addr: [6]uint8{0, 0, 0, 0, 0, 0}, // BDADDR_ANY or 00:00:00:00:00:00 | |
518 | // }) | |
519 | // _ = Listen(fd, 1) | |
520 | // nfd, sa, _ := Accept(fd) | |
521 | // fmt.Printf("conn addr=%v fd=%d", sa.(*unix.SockaddrRFCOMM).Addr, nfd) | |
522 | // Read(nfd, buf) | |
514 | // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM) | |
515 | // _ = unix.Bind(fd, &unix.SockaddrRFCOMM{ | |
516 | // Channel: 1, | |
517 | // Addr: [6]uint8{0, 0, 0, 0, 0, 0}, // BDADDR_ANY or 00:00:00:00:00:00 | |
518 | // }) | |
519 | // _ = Listen(fd, 1) | |
520 | // nfd, sa, _ := Accept(fd) | |
521 | // fmt.Printf("conn addr=%v fd=%d", sa.(*unix.SockaddrRFCOMM).Addr, nfd) | |
522 | // Read(nfd, buf) | |
523 | 523 | // |
524 | 524 | // Client example: |
525 | 525 | // |
526 | // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM) | |
527 | // _ = Connect(fd, &SockaddrRFCOMM{ | |
528 | // Channel: 1, | |
529 | // Addr: [6]byte{0x11, 0x22, 0x33, 0xaa, 0xbb, 0xcc}, // CC:BB:AA:33:22:11 | |
530 | // }) | |
531 | // Write(fd, []byte(`hello`)) | |
526 | // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM) | |
527 | // _ = Connect(fd, &SockaddrRFCOMM{ | |
528 | // Channel: 1, | |
529 | // Addr: [6]byte{0x11, 0x22, 0x33, 0xaa, 0xbb, 0xcc}, // CC:BB:AA:33:22:11 | |
530 | // }) | |
531 | // Write(fd, []byte(`hello`)) | |
532 | 532 | type SockaddrRFCOMM struct { |
533 | 533 | // Addr represents a bluetooth address, byte ordering is little-endian. |
534 | 534 | Addr [6]uint8 |
555 | 555 | // The SockaddrCAN struct must be bound to the socket file descriptor |
556 | 556 | // using Bind before the CAN socket can be used. |
557 | 557 | // |
558 | // // Read one raw CAN frame | |
559 | // fd, _ := Socket(AF_CAN, SOCK_RAW, CAN_RAW) | |
560 | // addr := &SockaddrCAN{Ifindex: index} | |
561 | // Bind(fd, addr) | |
562 | // frame := make([]byte, 16) | |
563 | // Read(fd, frame) | |
558 | // // Read one raw CAN frame | |
559 | // fd, _ := Socket(AF_CAN, SOCK_RAW, CAN_RAW) | |
560 | // addr := &SockaddrCAN{Ifindex: index} | |
561 | // Bind(fd, addr) | |
562 | // frame := make([]byte, 16) | |
563 | // Read(fd, frame) | |
564 | 564 | // |
565 | 565 | // The full SocketCAN documentation can be found in the linux kernel |
566 | 566 | // archives at: https://www.kernel.org/doc/Documentation/networking/can.txt |
631 | 631 | // Here is an example of using an AF_ALG socket with SHA1 hashing. |
632 | 632 | // The initial socket setup process is as follows: |
633 | 633 | // |
634 | // // Open a socket to perform SHA1 hashing. | |
635 | // fd, _ := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0) | |
636 | // addr := &unix.SockaddrALG{Type: "hash", Name: "sha1"} | |
637 | // unix.Bind(fd, addr) | |
638 | // // Note: unix.Accept does not work at this time; must invoke accept() | |
639 | // // manually using unix.Syscall. | |
640 | // hashfd, _, _ := unix.Syscall(unix.SYS_ACCEPT, uintptr(fd), 0, 0) | |
634 | // // Open a socket to perform SHA1 hashing. | |
635 | // fd, _ := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0) | |
636 | // addr := &unix.SockaddrALG{Type: "hash", Name: "sha1"} | |
637 | // unix.Bind(fd, addr) | |
638 | // // Note: unix.Accept does not work at this time; must invoke accept() | |
639 | // // manually using unix.Syscall. | |
640 | // hashfd, _, _ := unix.Syscall(unix.SYS_ACCEPT, uintptr(fd), 0, 0) | |
641 | 641 | // |
642 | 642 | // Once a file descriptor has been returned from Accept, it may be used to |
643 | 643 | // perform SHA1 hashing. The descriptor is not safe for concurrent use, but |
646 | 646 | // When hashing a small byte slice or string, a single Write and Read may |
647 | 647 | // be used: |
648 | 648 | // |
649 | // // Assume hashfd is already configured using the setup process. | |
650 | // hash := os.NewFile(hashfd, "sha1") | |
651 | // // Hash an input string and read the results. Each Write discards | |
652 | // // previous hash state. Read always reads the current state. | |
653 | // b := make([]byte, 20) | |
654 | // for i := 0; i < 2; i++ { | |
655 | // io.WriteString(hash, "Hello, world.") | |
656 | // hash.Read(b) | |
657 | // fmt.Println(hex.EncodeToString(b)) | |
658 | // } | |
659 | // // Output: | |
660 | // // 2ae01472317d1935a84797ec1983ae243fc6aa28 | |
661 | // // 2ae01472317d1935a84797ec1983ae243fc6aa28 | |
649 | // // Assume hashfd is already configured using the setup process. | |
650 | // hash := os.NewFile(hashfd, "sha1") | |
651 | // // Hash an input string and read the results. Each Write discards | |
652 | // // previous hash state. Read always reads the current state. | |
653 | // b := make([]byte, 20) | |
654 | // for i := 0; i < 2; i++ { | |
655 | // io.WriteString(hash, "Hello, world.") | |
656 | // hash.Read(b) | |
657 | // fmt.Println(hex.EncodeToString(b)) | |
658 | // } | |
659 | // // Output: | |
660 | // // 2ae01472317d1935a84797ec1983ae243fc6aa28 | |
661 | // // 2ae01472317d1935a84797ec1983ae243fc6aa28 | |
662 | 662 | // |
663 | 663 | // For hashing larger byte slices, or byte streams such as those read from |
664 | 664 | // a file or socket, use Sendto with MSG_MORE to instruct the kernel to update |
665 | 665 | // the hash digest instead of creating a new one for a given chunk and finalizing it. |
666 | 666 | // |
667 | // // Assume hashfd and addr are already configured using the setup process. | |
668 | // hash := os.NewFile(hashfd, "sha1") | |
669 | // // Hash the contents of a file. | |
670 | // f, _ := os.Open("/tmp/linux-4.10-rc7.tar.xz") | |
671 | // b := make([]byte, 4096) | |
672 | // for { | |
673 | // n, err := f.Read(b) | |
674 | // if err == io.EOF { | |
675 | // break | |
676 | // } | |
677 | // unix.Sendto(hashfd, b[:n], unix.MSG_MORE, addr) | |
678 | // } | |
679 | // hash.Read(b) | |
680 | // fmt.Println(hex.EncodeToString(b)) | |
681 | // // Output: 85cdcad0c06eef66f805ecce353bec9accbeecc5 | |
667 | // // Assume hashfd and addr are already configured using the setup process. | |
668 | // hash := os.NewFile(hashfd, "sha1") | |
669 | // // Hash the contents of a file. | |
670 | // f, _ := os.Open("/tmp/linux-4.10-rc7.tar.xz") | |
671 | // b := make([]byte, 4096) | |
672 | // for { | |
673 | // n, err := f.Read(b) | |
674 | // if err == io.EOF { | |
675 | // break | |
676 | // } | |
677 | // unix.Sendto(hashfd, b[:n], unix.MSG_MORE, addr) | |
678 | // } | |
679 | // hash.Read(b) | |
680 | // fmt.Println(hex.EncodeToString(b)) | |
681 | // // Output: 85cdcad0c06eef66f805ecce353bec9accbeecc5 | |
682 | 682 | // |
683 | 683 | // For more information, see: http://www.chronox.de/crypto-API/crypto/userspace-if.html. |
684 | 684 | type SockaddrALG struct { |
4 | 4 | package unix_test |
5 | 5 | |
6 | 6 | import ( |
7 | "bytes" | |
8 | 7 | "os" |
9 | 8 | "testing" |
10 | 9 | |
38 | 37 | t.Fatalf("IoctlGetPtmget: %v\n", err) |
39 | 38 | } |
40 | 39 | |
41 | t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)])) | |
40 | t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, unix.ByteSliceToString(ptm.Sn[:])) | |
42 | 41 | } |
43 | 42 | |
44 | 43 | func TestStatvfs(t *testing.T) { |
80 | 80 | } |
81 | 81 | |
82 | 82 | //sysnb pipe2(p *[2]_C_int, flags int) (err error) |
83 | ||
83 | 84 | func Pipe2(p []int, flags int) error { |
84 | 85 | if len(p) != 2 { |
85 | 86 | return EINVAL |
94 | 95 | } |
95 | 96 | |
96 | 97 | //sys Getdents(fd int, buf []byte) (n int, err error) |
98 | ||
97 | 99 | func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { |
98 | 100 | n, err = Getdents(fd, buf) |
99 | 101 | if err != nil || basep == nil { |
4 | 4 | // +build 386,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build amd64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build arm,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build arm64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build loong64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build mips,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build mips64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build mips64le,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build mipsle,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build ppc,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build ppc64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build ppc64le,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build riscv64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build s390x,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
4 | 4 | // +build sparc64,linux |
5 | 5 | |
6 | 6 | // Code generated by cmd/cgo -godefs; DO NOT EDIT. |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go | |
7 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go | |
8 | 8 | |
9 | 9 | package unix |
10 | 10 |
1642 | 1642 | |
1643 | 1643 | // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT |
1644 | 1644 | |
1645 | func Mount(fsType string, dir string, flags int, data unsafe.Pointer) (err error) { | |
1646 | var _p0 *byte | |
1647 | _p0, err = BytePtrFromString(fsType) | |
1648 | if err != nil { | |
1649 | return | |
1650 | } | |
1651 | var _p1 *byte | |
1652 | _p1, err = BytePtrFromString(dir) | |
1653 | if err != nil { | |
1654 | return | |
1655 | } | |
1656 | _, _, e1 := syscall_syscall6(libc_mount_trampoline_addr, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flags), uintptr(data), 0, 0) | |
1657 | if e1 != 0 { | |
1658 | err = errnoErr(e1) | |
1659 | } | |
1660 | return | |
1661 | } | |
1662 | ||
1663 | var libc_mount_trampoline_addr uintptr | |
1664 | ||
1665 | //go:cgo_import_dynamic libc_mount mount "/usr/lib/libSystem.B.dylib" | |
1666 | ||
1667 | // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT | |
1668 | ||
1645 | 1669 | func Open(path string, mode int, perm uint32) (fd int, err error) { |
1646 | 1670 | var _p0 *byte |
1647 | 1671 | _p0, err = BytePtrFromString(path) |
599 | 599 | GLOBL ·libc_mknod_trampoline_addr(SB), RODATA, $8 |
600 | 600 | DATA ·libc_mknod_trampoline_addr(SB)/8, $libc_mknod_trampoline<>(SB) |
601 | 601 | |
602 | TEXT libc_mount_trampoline<>(SB),NOSPLIT,$0-0 | |
603 | JMP libc_mount(SB) | |
604 | ||
605 | GLOBL ·libc_mount_trampoline_addr(SB), RODATA, $8 | |
606 | DATA ·libc_mount_trampoline_addr(SB)/8, $libc_mount_trampoline<>(SB) | |
607 | ||
602 | 608 | TEXT libc_open_trampoline<>(SB),NOSPLIT,$0-0 |
603 | 609 | JMP libc_open(SB) |
604 | 610 |
1642 | 1642 | |
1643 | 1643 | // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT |
1644 | 1644 | |
1645 | func Mount(fsType string, dir string, flags int, data unsafe.Pointer) (err error) { | |
1646 | var _p0 *byte | |
1647 | _p0, err = BytePtrFromString(fsType) | |
1648 | if err != nil { | |
1649 | return | |
1650 | } | |
1651 | var _p1 *byte | |
1652 | _p1, err = BytePtrFromString(dir) | |
1653 | if err != nil { | |
1654 | return | |
1655 | } | |
1656 | _, _, e1 := syscall_syscall6(libc_mount_trampoline_addr, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flags), uintptr(data), 0, 0) | |
1657 | if e1 != 0 { | |
1658 | err = errnoErr(e1) | |
1659 | } | |
1660 | return | |
1661 | } | |
1662 | ||
1663 | var libc_mount_trampoline_addr uintptr | |
1664 | ||
1665 | //go:cgo_import_dynamic libc_mount mount "/usr/lib/libSystem.B.dylib" | |
1666 | ||
1667 | // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT | |
1668 | ||
1645 | 1669 | func Open(path string, mode int, perm uint32) (fd int, err error) { |
1646 | 1670 | var _p0 *byte |
1647 | 1671 | _p0, err = BytePtrFromString(path) |
599 | 599 | GLOBL ·libc_mknod_trampoline_addr(SB), RODATA, $8 |
600 | 600 | DATA ·libc_mknod_trampoline_addr(SB)/8, $libc_mknod_trampoline<>(SB) |
601 | 601 | |
602 | TEXT libc_mount_trampoline<>(SB),NOSPLIT,$0-0 | |
603 | JMP libc_mount(SB) | |
604 | ||
605 | GLOBL ·libc_mount_trampoline_addr(SB), RODATA, $8 | |
606 | DATA ·libc_mount_trampoline_addr(SB)/8, $libc_mount_trampoline<>(SB) | |
607 | ||
602 | 608 | TEXT libc_open_trampoline<>(SB),NOSPLIT,$0-0 |
603 | 609 | JMP libc_open(SB) |
604 | 610 |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build 386 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build amd64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build arm && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build arm64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build loong64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build mips && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build mips64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build mips64le && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build mipsle && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build ppc && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build ppc64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build ppc64le && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build riscv64 && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build s390x && linux |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go | |
0 | // cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go | |
1 | 1 | // Code generated by the command above; see README.md. DO NOT EDIT. |
2 | 2 | |
3 | 3 | //go:build sparc64 && linux |
93 | 93 | F_namemax uint32 |
94 | 94 | F_owner uint32 |
95 | 95 | F_ctime uint64 |
96 | F_fstypename [16]int8 | |
97 | F_mntonname [90]int8 | |
98 | F_mntfromname [90]int8 | |
99 | F_mntfromspec [90]int8 | |
96 | F_fstypename [16]byte | |
97 | F_mntonname [90]byte | |
98 | F_mntfromname [90]byte | |
99 | F_mntfromspec [90]byte | |
100 | 100 | Pad_cgo_0 [2]byte |
101 | 101 | Mount_info [160]byte |
102 | 102 | } |
95 | 95 | F_namemax uint32 |
96 | 96 | F_owner uint32 |
97 | 97 | F_ctime uint64 |
98 | F_fstypename [16]int8 | |
99 | F_mntonname [90]int8 | |
100 | F_mntfromname [90]int8 | |
101 | F_mntfromspec [90]int8 | |
98 | F_fstypename [16]byte | |
99 | F_mntonname [90]byte | |
100 | F_mntfromname [90]byte | |
101 | F_mntfromspec [90]byte | |
102 | 102 | _ [2]byte |
103 | 103 | Mount_info [160]byte |
104 | 104 | } |
97 | 97 | F_namemax uint32 |
98 | 98 | F_owner uint32 |
99 | 99 | F_ctime uint64 |
100 | F_fstypename [16]int8 | |
101 | F_mntonname [90]int8 | |
102 | F_mntfromname [90]int8 | |
103 | F_mntfromspec [90]int8 | |
100 | F_fstypename [16]byte | |
101 | F_mntonname [90]byte | |
102 | F_mntfromname [90]byte | |
103 | F_mntfromspec [90]byte | |
104 | 104 | _ [2]byte |
105 | 105 | Mount_info [160]byte |
106 | 106 | } |
93 | 93 | F_namemax uint32 |
94 | 94 | F_owner uint32 |
95 | 95 | F_ctime uint64 |
96 | F_fstypename [16]int8 | |
97 | F_mntonname [90]int8 | |
98 | F_mntfromname [90]int8 | |
99 | F_mntfromspec [90]int8 | |
96 | F_fstypename [16]byte | |
97 | F_mntonname [90]byte | |
98 | F_mntfromname [90]byte | |
99 | F_mntfromspec [90]byte | |
100 | 100 | _ [2]byte |
101 | 101 | Mount_info [160]byte |
102 | 102 | } |
93 | 93 | F_namemax uint32 |
94 | 94 | F_owner uint32 |
95 | 95 | F_ctime uint64 |
96 | F_fstypename [16]int8 | |
97 | F_mntonname [90]int8 | |
98 | F_mntfromname [90]int8 | |
99 | F_mntfromspec [90]int8 | |
96 | F_fstypename [16]byte | |
97 | F_mntonname [90]byte | |
98 | F_mntfromname [90]byte | |
99 | F_mntfromspec [90]byte | |
100 | 100 | _ [2]byte |
101 | 101 | Mount_info [160]byte |
102 | 102 | } |
14 | 14 | // in http://msdn.microsoft.com/en-us/library/ms880421. |
15 | 15 | // This function returns "" (2 double quotes) if s is empty. |
16 | 16 | // Alternatively, these transformations are done: |
17 | // - every back slash (\) is doubled, but only if immediately | |
18 | // followed by double quote ("); | |
19 | // - every double quote (") is escaped by back slash (\); | |
20 | // - finally, s is wrapped with double quotes (arg -> "arg"), | |
21 | // but only if there is space or tab inside s. | |
17 | // - every back slash (\) is doubled, but only if immediately | |
18 | // followed by double quote ("); | |
19 | // - every double quote (") is escaped by back slash (\); | |
20 | // - finally, s is wrapped with double quotes (arg -> "arg"), | |
21 | // but only if there is space or tab inside s. | |
22 | 22 | func EscapeArg(s string) string { |
23 | 23 | if len(s) == 0 { |
24 | 24 | return "\"\"" |
11 | 11 | The prototypes are marked by lines beginning with "//sys" and read |
12 | 12 | like func declarations if //sys is replaced by func, but: |
13 | 13 | |
14 | * The parameter lists must give a name for each argument. This | |
15 | includes return parameters. | |
16 | ||
17 | * The parameter lists must give a type for each argument: | |
18 | the (x, y, z int) shorthand is not allowed. | |
19 | ||
20 | * If the return parameter is an error number, it must be named err. | |
21 | ||
22 | * If go func name needs to be different from its winapi dll name, | |
23 | the winapi name could be specified at the end, after "=" sign, like | |
24 | //sys LoadLibrary(libname string) (handle uint32, err error) = LoadLibraryA | |
25 | ||
26 | * Each function that returns err needs to supply a condition, that | |
27 | return value of winapi will be tested against to detect failure. | |
28 | This would set err to windows "last-error", otherwise it will be nil. | |
29 | The value can be provided at end of //sys declaration, like | |
30 | //sys LoadLibrary(libname string) (handle uint32, err error) [failretval==-1] = LoadLibraryA | |
31 | and is [failretval==0] by default. | |
32 | ||
33 | * If the function name ends in a "?", then the function not existing is non- | |
34 | fatal, and an error will be returned instead of panicking. | |
14 | - The parameter lists must give a name for each argument. This | |
15 | includes return parameters. | |
16 | ||
17 | - The parameter lists must give a type for each argument: | |
18 | the (x, y, z int) shorthand is not allowed. | |
19 | ||
20 | - If the return parameter is an error number, it must be named err. | |
21 | ||
22 | - If go func name needs to be different from its winapi dll name, | |
23 | the winapi name could be specified at the end, after "=" sign, like | |
24 | //sys LoadLibrary(libname string) (handle uint32, err error) = LoadLibraryA | |
25 | ||
26 | - Each function that returns err needs to supply a condition, that | |
27 | return value of winapi will be tested against to detect failure. | |
28 | This would set err to windows "last-error", otherwise it will be nil. | |
29 | The value can be provided at end of //sys declaration, like | |
30 | //sys LoadLibrary(libname string) (handle uint32, err error) [failretval==-1] = LoadLibraryA | |
31 | and is [failretval==0] by default. | |
32 | ||
33 | - If the function name ends in a "?", then the function not existing is non- | |
34 | fatal, and an error will be returned instead of panicking. | |
35 | 35 | |
36 | 36 | Usage: |
37 | ||
37 | 38 | mkwinsyscall [flags] [path ...] |
38 | 39 | |
39 | 40 | The flags are: |
41 | ||
40 | 42 | -output |
41 | 43 | Specify output file name (outputs to console if blank). |
42 | 44 | -trace |
19 | 19 | // log.Fatal(err) |
20 | 20 | // } |
21 | 21 | // fmt.Printf("Windows system root is %q\n", s) |
22 | // | |
23 | 22 | package registry |
24 | 23 | |
25 | 24 | import ( |
5 | 5 | // +build windows |
6 | 6 | |
7 | 7 | // Package debug provides facilities to execute svc.Handler on console. |
8 | // | |
9 | 8 | package debug |
10 | 9 | |
11 | 10 | import ( |
5 | 5 | // +build windows |
6 | 6 | |
7 | 7 | // Package eventlog implements access to Windows event log. |
8 | // | |
9 | 8 | package eventlog |
10 | 9 | |
11 | 10 | import ( |
11 | 11 | // stop / start / pause / continue any service, and how to |
12 | 12 | // write to event log. It also shows how to use debug |
13 | 13 | // facilities available in debug package. |
14 | // | |
15 | 14 | package main |
16 | 15 | |
17 | 16 | import ( |
8 | 8 | // It can be used to install and remove them. It can also start, |
9 | 9 | // stop and pause them. The package can query / change current |
10 | 10 | // service state and config parameters. |
11 | // | |
12 | 11 | package mgr |
13 | 12 | |
14 | 13 | import ( |