aboutsummaryrefslogtreecommitdiff
path: root/src/internal/syscall
AgeCommit message (Collapse)Author
2025-03-18os: add Root.ChtimesDamien Neil
For #67002 Change-Id: I9b10ac30f852052c85d6d21eb1752a9de5474346 Reviewed-on: https://go-review.googlesource.com/c/go/+/649515 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.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-19path/filepath: use RtlIsDosDeviceName_U to detect Windows devicesqmuntal
RtlIsDosDeviceName_U is specifically designed to detect Windows devices. We were using GetFullPathName to do this, but it's not the right API for the job, as it is slower and allocates more memory. goos: windows goarch: amd64 pkg: path/filepath cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ IsLocal-12 5.685µ ± 59% 1.853µ ± 12% -67.41% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ IsLocal-12 496.00 ± 0% 48.00 ± 0% -90.32% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ IsLocal-12 10.000 ± 0% 6.000 ± 0% -40.00% (p=0.000 n=10) Change-Id: Ib40ad7a90ab93cf7051c8d6becbce4d287f10f4e Reviewed-on: https://go-review.googlesource.com/c/go/+/650578 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-02-18all: use a more straightforward return valuecuishuang
Change-Id: I27e86c221da7f541c4823f501801e02942c9a829 Reviewed-on: https://go-review.googlesource.com/c/go/+/649935 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@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-14internal/syscall/unix: correct fchmodat on openbsdJoel Sing
This is incorrectly calling the fchownat trampoline - call fchmodat as intended. Change-Id: I7b1e758d456006303ca95b70df9e6b52d3020158 Reviewed-on: https://go-review.googlesource.com/c/go/+/649655 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> Commit-Queue: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-02-14internal/syscall/unix: fix fchownat linkname for AIX & SolarisDamien Neil
Typo fix: libc_chownat => libc_fchownat Change-Id: I6721a988c19e3438b967a73559159c948ed51a0e Reviewed-on: https://go-review.googlesource.com/c/go/+/649636 Auto-Submit: Damien Neil <dneil@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-13os: add Root.ChownDamien Neil
For #67002 Change-Id: I546537618cbe32217fa72264d49db2b1a1d3b6db Reviewed-on: https://go-review.googlesource.com/c/go/+/648295 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-12internal/syscall: add cgo_import_dynamic for Fchmodat on AIX and SolarisDamien Neil
For #67002 Change-Id: I1709fd51ba52c074501420943d311c785a49d851 Reviewed-on: https://go-review.googlesource.com/c/go/+/649015 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-10os: add Root.ChmodDamien Neil
For #67002 Change-Id: Id6c3a2096bd10f5f5f6921a0441dc6d9e6cdeb3b Reviewed-on: https://go-review.googlesource.com/c/go/+/645718 Commit-Queue: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
2024-12-21internal/syscall/unix: apply fstatat fix to linux/mips64leCherry Mui
Apply CL 633280 to linux/mips64le, as it has the same struct as mips64. Updates #70659. Change-Id: Ibab635e69e44682eb214bf6a00f4cd75816b2d34 Reviewed-on: https://go-review.googlesource.com/c/go/+/637739 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-12-17syscall, internal/syscall/unix: fix fstatat on linux/mips64Damien Neil
On linux/mips64, the syscall.Stat_t struct does not match the kernel version of the struct. Functions that operate on a Stat_t translate between it and the kernel struct. The fstatat function was not doing this translation. Make it do so. Export a syscall.Fstatat on mips64 for usage by internal/syscall/unix. Perhaps we should just do this on all architectures, but this is the smaller change for now. Fixes #70659 Change-Id: I38e36473689be25861953b418c9abc5b270a7bcf Reviewed-on: https://go-review.googlesource.com/c/go/+/633280 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-11-21all: fix some function names and typos in commentcuishuang
Change-Id: I07e7c8eaa5bd4bac0d576b2f2f4cd3f81b0b77a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/630055 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-11-20os: add Root.Stat and Root.LstatDamien Neil
For #67002 Change-Id: I0903f45dbb4c44ea0280c340c96c5f3c3c0781be Reviewed-on: https://go-review.googlesource.com/c/go/+/627475 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2024-11-20os: add Root.RemoveDamien Neil
For #67002 Change-Id: Ibbf44c0bf62f53695a7399ba0dae5b84d5efd374 Reviewed-on: https://go-review.googlesource.com/c/go/+/627076 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-20os: add RootDamien Neil
Add os.Root, a type which represents a directory and permits performing file operations within that directory. For #67002 Change-Id: I863f4f1bc320a89b1125ae4237761f3e9320a901 Reviewed-on: https://go-review.googlesource.com/c/go/+/612136 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-19internal/syscall/unix, os: add and use Waitid syscall wrapper on linuxTobias Klauser
Instead of open-coding the waitid syscall wrapper add it to internal/syscall/unix. As the syscall is currently only used on Linux, switch the implementation in os.(*Process).blockUntilWaitable to use the 128-byte unix.SiginfoChild type instead of a plain 128-byte buffer. Also use ignoringEINTR for the waitid calls instead of open-coding it. Change-Id: I8dc47e361faa1f5e912d5de021f119c91c9f12f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/629655 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2024-11-19os/user: fix race detector failureqmuntal
The race detector doesn't like that windows.GetSid* functions return pointers to the SID structure. This change makes these functions return values instead and mark them with nocheckptr. Fixes #70378 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race Change-Id: Iba39d75bb31679d25a5ee43b51e4abb0c435dbac Reviewed-on: https://go-review.googlesource.com/c/go/+/628995 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-15os/user: support built-in service user accounts on Windowsqmuntal
Built-in service user accounts should be treated as special cases of well-known groups and allowed in user.Lookup and user.LookupId. Namely, these accounts are: - NT AUTHORITY\SYSTEM (S-1-5-18) - NT AUTHORITY\LOCAL SERVICE (S-1-5-19) - NT AUTHORITY\NETWORK SERVICE (S-1-5-20) See https://learn.microsoft.com/en-us/windows/win32/services/service-user-accounts. Note that #49509 also mentions S-1-5-17 (NT AUTHORITY\IUSR) as another well-known group that should be treated as a user. I haven't found any documentation supporting this claim, and it is not an account that is used usually, so I'm not adding it for now. This CL is heavily based on CL 452497. Fixes #49509 Change-Id: I6e204ddfb4ed0c01b4503001cf284602531e4a88 Reviewed-on: https://go-review.googlesource.com/c/go/+/626255 Reviewed-by: Cherry Mui <cherryyz@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: David Chase <drchase@google.com>
2024-11-11runtime, syscall: use pointer types on wasmimport functionsCherry Mui
Now that we support pointer types on wasmimport functions, use them, instead of unsafe.Pointer. This removes unsafe conversions. There is still one unsafe.Pointer argument left. It is actually a *Stat_t, which is an exported type with an int field, which is not allowed as a wasmimport field type. We probably cannot change it at this point. Updates #66984. Change-Id: I445c70b356c3877a5604bee67d19d99a538c682e Reviewed-on: https://go-review.googlesource.com/c/go/+/627059 Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2024-10-28cmd: use internal/syscall/windows to get Windows versionqmuntal
internal/syscall/windows already provides a function to get the Windows version. There is no need to use golang.org/x/sys/windows for this. Change-Id: If31e9c662b10716ed6c3e9054604366e494345cf Reviewed-on: https://go-review.googlesource.com/c/go/+/622815 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-10-21internal/syscall/windows: set write access when O_TRUNC is usedqmuntal
Whenn O_TRUNC is set, Opentat ends up calling syscall.Ftruncate, which needs write access. Make sure write access is not removed when O_TRUNC and O_APPEND are both set. Updates #67002. Change-Id: Iccc470b7be3c62144318d6a707057504f3b74c97 Reviewed-on: https://go-review.googlesource.com/c/go/+/620576 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-10-14internal/syscall/windows: fix handle leak in Mkdiratqmuntal
Mkdirat does not close the handle returned by CreateFile, but it should. Mkdirat has been introduced in this developer cycle, so it is not necessary to backport this fix to any release branch. Change-Id: Icddac5ccdc6a142a5be5392a39aba2ae7cc9c69a Reviewed-on: https://go-review.googlesource.com/c/go/+/620195 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
2024-10-11internal/syscall/windows: add Openat, MkdiratDamien Neil
Windows versions of openat and mkdirat, implemented using NtCreateFile. For #67002 Change-Id: If43b1c1069733e5c45f7d45a69699fec30187308 Reviewed-on: https://go-review.googlesource.com/c/go/+/619435 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-07net: detect EAI_ADDRFAMILY for cgo host lookup on FreeBSDMichael Anthony Knyszek
For #61095. Change-Id: Iff9f19f6f2eada739967774b50d949f9c5893ee0 Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14,gotip-freebsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/go/+/618015 TryBot-Bypass: Michael Knyszek <mknyszek@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-10-07syscall, internal/syscall/unix: add Openat support for wasip1Damien Neil
The syscall package is mostly frozen, but wasip1 file syscall support was added to syscall and the Open and Openat implementations overlap. Implement Openat in syscall for overall simplicity. We already have syscall.Openat for some platforms, so this doesn't add any new functions to syscall. For #67002 Change-Id: Ia34b12ef11fc7a3b7832e07b3546a760c23efe5b Reviewed-on: https://go-review.googlesource.com/c/go/+/617378 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-07internal/syscall/unix: add Mkdirat and ReadlinkatDamien Neil
For #67002 Change-Id: I460e02db33799c145c296bcf0668fa555199036e Reviewed-on: https://go-review.googlesource.com/c/go/+/617376 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-07internal/syscall/windows: add NtCreateFileDamien Neil
Mostly copied from x/sys/windows. This adds a various related types and functions, but the purpose is to give access to NtCreateFile, which can be used as an equivalent to openat. For #67002 Change-Id: I04e6f630445a55c2000c9c323ce8dcdc7fc0d0e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/617377 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-10-07crypto/rand: use arc4random_buf() on OpenBSDFilippo Valsorda
OpenBSD system calls are mediated by libc anyway, and arc4random_buf() is the preferred mechanism to obtain random bytes. Also, rename NetBSD's function to reflect it's not actually calling getentropy(3). Cq-Include-Trybots: luci.golang.try:gotip-openbsd-amd64 Change-Id: Id1f3f7af16750537e2420bcf44b086de5854198c Reviewed-on: https://go-review.googlesource.com/c/go/+/608395 Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Bypass: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2024-10-07crypto/rand: prevent Read argument from escaping to heapFilippo Valsorda
Mateusz had this idea before me in CL 578516, but it got much easier after the recent cleanup. It's unfortunate we lose the test coverage of batched, but the package is significantly simpler than when we introduced it, so it should be easier to review that everything does what it's supposed to do. Fixes #66779 Co-authored-by: Mateusz Poliwczak <mpoliwczak34@gmail.com> Change-Id: Id35f1172e678fec184efb0efae3631afac8121d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/602498 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-30runtime, internal/syscall/unix: mark getrandom vDSO as non-escapingMateusz Poliwczak
Updates #66779 Updates #69577 Change-Id: I0dea5a30aab87aaa443e7e6646c1d07aa865ac1c GitHub-Last-Rev: 1cea46deb345369346efb2cb320fae1644466322 GitHub-Pull-Request: golang/go#69719 Reviewed-on: https://go-review.googlesource.com/c/go/+/616696 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-09-30runtime: align vgetrandom states to cache lineJason A. Donenfeld
This prevents false sharing, which makes a large difference on machines with several NUMA nodes, such as this dual socket server: cpu: Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz │ sec/op │ sec/op vs base │ ParallelGetRandom-128 0.7944n ± 5% 0.4503n ± 0% -43.31% (p=0.000 n=10) │ B/s │ B/s vs base │ ParallelGetRandom-128 4.690Gi ± 5% 8.272Gi ± 0% +76.38% (p=0.000 n=10) Change-Id: Id4421e9a4c190b38aff0be4c59e9067b0a38ccd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/616535 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jason Donenfeld <Jason@zx2c4.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-09-28runtime: use vDSO for getrandom() on linuxJason A. Donenfeld
Linux 6.11 supports calling getrandom() from the vDSO. It operates on a thread-local opaque state allocated with mmap using flags specified by the vDSO. Opaque states are allocated in chunks, ideally ncpu at a time as a hint, rounding up to as many fit in a complete page. On first use, a state is assigned to an m, which owns that state, until the m exits, at which point it is given back to the pool. Performance appears to be quite good: │ sec/op │ sec/op vs base │ Read/4-16 222.45n ± 3% 27.13n ± 6% -87.80% (p=0.000 n=10) │ B/s │ B/s vs base │ Read/4-16 17.15Mi ± 3% 140.61Mi ± 6% +719.82% (p=0.000 n=10) Fixes #69577. Change-Id: Ib6f44e8f2f3940c94d970eaada0eb566ec297dc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/614835 Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Jason Donenfeld <Jason@zx2c4.com> Reviewed-by: Paul Murphy <murp@ibm.com> 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>
2024-09-25internal/syscall/unix: allow calling getrandom(..., 0, ...)Jason A. Donenfeld
Calling getrandom() with a zero length is actually valid and useful: - Calling getrandom(..., 0, 0) will block until the RNG is initialized. - Calling getrandom(..., 0, GRND_NONBLOCK) will query whether the RNG is initialized. So instead of short circuiting execution for these circumstances, pass this through to the syscall. Change-Id: I15178f087908a2d8be6c020a1ef800cc0a074742 Reviewed-on: https://go-review.googlesource.com/c/go/+/615315 Run-TryBot: Jason Donenfeld <Jason@zx2c4.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Auto-Submit: Jason Donenfeld <Jason@zx2c4.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-16os/user: fix Current().GroupIds() for AD joined users on Windowsqmuntal
This CL special-case User.GroupIds to get the group IDs from the user's token when the user is the current user. This approach is more efficient than calling NetUserGetLocalGroups. It is also more reliable for users joined to an Active Directory domain, where NetUserGetLocalGroups is likely to fail. Updates #26041. Fixes #62712. Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Change-Id: If7c30287192872077b98a514bd6346dbd1a64fb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/611116 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-06internal/syscall/unix: Eaccess: return ENOSYS on AndroidKir Kolyshkin
On Android, faccessat2 syscall (which supports flags like AT_EACCESS) is not allowed, so syscall.Faccessat tries to emulate AT_EACCESS check in userspace using os.Stat, os.Geteuid etc. Also, according to [1], > Android doesn't have setuid programs, and never runs code with euid!=uid. This means on Android the proper AT_EACCESS check is neither possible nor really needed. Let's skip the syscall.Faccessat userspace emulation of AT_EACCESS check and return ENOSYS, so the callers can use a fallback. This should speed up exec.LookPath on Android. [1]: https://android.googlesource.com/platform/bionic/+/508b2f6e5cba4bdadf1e47a4ff27e25ce66c40e3/libc/bionic/faccessat.cpp#50 Change-Id: If7b529fa314480b70e9ae9cdd8c7ce82cd55d233 Reviewed-on: https://go-review.googlesource.com/c/go/+/611298 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-09-06internal/syscall/unix: implement Eaccess on all unix platformsKir Kolyshkin
Eaccess, initially added by CL 414824 for linux only, was later implemented for freebsd (CL 531155), netbsd (CL 531876), dragonfly (CL 532675), openbsd (CL 538836), and darwin (CL 579976). The only unix platforms which lack Eaccess are Solaris/Illumos and AIX. For AIX, syscall.Faccessat is already available, the only missing piece was AT_EACCESS constant. Let's take it from [1], which, judging by a few other known AT_ constants, appears to be accurate. For Solaris, wire the faccessat using the same logic as in the syscall package. Now, when we have faccessat for every unix, we can drop eaccess_other.go and consolidate Eaccess implementations to use faccessat. [1]: https://github.com/rust-lang/libc/blob/main/src/unix/aix/mod.rs Change-Id: I7e1b90dedc5d8174235d3a79d5c662f3dcb909c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/611295 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
2024-08-27os/user: test that Current does not depend on netapi32.dllqmuntal
Updates #21867. Change-Id: I1eb923ef66aa0f338bfa0d683159edc1d8ae2a6c Reviewed-on: https://go-review.googlesource.com/c/go/+/604415 Reviewed-by: Dmitri Shuralyov <dmitshur@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: Cherry Mui <cherryyz@google.com>
2024-08-21os/user: speed up Current on Windowsqmuntal
[This is a roll-forward of CL 597255, which had to be rolled back because it broke the windows-arm64 builder, whose current user display name is unavailable. This new CL fixes the issue by reintroducing the historical behavior of falling back to the user name instead of returning an error]. user.Current is slow on Windows sessions connected to an Active Directory domain. This is because it uses Windows APIs that do RPC calls to the domain controller, such as TranslateAccountW and NetUserGetInfo. This change speeds up user.Current by using the GetUserNameEx API instead, which is already optimized for retrieving the current user name in different formats. These are the improvements I see with the new implementation: goos: windows goarch: amd64 pkg: os/user cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Current-12 501.8µ ± 7% 118.6µ ± 11% -76.36% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ Current-12 888.0 ± 0% 832.0 ± 0% -6.31% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ Current-12 15.00 ± 0% 11.00 ± 0% -26.67% (p=0.000 n=10) Updates #5298 Fixes #21867 Fixes #68312 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: Ib7f77086d389cccb9d91cb77ea688d438a0ee5fd Reviewed-on: https://go-review.googlesource.com/c/go/+/605135 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-15internal,os: employ copy_file_range(2) for file-to-file copying on FreeBSDAndy Pan
FreeBSD 13.0 introduced the Linux-compatible copy_file_range(2) system call, we should make use of it. Ref: https://www.gnu.org/software/gnulib/manual/html_node/copy_005ffile_005frange.html https://reviews.freebsd.org/D20584?id=60021 https://man.freebsd.org/cgi/man.cgi?copy_file_range(2) Change-Id: I75edb5629717289c8887be436613d3a8b3820bdc Reviewed-on: https://go-review.googlesource.com/c/go/+/604655 Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-10Revert "os/user: speed up Current on Windows"Quim Muntal
This reverts CL 597255. Reason for revert: Broke windows/arm64 Fixes #68822. Updates #68312. Change-Id: I43efabad43c74045888bb62bd27522aeaba0a64c Reviewed-on: https://go-review.googlesource.com/c/go/+/604555 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-09os/user: speed up Current on Windowsqmuntal
user.Current is slow on Windows sessions connected to an Active Directory domain. This is because it uses Windows APIs that do RPC calls to the domain controller, such as TranslateAccountW and NetUserGetInfo. This change speeds up user.Current by using the GetUserNameEx API instead, which is already optimized for retrieving the current user name in different formats. These are the improvements I see with the new implementation: goos: windows goarch: amd64 pkg: os/user cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Current-12 501.8µ ± 7% 118.6µ ± 11% -76.36% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ Current-12 888.0 ± 0% 832.0 ± 0% -6.31% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ Current-12 15.00 ± 0% 11.00 ± 0% -26.67% (p=0.000 n=10) Updates #5298 Fixes #21867 Fixes #68312 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Change-Id: I893c5fcca6969050d73a20ed34770846becd5f5e Reviewed-on: https://go-review.googlesource.com/c/go/+/597255 Reviewed-by: Ian Lance Taylor <iant@google.com> 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>
2024-08-08os/user: support calling Current on impersonated threadsqmuntal
The syscall.OpenCurrentProcessToken call in user.Current fails when called from an impersonated thread, as the process token is normally in that case. This change ensures that the current thread is not impersonated when calling OpenCurrentProcessToken, and then restores the impersonation state, if any. Fixes #68647 Change-Id: I3197535dd8355d21029a42f7aa3936d8fb021202 Reviewed-on: https://go-review.googlesource.com/c/go/+/602415 Reviewed-by: David Chase <drchase@google.com> 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>
2024-06-18internal/syscall/unix: fix UTIME_OMIT for dragonflyKir Kolyshkin
CL 219638 added UTIME_OMIT values for various systems. The value for DragonFly BSD appears to be incorrect. The correct value is -2 (see references below), while -1 is used for UTIME_NOW. As a result, timestamp is changed to the current time instead of not touching. This should have been caught by the accompanying test case, TestChtimesWithZeroTimes, but its failures are essentially skipped on dragonfly (this is being fixed separately in a followup CL 591535). Improve formatting while at it. References: - https://github.com/DragonFlyBSD/DragonFlyBSD/blob/965b380e9609/sys/sys/stat.h#L284 - https://go.googlesource.com/sys/+/refs/tags/v0.20.0/unix/zerrors_dragonfly_amd64.go#1421 Change-Id: I432360ca982c84b7cd70d0cf01d860af9ff985fa Reviewed-on: https://go-review.googlesource.com/c/go/+/589496 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org>
2024-06-11os: RemoveAll: fix error returnedKir Kolyshkin
When unlink fails, it is not yet known if the argument is a directory or not. Since CL 588495, we figure out if it's a directory when trying to open it (and, for a directory, return the original unlink error). The (very minor) issue is, in case of a symlink, a different error is returned -- usually it's ELOOP, but some systems use other values. Let's account for that error code, too. This is a followup to CL 588495. Change-Id: I4ee10fe9b57f045fbca02f13e5c9ea16972803bc Reviewed-on: https://go-review.googlesource.com/c/go/+/589376 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-17os: make use of pidfd on linuxKir Kolyshkin
Use Process.handle field to store pidfd, and make use of it. Only use pidfd functionality if all the needed syscalls are available. 1. Add/use pidfdWorks, which checks that all needed pidfd-related functionality works. 2. os.StartProcess: obtain the pidfd from the kernel, if possible, using the functionality added by CL 520266. Note we could not modify syscall.StartProcess to return pidfd directly because it is a public API and its callers do not expect it, so we have to use ensurePidfd and getPidfd. 3. (*Process).Kill: use pidfdSendSignal, if available and the pidfd is known. Otherwise, fall back to the old implementation. 4. (*Process).Wait: use pidfdWait, if available, otherwise fall back to using waitid/wait4. This is more complicated than expected due to struct siginfo_t idiosyncrasy. NOTE pidfdSendSignal and pidfdWait are used without a race workaround (blockUntilWaitable and sigMu, added by CL 23967) because with pidfd, PID recycle issue doesn't exist (IOW, pidfd, unlike PID, is guaranteed to refer to one particular process) and thus the race doesn't exist either. Rework of CL 528438 (reverted in CL 566477 because of #65857). For #62654. Updates #13987. Change-Id: If5ef8920bd8619dc428b6282ffe4fb8c258ca224 Reviewed-on: https://go-review.googlesource.com/c/go/+/570036 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Cherry Mui <cherryyz@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-04-26testing: use QueryPerformanceCounter on WindowsEgon Elbre
Windows time.Now granularity is around 0.5ms on modern systems, which introduces a significant noise into benchmark results. Instead of relying time.Now use QueryPerformanceCounter, which has significantly better granularity compared to time.Now. │ TimeNow-32 │ HighPrecisionTimeNow-32 │ │ sec/op │ sec/op vs base │ 4.812n ± 0% 30.580n ± 0% +535.43% (p=0.000 n=20) Fixes #31160 Change-Id: Ib2a574d638c9c6762a2524212def02265574e267 Reviewed-on: https://go-review.googlesource.com/c/go/+/557315 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-04-19internal/syscall/unix: implement Eaccess on darwinTobias Klauser
Like on other Unix-like platforms, use faccessat(AT_FDCWD, path, mode, AT_EACCESS). Change-Id: I6e04b4244f8e90bd3b35b1b8a9ca38fe845b34ae Reviewed-on: https://go-review.googlesource.com/c/go/+/579976 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-04-15net: implement TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT on Solaris 11.4Andy Pan
Also simulate TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT with TCP_KEEPALIVE_THRESHOLD + TCP_KEEPALIVE_ABORT_THRESHOLD for Solaris prior to 11.4 Fixes #9614 Fixes #64251 Change-Id: Ia0777076a7952630bc52761cddd0b06b0d81c6a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/577195 Commit-Queue: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-04-14net: separate the Solaris fast/slow path of setting SOCK_* from othersAndy Pan
Along with the removal of the slow path from Linux and *BSD. For #59359 Change-Id: I6c79594252e5e5f1c1c57c11e09458fcae3793d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/577175 Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com>
2024-04-11internal/syscall/unix: implement Eaccess on openbsdTobias Klauser
Like on other BSDs, use faccessat(AT_FDCWD, path, mode, AT_EACCESS) Change-Id: I80f8d327dd152576165b9206e32dfb749b41d187 Reviewed-on: https://go-review.googlesource.com/c/go/+/538836 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> 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> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>