This commit is contained in:
2026-05-31 19:48:56 +01:00
parent 7f32417736
commit 68f8904282
39 changed files with 4519 additions and 5 deletions
+35
View File
@@ -0,0 +1,35 @@
//go:build darwin || linux
package pclntab
import (
"syscall"
"unsafe"
)
// mprotectRW makes a memory region read-write using an unsafe.Pointer conversion
// from a page-aligned uintptr. This is intentional for runtime memory manipulation.
//
//go:nosplit
func mprotectRW(addr uintptr, size uintptr) error {
p := *(*unsafe.Pointer)(unsafe.Pointer(&addr))
return syscall.Mprotect(
unsafe.Slice((*byte)(p), size),
syscall.PROT_READ|syscall.PROT_WRITE,
)
}
//go:nosplit
func mprotectRO(addr uintptr, size uintptr) {
p := *(*unsafe.Pointer)(unsafe.Pointer(&addr))
_ = syscall.Mprotect(
unsafe.Slice((*byte)(p), size),
syscall.PROT_READ,
)
}
//go:nosplit
func ptrToSlice(addr uintptr, size uintptr) []byte {
p := *(*unsafe.Pointer)(unsafe.Pointer(&addr))
return unsafe.Slice((*byte)(p), size)
}