diff options
| author | Michael Pratt <mpratt@google.com> | 2024-09-16 16:07:25 -0400 |
|---|---|---|
| committer | Michael Pratt <mpratt@google.com> | 2024-09-17 17:01:26 +0000 |
| commit | d1c3f255fda8b9bf86990b55353ca14fbfe5b257 (patch) | |
| tree | b652f4a29fb9af7e57c1d26b278be82c71a00e7d /src/internal/runtime/sys | |
| parent | 4f881115d4067bda8a236aabcae8c41cdd13b4d0 (diff) | |
| download | go-d1c3f255fda8b9bf86990b55353ca14fbfe5b257.tar.xz | |
runtime: move getclosureptr to internal/runtime/sys
Moving these intrinsics to a base package enables other internal/runtime
packages to use them.
There is no immediate need for getclosureptr outside of runtime, but it
is moved for consistency with the other intrinsics.
For #54766.
Change-Id: Ia68b16a938c8cb84cb222469db28e3a83861be5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/613262
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/internal/runtime/sys')
| -rw-r--r-- | src/internal/runtime/sys/intrinsics.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/internal/runtime/sys/intrinsics.go b/src/internal/runtime/sys/intrinsics.go index 8a431d0b36..147d5581f2 100644 --- a/src/internal/runtime/sys/intrinsics.go +++ b/src/internal/runtime/sys/intrinsics.go @@ -233,3 +233,24 @@ func PrefetchStreamed(addr uintptr) {} func GetCallerPC() uintptr func GetCallerSP() uintptr + +// GetClosurePtr returns the pointer to the current closure. +// GetClosurePtr can only be used in an assignment statement +// at the entry of a function. Moreover, go:nosplit directive +// must be specified at the declaration of caller function, +// so that the function prolog does not clobber the closure register. +// for example: +// +// //go:nosplit +// func f(arg1, arg2, arg3 int) { +// dx := GetClosurePtr() +// } +// +// The compiler rewrites calls to this function into instructions that fetch the +// pointer from a well-known register (DX on x86 architecture, etc.) directly. +// +// WARNING: PGO-based devirtualization cannot detect that caller of +// GetClosurePtr requires closure context, and thus must maintain a list of +// these functions, which is in +// cmd/compile/internal/devirtualize/pgo.maybeDevirtualizeFunctionCall. +func GetClosurePtr() uintptr |
