]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: call miniterrno on m0 on AIX and Solaris
authorIan Lance Taylor <iant@golang.org>
Wed, 26 Jul 2023 18:58:44 +0000 (11:58 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 27 Jul 2023 22:20:25 +0000 (22:20 +0000)
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>

src/runtime/fds_unix.go
src/runtime/os3_solaris.go
src/runtime/os_aix.go

index f39e6a49e9fe80141a178f084a5f7f595f987cb5..7182ef0789f182b3f6e6337e1110254a5d729229 100644 (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")
index 046d173c24a904363ce2f817d0b289ec44306a54..83acc648bbb6223c21b04c14e944b1b585b1f469 100644 (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()
index 0583e9afdb5185b223f9c50fa29f8c84a88a7bef..ce2d719d0bf2e91325c4b2adc797dc099115d0c8 100644 (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)
 }