github.com/tencent/goom@v1.0.1/internal/bytecode/stub/mmap_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package stub 5 6 import ( 7 "syscall" 8 "unsafe" 9 10 "github.com/tencent/goom/internal/logger" 11 ) 12 13 // acquireFromMMap enough executable space from holder 14 func acquireFromMMap(len int) (uintptr, *[]byte, error) { 15 executableSpace, err := syscall.Mmap( 16 -1, 17 0, 18 len, 19 syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC, 20 syscall.MAP_SHARED|syscall.MAP_ANON) 21 if err != nil { 22 logger.Debugf("acquireFromMMap fail: %v\n", err) 23 return 0, nil, err 24 } 25 addr := (uintptr)(unsafe.Pointer(&executableSpace[0])) 26 return addr, &executableSpace, nil 27 }