-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,44 @@ | ||
#include "textflag.h" | ||
//go:build go1.23 | ||
// +build go1.23 | ||
|
||
// After go1.9, goid in "goroutine struct" has a stable offset. | ||
// See https://github.com/golang/go/blob/master/src/runtime/runtime2.go#L458 | ||
// | ||
// This file exposes "goid()" function by | ||
// 1. get current "g" pointer, | ||
// 2. extract goid with a hardcoded offset. | ||
// *) for GOARCH amd64/arm64, offset=152, size=8. | ||
// *) for GOARCH arm/386, offset=80, size=4. | ||
// | ||
#include "textflag.h" | ||
|
||
#ifdef GOARCH_amd64 | ||
TEXT ·goid(SB),NOSPLIT,$0-8 | ||
MOVQ (TLS), R14 | ||
MOVQ 152(R14), R13 | ||
MOVQ 160(R14), R13 | ||
MOVQ R13, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_arm64 | ||
TEXT ·goid(SB),NOSPLIT,$0-8 | ||
MOVD g, R14 | ||
MOVD 152(R14), R13 | ||
MOVD 160(R14), R13 | ||
MOVD R13, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_arm | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVW g, R8 | ||
MOVW 80(R8), R7 | ||
MOVW 84(R8), R7 | ||
MOVW R7, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_386 | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVL (TLS), AX | ||
MOVL 80(AX), BX | ||
MOVL 84(AX), BX | ||
MOVL BX, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_mipsle | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVW g, R8 | ||
MOVW 80(R8), R7 | ||
MOVW 84(R8), R7 | ||
MOVW R7, ret+0(FP) | ||
RET | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build !go1.23 | ||
// +build !go1.23 | ||
|
||
#include "textflag.h" | ||
|
||
#ifdef GOARCH_amd64 | ||
TEXT ·goid(SB),NOSPLIT,$0-8 | ||
MOVQ (TLS), R14 | ||
MOVQ 152(R14), R13 | ||
MOVQ R13, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_arm64 | ||
TEXT ·goid(SB),NOSPLIT,$0-8 | ||
MOVD g, R14 | ||
MOVD 152(R14), R13 | ||
MOVD R13, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_arm | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVW g, R8 | ||
MOVW 80(R8), R7 | ||
MOVW R7, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_386 | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVL (TLS), AX | ||
MOVL 80(AX), BX | ||
MOVL BX, ret+0(FP) | ||
RET | ||
#endif | ||
|
||
#ifdef GOARCH_mipsle | ||
TEXT ·goid(SB),NOSPLIT,$0-4 | ||
MOVW g, R8 | ||
MOVW 80(R8), R7 | ||
MOVW R7, ret+0(FP) | ||
RET | ||
#endif |