1
0
mirror of https://github.com/golang/go synced 2024-11-22 19:24:59 -07:00

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 <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ian Lance Taylor 2023-07-26 11:58:44 -07:00 committed by Gopher Robot
parent 9b0361e549
commit 737a5b0eaa
3 changed files with 8 additions and 9 deletions

View File

@ -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")

View File

@ -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()

View File

@ -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)
}