From: Michael Hudson-Doyle Date: Fri, 16 Oct 2015 07:19:14 +0000 (+1300) Subject: runtime, runtime/debug: access unexported runtime functions with //go:linkname, not... X-Git-Tag: go1.6beta1~831 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=42c7929c0453b771fd22941ce7c1133c60f58bfb;p=gostls13.git runtime, runtime/debug: access unexported runtime functions with //go:linkname, not assembly stubs Change-Id: I88f80f5914d6e4c179f3d28aa59fc29b7ef0cc66 Reviewed-on: https://go-review.googlesource.com/15960 Reviewed-by: Minux Ma Run-TryBot: Minux Ma TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/debug/stubs.go b/src/runtime/debug/stubs.go index 95b33e4da6..6c87ffdafe 100644 --- a/src/runtime/debug/stubs.go +++ b/src/runtime/debug/stubs.go @@ -8,12 +8,10 @@ import ( "time" ) -// Uses assembly to call corresponding runtime-internal functions. +// Implemented in package runtime. +func readGCStats(*[]time.Duration) +func freeOSMemory() func setMaxStack(int) int func setGCPercent(int32) int32 func setPanicOnFault(bool) bool func setMaxThreads(int) int - -// Implemented in package runtime. -func readGCStats(*[]time.Duration) -func freeOSMemory() diff --git a/src/runtime/debug/stubs.s b/src/runtime/debug/stubs.s deleted file mode 100644 index 9dc8e54664..0000000000 --- a/src/runtime/debug/stubs.s +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 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 "textflag.h" - -#ifdef GOARCH_arm -#define JMP B -#endif -#ifdef GOARCH_arm64 -#define JMP B -#endif -#ifdef GOARCH_ppc64 -#define JMP BR -#endif -#ifdef GOARCH_ppc64le -#define JMP BR -#endif - -TEXT ·setMaxStack(SB),NOSPLIT,$0-0 - JMP runtime·setMaxStack(SB) - -TEXT ·setGCPercent(SB),NOSPLIT,$0-0 - JMP runtime·setGCPercent(SB) - -TEXT ·setPanicOnFault(SB),NOSPLIT,$0-0 - JMP runtime·setPanicOnFault(SB) - -TEXT ·setMaxThreads(SB),NOSPLIT,$0-0 - JMP runtime·setMaxThreads(SB) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 086fc957f0..f57e16cdeb 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -196,6 +196,7 @@ func gcenable() { memstats.enablegc = true // now that runtime is initialized, GC is okay } +//go:linkname setGCPercent runtime/debug.setGCPercent func setGCPercent(in int32) (out int32) { lock(&mheap_.lock) out = gcpercent diff --git a/src/runtime/proc1.go b/src/runtime/proc1.go index ec60f8c0d0..614de5110c 100644 --- a/src/runtime/proc1.go +++ b/src/runtime/proc1.go @@ -3645,6 +3645,7 @@ func testSchedLocalQueueSteal() { } } +//go:linkname setMaxThreads runtime/debug.setMaxThreads func setMaxThreads(in int) (out int) { lock(&sched.lock) out = int(sched.maxmcount) diff --git a/src/runtime/rdebug.go b/src/runtime/rdebug.go index f2766d7937..ad7b976989 100644 --- a/src/runtime/rdebug.go +++ b/src/runtime/rdebug.go @@ -4,12 +4,16 @@ package runtime +import _ "unsafe" // for go:linkname + +//go:linkname setMaxStack runtime/debug.setMaxStack func setMaxStack(in int) (out int) { out = int(maxstacksize) maxstacksize = uintptr(in) return out } +//go:linkname setPanicOnFault runtime/debug.setPanicOnFault func setPanicOnFault(new bool) (old bool) { mp := acquirem() old = mp.curg.paniconfault