Codebase list golang-golang-x-sys / a25585f0-3e1a-4621-9475-874509830041/upstream/sid
Import upstream version 0.0~git20220503.988cb79 Debian Janitor 2 years ago
24 changed file(s) with 165 addition(s) and 120 deletion(s). Raw diff Collapse all Expand all
105105
106106 // ARM contains the supported CPU features of the current ARM (32-bit) platform.
107107 // 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.
110110 var ARM struct {
111111 _ CacheLinePad
112112 HasSWP bool // SWP instruction support
5252 // LookPath instead returns an error.
5353 func LookPath(file string) (string, error) {
5454 path, err := exec.LookPath(file)
55 if err != nil {
55 if err != nil && !isGo119ErrDot(err) {
5656 return "", err
5757 }
5858 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 }
99 (like syscall_plan9.go) and generates system call bodies.
1010 The prototypes are marked by lines beginning with "//sys"
1111 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.
1717
1818 A line beginning with //sysnb is like //sys, except that the
1919 goroutine will not be suspended during the execution of the system
112112
113113 // use is a no-op, but the compiler cannot see that it is.
114114 // Calling use(p) ensures that p is kept live until that point.
115 //
115116 //go:noescape
116117 func use(p unsafe.Pointer)
114114 var ioSync int64
115115
116116 //sys fd2path(fd int, buf []byte) (err error)
117
117118 func Fd2path(fd int) (path string, err error) {
118119 var buf [512]byte
119120
125126 }
126127
127128 //sys pipe(p *[2]int32) (err error)
129
128130 func Pipe(p []int) (err error) {
129131 if len(p) != 2 {
130132 return syscall.ErrorString("bad arg in system call")
179181 }
180182
181183 //sys await(s []byte) (n int, err error)
184
182185 func Await(w *Waitmsg) (err error) {
183186 var buf [512]byte
184187 var f [5][]byte
300303 }
301304
302305 //sys open(path string, mode int) (fd int, err error)
306
303307 func Open(path string, mode int) (fd int, err error) {
304308 fixwd()
305309 return open(path, mode)
306310 }
307311
308312 //sys create(path string, mode int, perm uint32) (fd int, err error)
313
309314 func Create(path string, mode int, perm uint32) (fd int, err error) {
310315 fixwd()
311316 return create(path, mode, perm)
312317 }
313318
314319 //sys remove(path string) (err error)
320
315321 func Remove(path string) error {
316322 fixwd()
317323 return remove(path)
318324 }
319325
320326 //sys stat(path string, edir []byte) (n int, err error)
327
321328 func Stat(path string, edir []byte) (n int, err error) {
322329 fixwd()
323330 return stat(path, edir)
324331 }
325332
326333 //sys bind(name string, old string, flag int) (err error)
334
327335 func Bind(name string, old string, flag int) (err error) {
328336 fixwd()
329337 return bind(name, old, flag)
330338 }
331339
332340 //sys mount(fd int, afd int, old string, flag int, aname string) (err error)
341
333342 func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
334343 fixwd()
335344 return mount(fd, afd, old, flag, aname)
336345 }
337346
338347 //sys wstat(path string, edir []byte) (err error)
348
339349 func Wstat(path string, edir []byte) (err error) {
340350 fixwd()
341351 return wstat(path, edir)
55 // consts, funcs, and types into a common source file, per GOOS.
66 //
77 // Usage:
8 // $ mkmerge -out MERGED FILE [FILE ...]
8 //
9 // $ mkmerge -out MERGED FILE [FILE ...]
910 //
1011 // 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
1416 //
1517 // 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.
2022 package main
2123
2224 import (
55 // +build ignore
66
77 // 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.
99 package main
1010
1111 import (
99 (like syscall_darwin.go) and generates system call bodies.
1010 The prototypes are marked by lines beginning with "//sys"
1111 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.
1717
1818 A line beginning with //sysnb is like //sys, except that the
1919 goroutine will not be suspended during the execution of the system
99 (like syscall_aix.go) and generates system call bodies.
1010 The prototypes are marked by lines beginning with "//sys"
1111 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
2121 */
2222 package main
2323
3636 }
3737
3838 //sys utimes(path string, times *[2]Timeval) (err error)
39
3940 func Utimes(path string, tv []Timeval) error {
4041 if len(tv) != 2 {
4142 return EINVAL
4445 }
4546
4647 //sys utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
48
4749 func UtimesNano(path string, ts []Timespec) error {
4850 if len(ts) != 2 {
4951 return EINVAL
299301 }
300302
301303 //sys getdirent(fd int, buf []byte) (n int, err error)
304
302305 func Getdents(fd int, buf []byte) (n int, err error) {
303306 return getdirent(fd, buf)
304307 }
305308
306309 //sys wait4(pid Pid_t, status *_C_int, options int, rusage *Rusage) (wpid Pid_t, err error)
310
307311 func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
308312 var status _C_int
309313 var r Pid_t
371375 //sys fcntl(fd int, cmd int, arg int) (val int, err error)
372376
373377 //sys fsyncRange(fd int, how int, start int64, length int64) (err error) = fsync_range
378
374379 func Fsync(fd int) error {
375380 return fsyncRange(fd, O_SYNC, 0, 0)
376381 }
535540 //sys Getsystemcfg(label int) (n uint64)
536541
537542 //sys umount(target string) (err error)
543
538544 func Unmount(target string, flags int) (err error) {
539545 if flags != 0 {
540546 // AIX doesn't have any flags for umount.
124124 }
125125
126126 //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error)
127
127128 func pread(fd int, p []byte, offset int64) (n int, err error) {
128129 return extpread(fd, p, 0, offset)
129130 }
130131
131132 //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error)
133
132134 func pwrite(fd int, p []byte, offset int64) (n int, err error) {
133135 return extpwrite(fd, p, 0, offset)
134136 }
511511 //
512512 // Server example:
513513 //
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)
523523 //
524524 // Client example:
525525 //
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`))
532532 type SockaddrRFCOMM struct {
533533 // Addr represents a bluetooth address, byte ordering is little-endian.
534534 Addr [6]uint8
555555 // The SockaddrCAN struct must be bound to the socket file descriptor
556556 // using Bind before the CAN socket can be used.
557557 //
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)
564564 //
565565 // The full SocketCAN documentation can be found in the linux kernel
566566 // archives at: https://www.kernel.org/doc/Documentation/networking/can.txt
631631 // Here is an example of using an AF_ALG socket with SHA1 hashing.
632632 // The initial socket setup process is as follows:
633633 //
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)
641641 //
642642 // Once a file descriptor has been returned from Accept, it may be used to
643643 // perform SHA1 hashing. The descriptor is not safe for concurrent use, but
646646 // When hashing a small byte slice or string, a single Write and Read may
647647 // be used:
648648 //
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
662662 //
663663 // For hashing larger byte slices, or byte streams such as those read from
664664 // a file or socket, use Sendto with MSG_MORE to instruct the kernel to update
665665 // the hash digest instead of creating a new one for a given chunk and finalizing it.
666666 //
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
682682 //
683683 // For more information, see: http://www.chronox.de/crypto-API/crypto/userspace-if.html.
684684 type SockaddrALG struct {
8080 }
8181
8282 //sysnb pipe2(p *[2]_C_int, flags int) (err error)
83
8384 func Pipe2(p []int, flags int) error {
8485 if len(p) != 2 {
8586 return EINVAL
9495 }
9596
9697 //sys Getdents(fd int, buf []byte) (n int, err error)
98
9799 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
98100 n, err = Getdents(fd, buf)
99101 if err != nil || basep == nil {
1414 // in http://msdn.microsoft.com/en-us/library/ms880421.
1515 // This function returns "" (2 double quotes) if s is empty.
1616 // 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.
2222 func EscapeArg(s string) string {
2323 if len(s) == 0 {
2424 return "\"\""
1111 The prototypes are marked by lines beginning with "//sys" and read
1212 like func declarations if //sys is replaced by func, but:
1313
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.
3535
3636 Usage:
37
3738 mkwinsyscall [flags] [path ...]
3839
3940 The flags are:
41
4042 -output
4143 Specify output file name (outputs to console if blank).
4244 -trace
1919 // log.Fatal(err)
2020 // }
2121 // fmt.Printf("Windows system root is %q\n", s)
22 //
2322 package registry
2423
2524 import (
55 // +build windows
66
77 // Package debug provides facilities to execute svc.Handler on console.
8 //
98 package debug
109
1110 import (
55 // +build windows
66
77 // Package eventlog implements access to Windows event log.
8 //
98 package eventlog
109
1110 import (
1111 // stop / start / pause / continue any service, and how to
1212 // write to event log. It also shows how to use debug
1313 // facilities available in debug package.
14 //
1514 package main
1615
1716 import (
88 // It can be used to install and remove them. It can also start,
99 // stop and pause them. The package can query / change current
1010 // service state and config parameters.
11 //
1211 package mgr
1312
1413 import (
55 // +build windows
66
77 // Package svc provides everything required to build Windows service.
8 //
98 package svc
109
1110 import (
622622
623623 func getStdHandle(stdhandle uint32) (fd Handle) {
624624 r, _ := GetStdHandle(stdhandle)
625 CloseOnExec(r)
626625 return r
627626 }
628627