Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS 上的 permission denied 问题,也可能和 cgo 有关 #142

Open
myzhan opened this issue Nov 6, 2023 · 8 comments
Open

MacOS 上的 permission denied 问题,也可能和 cgo 有关 #142

myzhan opened this issue Nov 6, 2023 · 8 comments

Comments

@myzhan
Copy link
Contributor

myzhan commented Nov 6, 2023

环境

  1. macOS Sonoma
  2. AMD64
  3. go 1.20.7

问题
之前都是正常使用,通过 cgo 引入 sqlite 依赖后,运行出现 permission denied 的问题。引入 cgo 的模块,跟 monkey patch 的模块没有任何关联。只是发现引入 cgo 后,monkey patch 的函数地址变得很大,40 多亿的一个整数,没有引入 cgo 之前是 4 千万。

解法

  1. 通过 -ldflags=-extldflags=-Wl,-segprot,__TEXT,rwx,rx 参数运行 go test,可行。
  2. 换用 https://github.com/bytedance/mockey 库,可行。通过对比代码,发现 mockey 在通过 mprotect 修改失败后,还会通过 mach_vm_protect 再尝试修改。去掉 mach_vm_protect 部分后,mockey 也不能 patch。
@agiledragon
Copy link
Owner

please review #143

@myzhan
Copy link
Contributor Author

myzhan commented Nov 8, 2023

Tried on both intel machine and M1 machine, no luck.

@agiledragon
Copy link
Owner

Can you propose a PR to port mockey's mach_vm_protect feature to gomonkey?

@agiledragon
Copy link
Owner

#144 has been merged, please test it on both intel machine and M1 machine.

@myzhan
Copy link
Contributor Author

myzhan commented Nov 10, 2023

Yes, I have tested it on both intel and M1 machine, macOS sonoma.

@myzhan
Copy link
Contributor Author

myzhan commented Nov 10, 2023

Can you push a release tag?

@agiledragon
Copy link
Owner

Yes, I have tested it on both intel and M1 machine, macOS sonoma.

Good job!

@agiledragon
Copy link
Owner

Can you push a release tag?

v2.11.0 has been released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants