pkujhd / goloader

load and run golang code at runtime.
Apache License 2.0
506 stars 58 forks source link

Mac M1 Load error: syscall.Mmap: permission denied #56

Closed devanwang closed 2 years ago

devanwang commented 2 years ago

M1芯片 macOS 12.2.1 ,报错mmap无权限 同样的参数配置,用C调用mmap正常

mmap((void *)0x200000000, 8192, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE|MAP_ANON , 0, 0);

大佬看看是否是问题

pkujhd commented 2 years ago

@devanwang 给mmap_unix.go里边的syscall.MAP_PRIVATE|syscall.MAP_ANON 修改成syscall.MAP_PRIVATE|syscall.MAP_ANON|syscall.MAP_JIT 试一下

手头没有相应的系统,无法确认

devanwang commented 2 years ago

修改后不报syscall.Mmap: permission denied了 执行example下的http报了如下错误: unexpected fault address 0x10c184000 fatal error: fault [signal SIGBUS: bus error code=0x1 addr=0x10c184000 pc=0x104ba17e0]

pkujhd commented 2 years ago

那估计是link的问题,等找到运行环境了测试一下,我手头没有环境没发处理

pkujhd commented 2 years ago

@devanwang ,macosx在11.2以后增加了Jit的内存保护,需要进行迁移,你要是需要可以参考文档https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon?language=objc

pkujhd commented 2 years ago

@devanwang already support macosx M1 with version https://github.com/pkujhd/goloader/commit/58633ce2516bba6ef0ca487c0a6182bb8832a746

devanwang commented 2 years ago

58633ce

👌