From 737a5b0eaaff9098a41c04bcee5585678766bfae Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 26 Jul 2023 11:58:44 -0700 Subject: [PATCH] runtime: call miniterrno on m0 on AIX and Solaris AIX and Solaris call into libc for syscalls, and expect M.mOS.perrno to point to the thread-local errno value for the current M. We initialize that field in miniterrno called from mstart. However, this means that any libc calls before mstart will not return the correct errno value. This caused trouble in checkfds, which runs very early, before mstart. We worked around that in 513215. This CL reverts 513215 in favor of a better workaround: call miniterrno for m0 earlier (we will still wind up calling miniterrno again from mstart, which does no harm). This is a better workaround because it means that if we add future syscalls before mstart, they will behave as expected. Fixes #61584 Change-Id: Ib6a0d3c53d2c8214cc339a5019f9d4f71a746f0c Reviewed-on: https://go-review.googlesource.com/c/go/+/513535 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor --- src/runtime/fds_unix.go | 9 --------- src/runtime/os3_solaris.go | 4 ++++ src/runtime/os_aix.go | 4 ++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/runtime/fds_unix.go b/src/runtime/fds_unix.go index f39e6a49e9f..7182ef0789f 100644 --- a/src/runtime/fds_unix.go +++ b/src/runtime/fds_unix.go @@ -29,15 +29,6 @@ func checkfds() { continue } - // On AIX and Solaris we can't get the right errno - // value this early in program startup, - // because we haven't yet called minit - // which sets m.mOS.perrno. - // Just assume that the error is EBADF. - if GOOS == "aix" || GOOS == "solaris" { - errno = EBADF - } - if errno != EBADF { print("runtime: unexpected error while checking standard file descriptor ", i, ", errno=", errno, "\n") throw("cannot open standard fds") diff --git a/src/runtime/os3_solaris.go b/src/runtime/os3_solaris.go index 046d173c24a..83acc648bbb 100644 --- a/src/runtime/os3_solaris.go +++ b/src/runtime/os3_solaris.go @@ -133,6 +133,10 @@ func getPageSize() uintptr { } func osinit() { + // Call miniterrno so that we can safely make system calls + // before calling minit on m0. + asmcgocall(unsafe.Pointer(abi.FuncPCABI0(miniterrno)), unsafe.Pointer(&libc____errno)) + ncpu = getncpu() if physPageSize == 0 { physPageSize = getPageSize() diff --git a/src/runtime/os_aix.go b/src/runtime/os_aix.go index 0583e9afdb5..ce2d719d0bf 100644 --- a/src/runtime/os_aix.go +++ b/src/runtime/os_aix.go @@ -93,6 +93,10 @@ func semawakeup(mp *m) { } func osinit() { + // Call miniterrno so that we can safely make system calls + // before calling minit on m0. + miniterrno() + ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN)) physPageSize = sysconf(__SC_PAGE_SIZE) }