aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
AgeCommit message (Collapse)Author
2026-01-22syscall: document Sendfile semanticsBill Morgan
syscall.Sendfile behavior differs significantly between operating systems. Document the platform-specific behavior for the offset argument and partial write reporting on Linux versus BSD-derived systems. Fixes #64044 Change-Id: I93f740c3e2df911a10bf0884ffab218d4bb4e5fc GitHub-Last-Rev: a11b898bb98f2a136caaba875033f1c155c1c872 GitHub-Pull-Request: golang/go#77224 Reviewed-on: https://go-review.googlesource.com/c/go/+/737122 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2026-01-22syscall: return early on error in RecvmsgTobias Klauser
Currently, Recvmsg may access the rsa buffer even if the underlying syscall returns an error. Following the same change done for x/sys/unix.Recvmsg in CL 734740. For golang/go#76848 Change-Id: I2a145d822442a2033a76f4717317a39010b17bd5 Reviewed-on: https://go-review.googlesource.com/c/go/+/735121 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-11-26os: allow direntries to have zero inodes on LinuxDave Vasilevsky
Some Linux filesystems have been known to return valid enties with zero inodes. This new behavior also puts Go in agreement with recent glibc. Fixes #76428 Change-Id: Ieaf50739a294915a3ea2ef8c5a3bb2a91a186881 GitHub-Last-Rev: 8f83d009ef0320fd3fe7cf03e55d5d24df57f015 GitHub-Pull-Request: golang/go#76448 Reviewed-on: https://go-review.googlesource.com/c/go/+/724220 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26runtime/secret: implement new secret packageDaniel Morsing
Implement secret.Do. - When secret.Do returns: - Clear stack that is used by the argument function. - Clear all the registers that might contain secrets. - On stack growth in secret mode, clear the old stack. - When objects are allocated in secret mode, mark them and then zero the marked objects immediately when they are freed. - If the argument function panics, raise that panic as if it originated from secret.Do. This removes anything about the secret function from tracebacks. For now, this is only implemented on linux for arm64 and amd64. This is a rebased version of Keith Randalls initial implementation at CL 600635. I have added arm64 support, signal handling, preemption handling and dealt with vDSOs spilling into system stacks. Fixes #21865 Change-Id: I6fbd5a233beeaceb160785e0c0199a5c94d8e520 Co-authored-by: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/704615 Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-26os,internal/syscall/windows: support O_* flags in Root.OpenFileqmuntal
These file flags are supported by os.OpenFile since CL 699415. Closes #73676 Change-Id: Ib37102a565f538d394d2a94bd605d6c6004f3028 Reviewed-on: https://go-review.googlesource.com/c/go/+/724621 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-04os: ignore O_TRUNC errors on named pipes and terminal devices on Windowsqmuntal
Prior to Go 1.24, os.OpenFile used to support O_TRUNC on named pipes and terminal devices, even when the truncation was really ignored. This behavior was consistent with Unix semantics. CL 618836 changed the implementation of os.OpenFile on Windows and unintentionally started returning an error when O_TRUNC was used on such files. Fixes #76071 Change-Id: Id10d3d8120ae9aa0548ef05423a172ff4e502ff9 Reviewed-on: https://go-review.googlesource.com/c/go/+/716420 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-29internal/itoa, internal/runtime/strconv: deleteRuss Cox
Replaced by internal/strconv. Change-Id: I0656a9ad5075e60339e963fbae7d194d2f3e16be Reviewed-on: https://go-review.googlesource.com/c/go/+/716001 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-21runtime,syscall: implement and use syscalln on darwinqmuntal
All darwin syscall implementations can be consolidated into a single syscalln function, as already happens on Windows. This reduces duplication and allows moving some logic from runtime to syscall. Updates #699135 Cq-Include-Trybots: luci.golang.try:gotip-darwin-arm64-longtest,gotip-darwin-amd64-longtest,x_sys-gotip-darwin-arm64-longtest,x_sys-gotip-darwin-amd64-longtest Change-Id: If5de80442b1d4a1123258401a3ae21695e7c8f6b Reviewed-on: https://go-review.googlesource.com/c/go/+/699177 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-21syscall: use rawSyscall6 to call ptrace in forkAndExecInChildqmuntal
On darwin and openbsd, the autogenerated ptrace wrapper is nosplit because it is called from forkAndExecInChild. This makes it difficult to modify and improve the underlying syscall mechanism, as ptrace is almost over the nosplit limit. We better call ptrace directly using rawSyscall6 in forkAndExecInChild so that we can lift the ptrace nosplit restriction to. Doing so also fixes a long-standing inconsistency: forkAndExecInChild is documented to only allow rawSyscall, but the ptrace wrapper is using non-raw syscalls. Updates #64113 Change-Id: Ibbbb218511561c1a5cb5b6d288a691f9738b14a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/708575 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-15all: replace os.Getenv("GO_BUILDER_NAME") with testenv.Builder in testsMichael Anthony Knyszek
Some tests still reach for GO_BUILDER_NAME directly. This change makes it so that they go through testenv.Builder. There are a couple more, but changing them may also cause tests to start failing. Done in a follow-up. Change-Id: Id2453b7b62f5ebf3594e92fa53724a577a97440f Reviewed-on: https://go-review.googlesource.com/c/go/+/703135 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-12vendor: update x/tools to 3adf0e9, and other reposAlan Donovan
Notably, the x/tools update includes CL 702835. Also, pacify copyright_test report of missing copyright header in generated h2_bundle. Updates golang/go#75432 Change-Id: I428278e50dbcef5dcaa661004da0da9ab8f2c924 Reviewed-on: https://go-review.googlesource.com/c/go/+/702955 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2025-09-11syscall: actually remove unreachable codeDmitri Shuralyov
CL 702415 claimed to remove unreachable code, but in reality merely hid it from vet's unreachable pass. Since the unreachable code isn't serving an active role in the test, do remove it to simplify code. Change-Id: I5905b8b566e4ca013bdd1202d1492e3eae6a5ede Reviewed-on: https://go-review.googlesource.com/c/go/+/702575 Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-09-10go/token, syscall: annotate if blocks that defeat vet's unreachable passDmitri Shuralyov
Since putting code in an "if true" block is unusual, make it easier for readers to understand the purpose of doing this. For #73998. Change-Id: I3fd8d65130211c7c01d424366a3c662482d80add Reviewed-on: https://go-review.googlesource.com/c/go/+/702416 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-10syscall: remove unreachable codeDmitri Shuralyov
Reported by go vet: $ go vet syscall # syscall_test # [syscall_test] syscall/env_unix_test.go:100:4: unreachable code The TestVetStdlib test in golang.org/x/tools/go/analysis/unitchecker also ran into this. Fixes #73998. Change-Id: I7f2842a42835a38163433a09a3311be9c30f8a14 Cq-Include-Trybots: luci.golang.try:x_tools-gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/702415 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
2025-09-09syscall: optimise cgo clearenvAleksa Sarai
For programs with very large environments, calling unsetenv(3) for each environment variable can be very expensive because of CGo overhead, but clearenv(3) is much faster. The only thing we have to track is whether GODEBUG is being unset by the operation, which can be done very quickly without resorting to doing unsetenv(3) for every variable. This change makes syscall.Clearenv() >98% faster when run in an environment with as little as 100 environment variables. (Note that due to golang/go#27217, it is necessary to modify BenchmarkClearenv to use t.StopTimer() and -benchtime=100x in order to get these benchmark times -- otherwise syscall.Setenv() time is included and the benchmarks give a more pessimistic 50% performance improvement.) goos: linux goarch: amd64 pkg: syscall cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics │ before │ after │ │ sec/op │ sec/op vs base │ Clearenv/100-16 22276.5n ± 5% 285.8n ± 3% -98.72% (p=0.000 n=10) Clearenv/1000-16 1414104.0n ± 1% 783.1n ± 8% -99.94% (p=0.000 n=10) Clearenv/10000-16 143827.554µ ± 1% 7.591µ ± 5% -99.99% (p=0.000 n=10) geomean 1.655m 1.193µ -99.93% The above benchmarks are CGo builds, which require CGo overhead for every setenv(2). If you run the same benchmarks for a non-CGo package (i.e., outside of the "syscall" package), you get slightly more modest performance improvements: goos: linux goarch: amd64 pkg: clearenv_nocgo cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics │ before │ after │ │ sec/op │ sec/op vs base │ Clearenv/100-16 1106.0n ± 3% 230.7n ± 8% -79.14% (p=0.000 n=10) Clearenv/1000-16 11222.0n ± 1% 305.4n ± 6% -97.28% (p=0.000 n=10) Clearenv/10000-16 195676.5n ± 6% 759.9n ± 10% -99.61% (p=0.000 n=10) geomean 13.44µ 376.9n -97.20% (As above, this requires modifying the benchmarks to use t.StopTimer() and -benchtime=100x.) Change-Id: I53b96a75f189e91affbde423c907888b7e0fafcd GitHub-Last-Rev: f8d7a8140d8490189d726eb380522dccacc5f176 GitHub-Pull-Request: golang/go#70672 Reviewed-on: https://go-review.googlesource.com/c/go/+/633515 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-08-29os,syscall: pass file flags to CreateFile on Windowsqmuntal
Add support for FILE_FLAG_* constants in the flag argument of os.OpenFile and syscall.Open on Windows. Passing invalid flags will result in an error. Updates #73676 Change-Id: Ie215a3dd14f0d74141533f0a07865a02a67a3846 Reviewed-on: https://go-review.googlesource.com/c/go/+/699415 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-28syscall: only get parent PID if SysProcAttr.Pdeathsig is setTobias Klauser
The value of the parent PID is only used to check against get value returned by getppid(2) in case SysProcAttr.Pdeathsig is non-zero. Avoid the useless getpid(2) system call otherwise. Cq-Include-Trybots: luci.golang.try:gotip-freebsd-amd64 Change-Id: If89f9c7acc82016ec359c79bd861d41460f42218 Reviewed-on: https://go-review.googlesource.com/c/go/+/699175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-08-27os: return nil slice when ReadDir is used with a file on file_windowsqmuntal
ReadDir should return (nil, ENOTDIR) when the path points to a file instead of a directory. That's the behavior on Unix systems, and it also used to be the behavior on Windows. However, Windows currently returns ([]DirEntry{}, ENOTDIR). We should change the implementation to match the expected behavior. Fixed #75157 Change-Id: I3a3ddb71b5cd6e51dbca435a1585f01116844d4a Reviewed-on: https://go-review.googlesource.com/c/go/+/699375 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Steven Hartland <stevenmhartland@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-26syscall: sort Windows env block in StartProcessBrad Fitzpatrick
Fixes #29530 Change-Id: Ia28c78274b9288bfa5de9ccb142a452d291a5b66 Reviewed-on: https://go-review.googlesource.com/c/go/+/694435 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
2025-08-22internal/syscall/windows: increase internal Windows O_ flags valuesqmuntal
The lowercase o_ flags are invented values. These conflict with constants that will soon be allowed by os.OpenFile, which values will be mandated by the Windows API. To avoid this overlap, the internal values have been increased to the 33-63 bit range, as the Windows ones are in the 0-32 bit range. Updates #73676 Change-Id: I0f657f3ed3403de150f1730a5a65ae887a18a4e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/697363 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-21syscall: simplify execve handling on libc platformsJoel Sing
Rather than providing three different execve variables for different platforms, use a single variable. Provide a small wrapper that handles conversion to uintptr for the AIX/Solaris case. Note that this removes special handling for openbsd/mips64, which is now a dead port. Updates #61546 Change-Id: I3d6387c31669f64bfb61639536803e595f478647 Reviewed-on: https://go-review.googlesource.com/c/go/+/693880 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-08-19syscall: forkAndExecInChild1: don't reuse pid variableKir Kolyshkin
A named return variable pid is reused in a few places, and while the code is not wrong, it is somewhat confusing. This variable used to be called r1 before CL 456516 (which did the right thing, but slightly added to the confusion). Now, the code calling SYS_WRITE (initially added by CL 158298) never checks the number of bytes written, so let's remove the assignment. In the code that calls SYS_READ it is used, so let's use a different variable, c, which seems less confusing. All this hopefully makes the code more readable. Change-Id: I0d7ec311615100deb7e0aa3f02384eadcc1b47e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/696835 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-15syscall: permit nil destination address in sendmsgN{Inet4,Inet6}database64128
For #74841 Change-Id: Ic3ef9c61a89bc8bc0594724a6d94eed91fb63eae Reviewed-on: https://go-review.googlesource.com/c/go/+/692435 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2025-08-11net, os, file/filepath, syscall: use slices.Equal in testsTobias Klauser
Use slices.Equal to compare slices instead of strings.Join and then comparing strings. Change-Id: Ib916002b7357bd7f4e66b853dd7af8d98eba5549 Reviewed-on: https://go-review.googlesource.com/c/go/+/690475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-08-06all: remove support for windows/armqiulaidongfeng
Also CL 690655 for golang.org/x/sys. For #71671 Change-Id: Iceb369dec5affb944a39d07cdabfd7add6f1f319 Reviewed-on: https://go-review.googlesource.com/c/go/+/648795 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-01runtime,syscall: move loadlibrary and getprocaddress to syscallqmuntal
There is no need for loadlibrary, loadsystemlibrary and getprocaddress to be implemented in the runtime and linknamed from syscall. Change-Id: Icefd53a8e8f7012ed0c94c356be4179d5e45a01b Reviewed-on: https://go-review.googlesource.com/c/go/+/690516 Reviewed-by: Mark Freeman <mark@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-07-28all: omit unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: Ib78cceb718146509d96dbb6da87b27dbaeba1306 GitHub-Last-Rev: dedf354811701ce8920c305b6f7aa78914a4171c GitHub-Pull-Request: golang/go#74771 Reviewed-on: https://go-review.googlesource.com/c/go/+/690735 Reviewed-by: Mark Freeman <mark@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2025-07-28runtime,syscall: move SyscallX implementations from runtime to syscallqmuntal
There is no need for syscall.Syscall{3,6,9,12,15,18} to be implemented in the runtime and linknamed from syscall. All of them can be implemented using the single runtime.syscall_syscalln function. While here, improve the documentation of syscall.SyscallN. Change-Id: I0e09d42e855d6baf900354c9b7992a4329c4ffc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/690515 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-07-24internal/runtime/syscall: rename to internal/runtime/syscall/linuxqmuntal
All code in internal/runtime/syscall is Linux-specific, so better move it to a new linux sub-directory. This way it will be easier to factor out runtime syscall code from other platforms, e.g. Windows. Updates #51087. Change-Id: Idd2a52444b33bf3ad576b47fd232e990cdc8ae75 Reviewed-on: https://go-review.googlesource.com/c/go/+/689155 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-27os: don't follow symlinks on Windows when O_CREATE|O_EXCL and read-onlyDamien Neil
Fix a bug in CL 672396, where we add FILE_FLAG_OPEN_REPARSE_POINT to the attributes passed to CreateFile, but then overwrite the attributes with FILE_ATTRIBUTE_READONLY when opening a file with a read-only permissions mode. For #73702 Change-Id: I6c10bf470054592bafa031732585fc3155c61341 Reviewed-on: https://go-review.googlesource.com/c/go/+/676655 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-05-21runtime: add valgrind instrumentationRoland Shoemaker
Add build tag gated Valgrind annotations to the runtime which let it understand how the runtime manages memory. This allows for Go binaries to be run under Valgrind without emitting spurious errors. Instead of adding the Valgrind headers to the tree, and using cgo to call the various Valgrind client request macros, we just add an assembly function which emits the necessary instructions to trigger client requests. In particular we add instrumentation of the memory allocator, using a two-level mempool structure (as described in the Valgrind manual [0]). We also add annotations which allow Valgrind to track which memory we use for stacks, which seems necessary to let it properly function. We describe the memory model to Valgrind as follows: we treat heap arenas as a "pool" created with VALGRIND_CREATE_MEMPOOL_EXT (so that we can use VALGRIND_MEMPOOL_METAPOOL and VALGRIND_MEMPOOL_AUTO_FREE). Within the pool we treat spans as "superblocks", annotated with VALGRIND_MEMPOOL_ALLOC. We then allocate individual objects within spans with VALGRIND_MALLOCLIKE_BLOCK. It should be noted that running binaries under Valgrind can be _quite slow_, and certain operations, such as running the GC, can be _very slow_. It is recommended to run programs with GOGC=off. Additionally, async preemption should be turned off, since it'll cause strange behavior (GODEBUG=asyncpreemptoff=1). Running Valgrind with --leak-check=yes will result in some errors resulting from some things not being marked fully free'd. These likely need more annotations to rectify, but for now it is recommended to run with --leak-check=off. Updates #73602 [0] https://valgrind.org/docs/manual/mc-manual.html#mc-manual.mempools Change-Id: I71b26c47d7084de71ef1e03947ef6b1cc6d38301 Reviewed-on: https://go-review.googlesource.com/c/go/+/674077 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-15os: set FILE_FLAG_BACKUP_SEMANTICS when opening without I/O accessqmuntal
FILE_FLAG_BACKUP_SEMANTICS is necessary to open directories on Windows, and to enable backup applications do extended operations on files if they hold the SE_BACKUP_NAME and SE_RESTORE_NAME privileges. os.OpenFile currently sets FILE_FLAG_BACKUP_SEMANTICS for all supported cases except when the file is opened with O_WRONLY | O_RDWR (that is, access mode 3). This access mode doesn't correspond to any of the standard POSIX access modes, but some OSes special case it to mean different things. For example, on Linux, O_WRONLY | O_RDWR means check for read and write permission on the file and return a file descriptor that can't be used for reading or writing. On Windows, os.OpenFile has historically mapped O_WRONLY | O_RDWR to a 0 access mode, which Windows internally interprets as FILE_READ_ATTRIBUTES. Additionally, it doesn't prepare the file for I/O, given that the read attributes permission doesn't allow reading or writing (not that this is similar to what happens on Linux). This makes opening the file around 50% faster, and one can still use the handle to stat it, so some projects have been using this behavior to open files without I/O access. This CL updates os.OpenFile so that directories can also be opened without I/O access. This effectively closes #23312, as all the remaining cases where we don't set FILE_FLAG_BACKUP_SEMANTICS imply opening with O_WRONLY or O_RDWR, and that's not allowed by Unix's open. Closes #23312. Change-Id: I77c4f55e1ca377789aef75bd8a9bce2b7499f91d Reviewed-on: https://go-review.googlesource.com/c/go/+/673035 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-14os: don't follow symlinks on Windows when O_CREATE|O_EXCLDamien Neil
Match standard Unix behavior: Symlinks are not followed when O_CREATE|O_EXCL is passed to open. Thanks to Junyoung Park and Dong-uk Kim of KAIST Hacking Lab for discovering this issue. Fixes #73702 Fixes CVE-2025-0913 Change-Id: Ieb46a6780c5e9a6090b09cd34290f04a8e3b0ca5 Reviewed-on: https://go-review.googlesource.com/c/go/+/672396 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-04-30syscall: cache Errno.Error() on WindowsJake Bailey
Windows is unlike the other OSs and depends on a syscall for most errors. This can be costly; cache the returned string for later reuse. This helps test caching, since errors are written out as string to the test ID, which are often PathErrors wrapping Errnos. For now, only cache ERROR_FILE_NOT_FOUND and ERROR_PATH_NOT_FOUND. goos: windows goarch: amd64 pkg: syscall cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ErrnoString-20 1788.00n ± 1% 11.08n ± 1% -99.38% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ErrnoString-20 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ErrnoString-20 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) For #72992 Change-Id: I9a0910fa6538772ffc64ef7670b44059a2c7d18c Reviewed-on: https://go-review.googlesource.com/c/go/+/667495 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Auto-Submit: Carlos Amedee <carlos@golang.org>
2025-04-30net: support IPv6 addresses in ListenMulticastUDP on Windowsqmuntal
Fixes #63529. Change-Id: Id9246af1a72beef3149af571f0891437bba2f4e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/668216 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2025-04-08syscall: remove unused windows functionKeith Randall
It's causing the dependency test to fail. Fixes #73274 Change-Id: I7d80ea4872e360c16ac3b77acf15fa2660d117b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/663975 Auto-Submit: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2025-04-08syscall: fix dangling pointers in Windows' process attributesqmuntal
Windows' _PROC_THREAD_ATTRIBUTE_LIST can contain pointers to memory owned by Go, but the GC is not aware of this. This can lead to the memory being freed while the _PROC_THREAD_ATTRIBUTE_LIST is still in use. This CL uses the same approach as in x/sys/windows to ensure that the attributes are not collected by the GC. Fixes #73170. Updates #73199. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Change-Id: I7dca8d386aed4c02fdcd4a631d0fa4dc5747a96f Reviewed-on: https://go-review.googlesource.com/c/go/+/663715 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2025-03-13syscall: use testing.T.ContextTobias Klauser
Change-Id: I62763878d51598bf1ae0a4e75441e1d3a4b86aa3 Reviewed-on: https://go-review.googlesource.com/c/go/+/656955 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-03-05runtime: in asan mode call __lsan_do_leak_check when exitingIan Lance Taylor
This enables the ASAN default behavior of reporting C memory leaks. It can be disabled with ASAN_OPTIONS=detect_leaks=0. Fixes #67833 Change-Id: I420da1b5d79cf70d8cf134eaf97bf0a22f61ffd0 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-arm64-asan-clang15 Reviewed-on: https://go-review.googlesource.com/c/go/+/651755 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-25os, syscall: use unix build tag where appropriateTobias Klauser
These newly added files may use the unix build tag instead of explitly listing all unix-like GOOS values. For #51572 Change-Id: I31c71d2b5533b39bbccd89bf616a99b8e33565d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/651996 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-02-25all: gofmt -wJes Cok
Change-Id: Ie30a780cbd98bab1e80035b3dfddf92eb281759e GitHub-Last-Rev: 369ada24ffc297efb47768e430b1bd0216706998 GitHub-Pull-Request: golang/go#71898 Reviewed-on: https://go-review.googlesource.com/c/go/+/651795 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2025-02-25all: surround -test.run arguments with ^$qmuntal
If the -test.run value is not surrounded by ^$ then any test that matches the -test.run value will be run. This is normally not the desired behavior, as it can lead to unexpected tests being run. Change-Id: I3447aaebad5156bbef7f263cdb9f6b8c32331324 Reviewed-on: https://go-review.googlesource.com/c/go/+/651956 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-24all: use testenv.Executable instead of os.Executable and os.Args[0]qmuntal
In test files, using testenv.Executable is more reliable than os.Executable or os.Args[0]. Change-Id: I88e577efeabc20d02ada27bf706ae4523129128e Reviewed-on: https://go-review.googlesource.com/c/go/+/651955 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-24syscall: allow \x00-prefixed unix abstract socket to use full path lengthAlbert Sundjaja
Fixes #70893 Change-Id: Ia0aaa497dad335fe962d52d3f115d26e8046e36f GitHub-Last-Rev: 7dd663678d8aecdfac94541a570dfbd1aa2577e7 GitHub-Pull-Request: golang/go#71851 Reviewed-on: https://go-review.googlesource.com/c/go/+/650875 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-02-23syscall: use sync.OnceFunc for copyenvTobias Klauser
Change-Id: I64f658c1962878685ba7736f19d58e10fbdcb94a Reviewed-on: https://go-review.googlesource.com/c/go/+/651835 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-21runtime: use WCLONE when waiting on pidfd test childMichael Pratt
As of CL 650835, the pidfd test child no longer sends SIGCHLD on exit. Per clone(2), "If [the child termination] signal is specified as anything other than SIGCHLD, then the parent process must specify the __WALL or __WCLONE options when waiting for the child with wait(2)." Align with this requirement. For #71828. Change-Id: I6a6a636c739e4a59abe1533fe429a433e8588939 Reviewed-on: https://go-review.googlesource.com/c/go/+/651415 Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-20syscall: don't send child signal when testing pidfdIan Lance Taylor
Avoid a spurious SIGCHLD the first time we start a process. Fixes #71828 Change-Id: I744100d21bf6aaaaafc99bc5eec9f9f807a50682 Reviewed-on: https://go-review.googlesource.com/c/go/+/650835 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-19syscall: don't truncate newly created files on Windowsqmuntal
There is no need for syscall.OpenFile to truncate newly created files. Some special Windows files, like the NUL device, can't be truncated, so we should avoid truncating unless it is really necessary. Fixes #71752. Change-Id: I8238048594f706f6a5281053d55cfe3dc898828d Reviewed-on: https://go-review.googlesource.com/c/go/+/650276 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-02-18syscall: disable O_DIRECTORY on Windows for js/wasmZxilly
O_DIRECTORY is not available on all platforms, as described at https://nodejs.org/docs/latest/api/fs.html#file-open-constants . On Windows, only O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, and UV_FS_O_FILEMAP are available. Fixes #71758 Change-Id: Iacc890ba9a30dcd75eb746ec324fa0c3e368048e GitHub-Last-Rev: a0160e8fc82583c4f903ae165fe9f204896cf56d GitHub-Pull-Request: golang/go#71770 Reviewed-on: https://go-review.googlesource.com/c/go/+/650015 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>