Skip to content

Commit 737a5b0

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 9b0361e commit 737a5b0

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/runtime/fds_unix.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ func checkfds() {
2929
continue
3030
}
3131

32-
// On AIX and Solaris we can't get the right errno
33-
// value this early in program startup,
34-
// because we haven't yet called minit
35-
// which sets m.mOS.perrno.
36-
// Just assume that the error is EBADF.
37-
if GOOS == "aix" || GOOS == "solaris" {
38-
errno = EBADF
39-
}
40-
4132
if errno != EBADF {
4233
print("runtime: unexpected error while checking standard file descriptor ", i, ", errno=", errno, "\n")
4334
throw("cannot open standard fds")

src/runtime/os3_solaris.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ func getPageSize() uintptr {
133133
}
134134

135135
func osinit() {
136+
// Call miniterrno so that we can safely make system calls
137+
// before calling minit on m0.
138+
asmcgocall(unsafe.Pointer(abi.FuncPCABI0(miniterrno)), unsafe.Pointer(&libc____errno))
139+
136140
ncpu = getncpu()
137141
if physPageSize == 0 {
138142
physPageSize = getPageSize()

src/runtime/os_aix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func semawakeup(mp *m) {
9393
}
9494

9595
func osinit() {
96+
// Call miniterrno so that we can safely make system calls
97+
// before calling minit on m0.
98+
miniterrno()
99+
96100
ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN))
97101
physPageSize = sysconf(__SC_PAGE_SIZE)
98102
}

0 commit comments

Comments
 (0)