summaryrefslogtreecommitdiff
path: root/src/internal/syscall
Commit message (Collapse)AuthorAgeFilesLines
* cmd/go: add functions to read index fileMichael Matloob2022-06-033-0/+26
| | | | | | | | | | | | | | The data read is used for three primary functions: ImportPackage, IsDirWithGoFiles and ScanDir. Functions are also provided to get this information from the intermediate package representation to cache the information from reads for non-indexed packages. Change-Id: I5eed629bb0d6ee5b88ab706d06b074475004c081 Reviewed-on: https://go-review.googlesource.com/c/go/+/403975 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
* syscall: update linux/loong64 kernel ABI, emulate fstatat with statxWANG Xuerui2022-05-264-17/+44
| | | | | | | | | | | | | | | | | | | | | | | | | The linux/loong64 kernel ABI has changed a little since the inception of the Go port; most notably fstat and fstatat are being removed [1], leaving only statx as the stat mechanism. Fortunately the structs are easy enough to translate, and we now exclusively use statx across the board on loong64 for best compatibility with past and future kernels (due to the architecture's young age, statx is always available). In wiring up the statx calls, it turned out the linux/loong64 syscall definitions were out-of-date, so the generation script received some tweaking as well. [1]: https://lore.kernel.org/all/20220518092619.1269111-1-chenhuacai@loongson.cn/ Change-Id: Ifebb9ab9fef783683e453fa331d623575e824a48 Reviewed-on: https://go-review.googlesource.com/c/go/+/407694 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Rakoczy <alex@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* internal/syscall/unix: loong64 use generic syscallXiaodong Liu2022-05-172-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Contributors to the loong64 port are: Weining Lu <luweining@loongson.cn> Lei Wang <wanglei@loongson.cn> Lingqin Gong <gonglingqin@loongson.cn> Xiaolin Zhao <zhaoxiaolin@loongson.cn> Meidan Li <limeidan@loongson.cn> Xiaojuan Zhai <zhaixiaojuan@loongson.cn> Qiyuan Pu <puqiyuan@loongson.cn> Guoqi Chen <chenguoqi@loongson.cn> This port has been updated to Go 1.15.6: https://github.com/loongson/go Updates #46229 Change-Id: I5988bf3efed37b03b9193f1089dfece060ccba99 Reviewed-on: https://go-review.googlesource.com/c/go/+/363934 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
* all: gofmt main repoRuss Cox2022-04-111-1/+0
| | | | | | | | | | | | | | | [This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: separate doc comment from //go: directivesRuss Cox2022-04-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | A future change to gofmt will rewrite // Doc comment. //go:foo to // Doc comment. // //go:foo Apply that change preemptively to all comments (not necessarily just doc comments). For #51082. Change-Id: Iffe0285418d1e79d34526af3520b415a12203ca9 Reviewed-on: https://go-review.googlesource.com/c/go/+/384260 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* Revert "os: add handling of os.Interrupt for windows"Bryan Mills2022-04-042-10/+0
| | | | | | | | | | | | | This reverts CL 367495. Reason for revert: broke `x/tools` tests on Windows. Change-Id: Iab6b33259181c9520cf8db1e5b6edfeba763f974 Reviewed-on: https://go-review.googlesource.com/c/go/+/397997 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
* os: add handling of os.Interrupt for windowsConstantin Konstantinidis2022-04-032-0/+10
| | | | | | | | | | | | | | | | Add GenerateConsoleCtrlEvent call to internal syscall package. Define ErrProcessDone while reviewing handling of os.Signal(). Update test to run for windows using the added call. Fixes #42311 Fixes #46354 Change-Id: I460955efc76c4febe04b612ac9a0670e62ba5ff3 Reviewed-on: https://go-review.googlesource.com/c/go/+/367495 Trust: Patrik Nyblom <pnyb@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: use new "unix" build tag where appropriateIan Lance Taylor2022-03-291-1/+1
| | | | | | | | | | For #20322 For #51572 Change-Id: Id0b4799d097d01128e98ba4cc0092298357bca45 Reviewed-on: https://go-review.googlesource.com/c/go/+/389935 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* os, internal/syscall/unix: consolidate Pipe implementationsTobias Klauser2022-03-081-34/+0
| | | | | | | | | | | | | | | | All platforms with the pipe2 syscall now provide syscall.Pipe2. Use it to implement os.Pipe. This also allows to drop the illumos-specific wrapper in internal/sys/unix. Change-Id: Ieb712a1498e86a389bad261e4e97c61c11d4bdd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/390715 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Trust: Matt Layher <mdlayher@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: gofmt -w -r 'interface{} -> any' srcRuss Cox2021-12-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* net: pass around pointers to SockaddrInetNJosh Bleecher Snyder2021-11-043-10/+10
| | | | | | | | | | | | | ...instead of the structs themselves. Escape analysis can handle this, and it'll avoid a bunch of large struct copies. Change-Id: Ia9c6064ed32a4c26d5a96dae2ed7d7ece6d38704 Reviewed-on: https://go-review.googlesource.com/c/go/+/361264 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* net: remove the alloc from ReadMsgUDPAddrPortJosh Bleecher Snyder2021-11-042-0/+16
| | | | | | | | | | | | | | | | | | name old time/op new time/op delta ReadWriteMsgUDPAddrPort-8 4.95µs ± 5% 4.55µs ± 1% -7.96% (p=0.016 n=5+4) name old alloc/op new alloc/op delta ReadWriteMsgUDPAddrPort-8 32.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta ReadWriteMsgUDPAddrPort-8 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) Change-Id: Ib968c6f2968926ec9a364dd52063cd0d7c29b10c Reviewed-on: https://go-review.googlesource.com/c/go/+/360862 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* net: remove the alloc from WriteMsgUDPAddrPortJosh Bleecher Snyder2021-11-042-0/+16
| | | | | | | | | | | | | | | | | | name old time/op new time/op delta ReadWriteMsgUDPAddrPort-8 5.12µs ± 8% 4.59µs ± 3% -10.19% (p=0.000 n=10+9) name old alloc/op new alloc/op delta ReadWriteMsgUDPAddrPort-8 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ReadWriteMsgUDPAddrPort-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Change-Id: Idf540b2f9f8035660305a0ab1cfc3e162569db63 Reviewed-on: https://go-review.googlesource.com/c/go/+/361257 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: fix and document uses of RegEnumKeyExMichael Anthony Knyszek2021-11-041-1/+10
| | | | | | | | | | | | | | | RegEnumKeyEx has an undocumented requirement that subsequent calls need to be made from the same thread. This change documents that requirement and fixes uses of it in std. Fixes #49320. Change-Id: I6d182227e22dd437996a878b3a978943f01b2d61 Reviewed-on: https://go-review.googlesource.com/c/go/+/361154 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: migrate new UDP send/recv API to internal/syscall/unixJosh Bleecher Snyder2021-11-033-0/+74
| | | | | | | | | | | | CL 331490 and friends added new API to package syscall. This was a mistake that we need to fix before Go 1.18 is released. Change-Id: I697c9a4fa649d564822f585dc163df5ab9e5ae08 Reviewed-on: https://go-review.googlesource.com/c/go/+/361216 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: manual fixups for //go:build vs // +buildRuss Cox2021-10-289-9/+0
| | | | | | | | | | | | | Update many generators, also handle files that were not part of the standard build during 'go fix' in CL 344955. Fixes #41184. Change-Id: I1edc684e8101882dcd11f75c6745c266fccfe9e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/359476 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox2021-10-2819-20/+0
| | | | | | | | | | | | | | | | | | | | | | | | When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* crypto/rand, internal/syscall/unix: don't use getentropy on iOSTobias Klauser2021-08-201-0/+3
| | | | | | | | | | | | | | | | CL 302489 switched crypto/rand to use getentropy on darwin, however this function is not available on iOS. Enable getentropy only on macOS and disable it on iOS. Fixes #47812 Change-Id: Ib7ba5d77346aee87904bb93d60cacc845f5c0089 Reviewed-on: https://go-review.googlesource.com/c/go/+/343609 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
* internal/syscall/unix: change Ioctl arg type to unsafe.Pointer on AIXMatt Layher2021-08-161-1/+1
| | | | | | | | | | | | | Without this change, this code is technically in violation of the unsafe.Pointer rules since the conversion from unsafe.Pointer to uintptr has to happen when calling into the syscall6 assembly implementation. Change-Id: I4821f5bf9788c8fa2efeb041f811ed092e07ae74 Reviewed-on: https://go-review.googlesource.com/c/go/+/340949 Trust: Matt Layher <mdlayher@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: gofmt more (but vendor, testdata, and top-level test directories)Dmitri Shuralyov2021-08-139-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CL 294430 made packages in std and cmd modules use Go 1.17 gofmt format, adding //go:build lines. This change applies the same formatting to some more packages that 'go fmt' missed (e.g., syscall/js, runtime/msan), and everything else that is easy and safe to modify in bulk. Consider the top-level test directory, testdata, and vendor directories out of scope, since there are many files that don't follow strict gofmt formatting, often for intentional and legitimate reasons (testing gofmt itself, invalid Go programs that shouldn't crash the compiler, etc.). That makes it easy and safe to gofmt -w the .go files that are found with gofmt -l with aforementioned directories filtered out: $ gofmt -l . 2>/dev/null | \ grep -v '^test/' | \ grep -v '/testdata/' | \ grep -v '/vendor/' | wc -l 51 None of the 51 files are generated. After this change, the same command prints 0. For #41184. Change-Id: Ia96ee2a0f998d6a167d4473bcad17ad09bc1d86e Reviewed-on: https://go-review.googlesource.com/c/go/+/341009 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
* internal/syscall/unix: use internal/abi.FuncPC for syscall wrapperCherry Zhang2021-05-031-4/+2
| | | | | | | | | | | | | Following CL 313230, this is for internal/syscall/unix package. Updates #45702. Change-Id: Ie6d8c1923dfeae56896212393c5c2a6e257648d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/316649 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* crypto/rand, internal/syscall/unix: add support for getentropy syscall on darwinTobias Klauser2021-03-172-0/+40
| | | | | | | | | | | | The getentropy syscall is available on macOS since version 10.12, which is the minimum required version since Go 1.15. Change-Id: I294259af0b11df9669e4dc5fa891d2f2f039d91a Reviewed-on: https://go-review.googlesource.com/c/go/+/302489 Trust: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
* crypto/rand, internal/syscall/unix: add support for getrandom syscall on solarisTobias Klauser2021-03-111-0/+53
| | | | | | | | | | | | | The getrandom syscall is available on Solaris and Illumos, see https://docs.oracle.com/cd/E88353_01/html/E37841/getrandom-2.html and https://illumos.org/man/2/getrandom Change-Id: Id1c65d6a5b2fbc80d20b43d8b32dab137ca950ca Reviewed-on: https://go-review.googlesource.com/c/go/+/299134 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/syscall/unix: unify GetRandom implementationTobias Klauser2021-03-114-102/+42
| | | | | | | | | | | | | | | The implementation of GetRandom for Linux, FreeBSD and DragonflyBSD can be shared. Also remove GRND_INSECURE on DragonflyBSD as pointed out by Ian in the review of CL 269999. Change-Id: I5bf4c1bd51ddb2ad600652a57e0bc1bafa1cf40d Reviewed-on: https://go-review.googlesource.com/c/go/+/299133 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* crypto/rand: supports for getrandom syscall in DragonFlyBSDDavid Carlier2021-03-101-0/+51
| | | | | | | | | | | | | | | Since the 5.7 release, DragonFlyBSD supports as well the getrandom function, the actual stable is 5.8. Change-Id: I2b8fc468771b10ac12b38ea7e8e5314342de6375 GitHub-Last-Rev: c5c496f41898d58f2c6f3ccc81f754792f49edbe GitHub-Pull-Request: golang/go#42617 Reviewed-on: https://go-review.googlesource.com/c/go/+/269999 Run-TryBot: Ian Lance Taylor <iant@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* all: go fmt std cmd (but revert vendor)Russ Cox2021-02-2017-0/+17
| | | | | | | | | | | | | | | | Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: remove RtlGenRandom and move it into internal/syscallJason A. Donenfeld2021-01-152-0/+15
| | | | | | | | | | | | | | | There's on need to expose this to the frozen syscall package, and it also doesn't need to be unsafe. So we move it into internal/syscall and have the generator make a safer function signature. Fixes #43704. Change-Id: Iccae69dc273a0aa97ee6846eb537f1dc1412f2de Reviewed-on: https://go-review.googlesource.com/c/go/+/283992 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
* all: update dependency on golang.org/x/sys and regenerate Windows syscallsBryan C. Mills2020-11-022-239/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | | Steps run: $ cd $(go env GOROOT)/src $ go get -d golang.org/x/sys $ go mod tidy $ go mod vendor $ go generate syscall/... internal/syscall/... $ cd cmd $ go get -d golang.org/x/sys $ go mod tidy $ go mod vendor $ cd .. $ git add . This change subsumes CL 260860. For #36905 Change-Id: I7c677c6aa1ad61b9cbd8cf9ed208ed5a30f29c87 Reviewed-on: https://go-review.googlesource.com/c/go/+/267103 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
* syscall: switch go:generate directives back to mksyscall_windows.goBryan C. Mills2020-11-023-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adjust mksyscall_windows.go to activate module mode and set -mod=readonly, and to suppress its own deprecation warning when run from within GOROOT/src. We can't vendor the mkwinsyscall tool in to the std module directly, because std-vendored dependencies (unlike the dependencies of all other modules) turn into actual, distinct packages in 'std' when viewed from outside the 'std' module. We don't want to introduce a binary in the 'std' meta-pattern, but we also don't particularly want to add more special-cases to the 'go' command right now when we have an existing wrapper program that can do the job. I also regenerated the affected packages to ensure that they are consistent with the current version of mksyscall, which produced some declaration-order changes in internal/syscall/windows/zsyscall_windows.go. Fixes #41916 Updates #25922 Change-Id: If6e6f8ba3dd372a7ecd6820ee6c0ca38d55f0f35 Reviewed-on: https://go-review.googlesource.com/c/go/+/261499 Trust: Bryan C. Mills <bcmills@google.com> Trust: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
* syscall: remove dependency on ioRuss Cox2020-10-133-30/+6
| | | | | | | | | | | | Keep syscall and io separated; neither should depend on the other. Change-Id: Icdd61bd0c05d874cabd7b5ae6631dd09dec90112 Reviewed-on: https://go-review.googlesource.com/c/go/+/243902 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* os, internal/syscall/unix: use pipe2 instead of pipe on illumosTobias Klauser2020-09-161-0/+34
| | | | | | | | | | | | Illumos provides the pipe2 syscall. Add a wrapper to internal/syscall/unix and use it to implement os.Pipe. Change-Id: I26ecdbcae1e8d51f80e2bc8a86fb129826387b1f Reviewed-on: https://go-review.googlesource.com/c/go/+/254981 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/poll, internal/syscall/unix, net: enable writev on illumosTobias Klauser2020-09-151-0/+30
| | | | | | | | | | | | | Illumos supports iovec read/write. Add the writev wrapper to internal/syscall/unix and use it to implement internal/poll.writev for net.(*netFD).writeBuffers. Change-Id: Ie256c2f96aba8e61fb21991788789a049425f792 Reviewed-on: https://go-review.googlesource.com/c/go/+/254638 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com>
* os: implement File.Chmod on WindowsConstantin Konstantinidis2020-09-112-0/+22
| | | | | | | | | | Fixes: #39606 Change-Id: I4def67ef18bd3ff866b140f6e76cdabe5d51a1c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/250077 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
* syscall, internal/syscall/windows: remove utf16PtrToString parameterAlex Brainman2020-05-031-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | CL 208617 introduced syscall.utf16PtrToString and internal/syscall/windows.UTF16PtrToString functions. Original version of CL 208617 did not include syscall.utf16PtrToString and internal/syscall/windows.UTF16PtrToString max parameter. The parameter was added by Brad at the request of Ian. Ian said: "In some cases it seems at least possible that the null terminator is not present. I think it would be safer if we passed a maximum length here." The syscall.utf16PtrToString and internal/syscall/windows.UTF16PtrToString function are designed to work with only null terminated strings. So max parameter is superfluous. This change removes max parameter. Updates #34972 Change-Id: Ifea65dbd86bca8a08353579c6b9636c6f963d165 Reviewed-on: https://go-review.googlesource.com/c/go/+/228858 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* os, internal/poll, internal/syscall/unix: use copy_file_range on LinuxAndrei Tudor Călin2020-04-2810-28/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Linux 4.5 introduced (and Linux 5.3 refined) the copy_file_range system call, which allows file systems the opportunity to implement copy acceleration techniques. This commit adds support for copy_file_range(2) to the os package. Introduce a new ReadFrom method on *os.File, which makes *os.File implement the io.ReaderFrom interface. If dst and src are both files, this enables io.Copy(dst, src) to call dst.ReadFrom(src), which, in turn, will call copy_file_range(2) if possible. If copy_file_range(2) is not supported by the host kernel, or if either of dst or src refers to a non-regular file, ReadFrom falls back to the regular io.Copy code path. Add internal/poll.CopyFileRange, which acquires locks on the appropriate poll.FDs and performs the actual work, as well as internal/syscall/unix.CopyFileRange, which wraps the copy_file_range system call itself at the lowest level. Rework file layout in internal/syscall/unix to accomodate the additional system call numbers needed for copy_file_range. Merge these definitions with the ones used by getrandom(2) into sysnum_linux_$GOARCH.go files. A note on additional optimizations: if dst and src both refer to pipes in the invocation dst.ReadFrom(src), we could, in theory, use the existing splice(2) code in package internal/poll to splice directly from src to dst. Attempting this runs into trouble with the poller, however. If we call splice(src, dst) and see EAGAIN, we cannot know if it came from src not being ready for reading or dst not being ready for writing. The write end of src and the read end of dst are not under our control, so we cannot reliably use the poller to wait for readiness. Therefore, it seems infeasible to use the new ReadFrom method to splice between pipes directly. In conclusion, for now, the only optimization enabled by the new ReadFrom method on *os.File is the copy_file_range optimization. Fixes #36817. Change-Id: I696372639fa0cdf704e3f65414f7321fc7d30adb Reviewed-on: https://go-review.googlesource.com/c/go/+/229101 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/syscall/windows: change WSAMsg.Name typeAlex Brainman2020-04-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was discovered while running go test -a -short -gcflags=all=-d=checkptr -run=TestUDPConnSpecificMethods net WSAMsg is type defined by Windows. And WSAMsg.Name could point to two different structures for IPv4 and IPV6 sockets. Currently WSAMsg.Name is declared as *syscall.RawSockaddrAny. But that violates (1) Conversion of a *T1 to Pointer to *T2. rule of https://golang.org/pkg/unsafe/#Pointer When we convert *syscall.RawSockaddrInet4 into *syscall.RawSockaddrAny, syscall.RawSockaddrInet4 and syscall.RawSockaddrAny do not share an equivalent memory layout. Same for *syscall.SockaddrInet6 into *syscall.RawSockaddrAny. This CL changes WSAMsg.Name type to *syscall.Pointer. syscall.Pointer length is 0, and that at least makes type checker happy. After this change I was able to run go test -a -short -gcflags=all=-d=checkptr std cmd without type checker complaining. Updates #34972 Change-Id: Ic5c2321c20abd805c687ee16ef6f643a2f8cd93f Reviewed-on: https://go-review.googlesource.com/c/go/+/222457 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os/exec: use environment variables for user token when presentLiam 'Auzzie' Haworth2020-02-252-0/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Builds upon the changes from #32000 which supported sourcing environment variables for a new process from the environment of a Windows user token when supplied. But due to the logic of os/exec, the Env field of a process was always non-nil when it reached that change. This change moves the logic up to os/exec, specifically when os.ProcAttr is being built for the os.StartProcess call, this ensures that if a user token has been supplied and no Env slice has been provided on the command it will be sourced from the user's environment. If no token is provided, or the program is compiled for any other platform than Windows, the default environment will be sourced from syscall.Environ(). Fixes #35314 Change-Id: I4c1722e90b91945eb6980d5c5928183269b50487 GitHub-Last-Rev: 32216b7291418f9285147a93ed6d0ba028f94ef2 GitHub-Pull-Request: golang/go#37402 Reviewed-on: https://go-review.googlesource.com/c/go/+/220587 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/syscall/unix: use libc based fcntl for IsNonblock on aix and solarisTobias Klauser2019-12-302-3/+3
| | | | | | | | | | | On aix and solaris (like on darwin) use libc fcntl to implement IsNonblock instead of Syscall(SYS_FCNTL, ...) which isn't supported. Change-Id: I989b02aa0c90b7e2dae025572867dda277fef8be Reviewed-on: https://go-review.googlesource.com/c/go/+/212600 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/syscall/unix: use fcntl64 on 32-bit GNU/Linux systemsIan Lance Taylor2019-12-232-1/+21
| | | | | | | | | | | | | | Patch up runtime testing to use the libc fcntl function on Darwin, which is what we should be doing anyhow. This is similar to how we handle fcntl on AIX and Solaris. Fixes #36211 Change-Id: I47ad87e11df043ce21496a0d59523dad28960f76 Reviewed-on: https://go-review.googlesource.com/c/go/+/212299 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* all: fix most of the remaining windows -d=checkptr violationsAlex Brainman2019-12-062-4/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change replaces buf := [HUGE_CONST]*T)(unsafe.Pointer(p))[:] with buf := [HUGE_CONST]*T)(unsafe.Pointer(p))[:n:n] Pointer p points to n of T elements. New unsafe pointer conversion logic verifies that both first and last elements point into the same Go variable. This change replaces [:] with [:n:n] to please pointer checker. According to @mdempsky, compiler specially recognizes when you combine a pointer conversion with a full slice operation in a single expression and makes an exception. After this, only one failure in net remains when running: go test -a -short -gcflags=all=-d=checkptr std cmd Updates #34972 Change-Id: I2c8731650c856264bc788e4e07fa0530f7c250fa Reviewed-on: https://go-review.googlesource.com/c/go/+/208617 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* internal/syscall/unix: add support for linux/riscv64Tobias Klauser2019-11-012-6/+6
| | | | | | | | | | | | Based on the riscv-go port. Updates #27532 Change-Id: I3a4d86783fbd625e3ade16d08f87d66e4502f3f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/204660 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* internal/syscall/windows/registry: make '-gcflags=all=-d=checkptr' flag workAlex Brainman2019-10-291-6/+5
| | | | | | | | | | | | | | | Mostly replaced [:x] slice operation with [:x:x].  According to @mdempsky, compiler specially recognizes when you combine a pointer conversion with a full slice operation in a single expression and makes an exception. Updates golang/go#34972 Change-Id: I07d9de3b31da254d55f50d14c18155f8fc8f3ece Reviewed-on: https://go-review.googlesource.com/c/go/+/203442 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
* internal/syscall/windows/registry: remove TestWalkFullRegistry due to false ↵Jason A. Donenfeld2019-10-271-98/+0
| | | | | | | | | | | | | | | | | | | | assumptions This test's existence was predicated upon assumptions about the full range of known data types and known data into those types. However, we've learned from Microsoft that there are several undocumented secret registry types that are in use by various parts of Windows, and we've learned from inspection that many Microsoft uses of registry types don't strictly adhere to the recommended value size. It's therefore foolhardy to make any assumptions about what goes in and out of the registry, and so this test, as well as its "blacklist", are meaningless. Fixes #35084 Change-Id: I6c3fe5fb0e740e88858321b3b042c0ff1a23284e Reviewed-on: https://go-review.googlesource.com/c/go/+/203604 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
* internal/syscall/windows/registry: allow for non-null terminated stringsJason A. Donenfeld2019-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | According to MSDN, "If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes any terminating null character or characters unless the data was stored without them. [...] If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper terminating null characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer." It's therefore dangerous to pass it off unbounded as we do, and in fact this led to crashes on real systems. Change-Id: I6d786211814656f036b87fd78631466634cd764a Reviewed-on: https://go-review.googlesource.com/c/go/+/202937 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
* internal/syscall/windows/registry: blacklist certain registry keys in ↵Jason A. Donenfeld2019-10-231-19/+34
| | | | | | | | | | | | | | | | | | | | TestWalkFullRegistry It turns out that Windows has "legitimate" keys that have bogus type values or bogus lengths that don't correspond with their type. On up to date Windows 10 systems, this test always fails for this reason. These keys exist because of bugs in Microsoft's code. This commit works around the problem by simply blacklisting known instances. It also expands the error message a bit so that we can make adjustments should the problem ever happen again, and reformats the messages so that it makes copy and pasting into the blacklist easier. Updates #35084 Change-Id: I50322828c0eb0ccecbb62d6bf4f9c726fa0b3c27 Reviewed-on: https://go-review.googlesource.com/c/go/+/202897 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* internal/syscall/windows/registry: fix strict assumptions in ↵Jason A. Donenfeld2019-10-231-2/+5
| | | | | | | | | | | | | | | | | | | TestWalkFullRegistry It turns out that Windows has "legitimate" keys that have bogus type values or bogus lengths that don't correspond with their type. On up to date Windows 10 systems, this test always fails for this reason. So, this commit alters the test to simply log the discrepancy and move on. Fixes #35084 Change-Id: I56e12cc62aff49cfcc38ff01a19dfe53153976a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/202678 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* internal/syscall/unix: remove unused *Trap constsTobias Klauser2019-10-141-4/+0
| | | | | | | | | | | These are unused since the darwin port switched to libc calls in CL 148457. Change-Id: I309bb5b0a52c9069484e7a649d4a652efcb8e160 Reviewed-on: https://go-review.googlesource.com/c/go/+/200866 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: remove the nacl port (part 1)Brad Fitzpatrick2019-10-091-9/+0
| | | | | | | | | | | | | | | | | | You were a useful port and you've served your purpose. Thanks for all the play. A subsequent CL will remove amd64p32 (including assembly files and toolchain bits) and remaining bits. The amd64p32 removal will be separated into its own CL in case we want to support the Linux x32 ABI in the future and want our old amd64p32 support as a starting point. Updates #30439 Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/199499 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall, internal/syscall/windows, internal/syscall/windows/registry: make ↵Alex Brainman2019-10-052-2/+2
| | | | | | | | | | | | | go generate use new golang.org/x/sys/windows/mkwinsyscall Updates #34388 Change-Id: I327a1c1557c47fa6c113c7a1a507a8e7355f9d1a Reviewed-on: https://go-review.googlesource.com/c/go/+/199277 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
* os: pass correct environment when creating Windows processesJason A. Donenfeld2019-05-162-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is CVE-2019-11888. Previously, passing a nil environment but a non-nil token would result in the new potentially unprivileged process inheriting the parent potentially privileged environment, or would result in the new potentially privileged process inheriting the parent potentially unprivileged environment. Either way, it's bad. In the former case, it's an infoleak. In the latter case, it's a possible EoP, since things like PATH could be overwritten. Not specifying an environment currently means, "use the existing environment". This commit amends the behavior to be, "use the existing environment of the token the process is being created for." The behavior therefore stays the same when creating processes without specifying a token. And it does the correct thing when creating processes when specifying a token. Fixes #32000 Change-Id: Ia57f6e89b97bdbaf7274d6a89c1d9948b6d40ef5 Reviewed-on: https://go-review.googlesource.com/c/go/+/176619 Run-TryBot: Jason Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>