Skip to content

Commit

Permalink
feat: 修改 getg 在amd64平台上的实现方式
Browse files Browse the repository at this point in the history
根据 https://go.googlesource.com/go/+/refs/heads/dev.regabi/src/cmd/compile/internal-abi.md
的描述,go使用r14寄存器保存当前协程。
  • Loading branch information
Ruomenger committed Oct 9, 2023
1 parent ebe8718 commit 0abe4b4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
version: [1.18, 1.19, "1.20", 1.21]
os: [ubuntu-latest, macos-latest, windows-latest]
version: [1.18, 1.19, 1.20, 1.21]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go ${{ matrix.version }}
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@ func main() {
1. Monkey 需要关闭 Go 语言的内联优化才能生效,比如测试的时候需要:`go test -gcflags='all=-N -l'`
2. Monkey 需要在运行的时候修改内存代码段,因而无法在一些对安全性要求比较高的系统上工作。
3. Monkey 不应该用于生产系统,但用来 mock 测试代码还是没有问题的。
4. Monkey 目前仅支持 amd64 指令架构,支持 linux/macos/~~windows~~[^win] 平台。

[^win]: 目前在 Win 平台下 Go 1.20 版本之后会报错。欢迎熟悉 Win 平台的同学提供 PR。问题解决之前建议 Win 用户使用 WSL。
4. Monkey 目前仅支持 amd64 指令架构,支持 linux/macos/windows 平台。
10 changes: 10 additions & 0 deletions getg_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package monkey

// getg 获取当前协程的指针,根据go内部abi的文档在amd64架构中使用r14寄存器保存当前的协程g地址
// 参见 https://go.googlesource.com/go/+/refs/heads/dev.regabi/src/cmd/compile/internal-abi.md
func getg() []byte {
return []byte{
// mov r12, r14
0x4D, 0x89, 0xF4,
}
}
11 changes: 0 additions & 11 deletions getg_darwin.go

This file was deleted.

11 changes: 0 additions & 11 deletions getg_linux.go

This file was deleted.

13 changes: 0 additions & 13 deletions getg_windows.go

This file was deleted.

0 comments on commit 0abe4b4

Please sign in to comment.