diff options
| author | Cherry Mui <cherryyz@google.com> | 2023-03-31 18:29:10 +0000 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-03-31 18:42:48 +0000 |
| commit | 63ef9059a2e920d22522f9be068df357fab3d1f6 (patch) | |
| tree | 1affff0606132b2c244304e2665895dd1d18e4e2 /src | |
| parent | 092d43c329babb41f9bbad265bfe82bb48522b64 (diff) | |
| download | go-63ef9059a2e920d22522f9be068df357fab3d1f6.tar.xz | |
Revert "runtime: get a better g0 stack bound in needm"
This reverts CL 479915.
Reason for revert: breaks a lot google internal tests.
Change-Id: I13a9422e810af7ba58cbf4a7e6e55f4d8cc0ca51
Reviewed-on: https://go-review.googlesource.com/c/go/+/481055
Reviewed-by: Chressie Himpel <chressie@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/cgo.go | 2 | ||||
| -rw-r--r-- | src/runtime/cgo/callbacks.go | 9 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_stack_darwin.c | 21 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_stack_unix.c | 32 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_stack_windows.c | 7 | ||||
| -rw-r--r-- | src/runtime/proc.go | 22 | ||||
| -rw-r--r-- | src/runtime/signal_unix.go | 4 |
7 files changed, 7 insertions, 90 deletions
diff --git a/src/runtime/cgo.go b/src/runtime/cgo.go index 395303552c..6a3eeb5822 100644 --- a/src/runtime/cgo.go +++ b/src/runtime/cgo.go @@ -19,7 +19,6 @@ import "unsafe" //go:linkname _cgo_yield _cgo_yield //go:linkname _cgo_pthread_key_created _cgo_pthread_key_created //go:linkname _cgo_bindm _cgo_bindm -//go:linkname _cgo_getstackbound _cgo_getstackbound var ( _cgo_init unsafe.Pointer @@ -31,7 +30,6 @@ var ( _cgo_yield unsafe.Pointer _cgo_pthread_key_created unsafe.Pointer _cgo_bindm unsafe.Pointer - _cgo_getstackbound unsafe.Pointer ) // iscgo is set to true by the runtime/cgo package diff --git a/src/runtime/cgo/callbacks.go b/src/runtime/cgo/callbacks.go index 3c246a88b6..792dd7d086 100644 --- a/src/runtime/cgo/callbacks.go +++ b/src/runtime/cgo/callbacks.go @@ -141,12 +141,3 @@ var _cgo_yield unsafe.Pointer //go:cgo_export_static _cgo_topofstack //go:cgo_export_dynamic _cgo_topofstack - -// x_cgo_getstackbound gets the thread's C stack size and -// set the G's stack bound based on the stack size. - -//go:cgo_import_static x_cgo_getstackbound -//go:linkname x_cgo_getstackbound x_cgo_getstackbound -//go:linkname _cgo_getstackbound _cgo_getstackbound -var x_cgo_getstackbound byte -var _cgo_getstackbound = &x_cgo_getstackbound diff --git a/src/runtime/cgo/gcc_stack_darwin.c b/src/runtime/cgo/gcc_stack_darwin.c deleted file mode 100644 index 2cc9b76196..0000000000 --- a/src/runtime/cgo/gcc_stack_darwin.c +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -#include <pthread.h> -#include "libcgo.h" - -void -x_cgo_getstackbound(G *g) -{ - void* addr; - size_t size; - pthread_t p; - - p = pthread_self(); - addr = pthread_get_stackaddr_np(p); // high address (!) - size = pthread_get_stacksize_np(p); - g->stacklo = (uintptr)addr - size; - // NOTE: don't change g->stackhi. We are called from asmcgocall - // which saves the stack depth based on g->stackhi. -} diff --git a/src/runtime/cgo/gcc_stack_unix.c b/src/runtime/cgo/gcc_stack_unix.c deleted file mode 100644 index 3826322661..0000000000 --- a/src/runtime/cgo/gcc_stack_unix.c +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build unix && !darwin - -#ifndef _GNU_SOURCE // pthread_getattr_np -#define _GNU_SOURCE -#endif - -#include <pthread.h> -#include "libcgo.h" - -void -x_cgo_getstackbound(G *g) -{ - pthread_attr_t attr; - void *addr; - size_t size; - - pthread_attr_init(&attr); -#if defined(__GLIBC__) || defined(__sun) - pthread_getattr_np(pthread_self(), &attr); // GNU extension - pthread_attr_getstack(&attr, &addr, &size); // low address -#else - pthread_attr_getstacksize(&attr, &size); - addr = __builtin_frame_address(0) + 4096 - size; -#endif - g->stacklo = (uintptr)addr; - // NOTE: don't change g->stackhi. We are called from asmcgocall - // which saves the stack depth based on g->stackhi. -} diff --git a/src/runtime/cgo/gcc_stack_windows.c b/src/runtime/cgo/gcc_stack_windows.c deleted file mode 100644 index 9fcb59cf1a..0000000000 --- a/src/runtime/cgo/gcc_stack_windows.c +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -#include "libcgo.h" - -void x_cgo_getstackbound(G *g) {} // no-op for now diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 4152aa4852..fd7760a571 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1889,11 +1889,8 @@ func allocm(pp *p, fn func(), id int64) *m { // 1. when the callback is done with the m in non-pthread platforms, // 2. or when the C thread exiting on pthread platforms. // -// The signal argument indicates whether we're called from a signal -// handler. -// //go:nosplit -func needm(signal bool) { +func needm() { if (iscgo || GOOS == "windows") && !cgoHasExtraM { // Can happen if C/C++ code calls Go from a global ctor. // Can also happen on Windows if a global ctor uses a @@ -1942,23 +1939,14 @@ func needm(signal bool) { osSetupTLS(mp) // Install g (= m->g0) and set the stack bounds - // to match the current stack. If we don't actually know + // to match the current stack. We don't actually know // how big the stack is, like we don't know how big any - // scheduling stack is, but we assume there's at least 32 kB. - // If we can get a more accurate stack bound from pthread, - // use that. + // scheduling stack is, but we assume there's at least 32 kB, + // which is more than enough for us. setg(mp.g0) gp := getg() gp.stack.hi = getcallersp() + 1024 gp.stack.lo = getcallersp() - 32*1024 - if !signal && _cgo_getstackbound != nil { - // Don't adjust if called from the signal handler. - // We are on the signal stack, not the pthread stack. - // (We could get the stack bounds from sigaltstack, but - // we're getting out of the signal handler very soon - // anyway. Not worth it.) - asmcgocall(_cgo_getstackbound, unsafe.Pointer(gp)) - } gp.stackguard0 = gp.stack.lo + _StackGuard // Should mark we are already in Go now. @@ -1979,7 +1967,7 @@ func needm(signal bool) { // //go:nosplit func needAndBindM() { - needm(false) + needm() if _cgo_pthread_key_created != nil && *(*uintptr)(_cgo_pthread_key_created) != 0 { cgoBindM() diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index c7edbcd239..d1719b22ff 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -585,7 +585,7 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool { // sp is not within gsignal stack, g0 stack, or sigaltstack. Bad. setg(nil) - needm(true) + needm() if st.ss_flags&_SS_DISABLE != 0 { noSignalStack(sig) } else { @@ -1068,7 +1068,7 @@ func badsignal(sig uintptr, c *sigctxt) { exit(2) *(*uintptr)(unsafe.Pointer(uintptr(123))) = 2 } - needm(true) + needm() if !sigsend(uint32(sig)) { // A foreign thread received the signal sig, and the // Go code does not want to handle it. |
