gitlab.com/Raven-IO/raven-delve@v1.22.4/pkg/proc/native/dump_freebsd.go (about) 1 package native 2 3 import ( 4 "errors" 5 "unsafe" 6 7 "gitlab.com/Raven-IO/raven-delve/pkg/elfwriter" 8 "gitlab.com/Raven-IO/raven-delve/pkg/proc" 9 ) 10 11 /* 12 #include <sys/types.h> 13 #include <sys/user.h> 14 #include <libutil.h> 15 #include <stdlib.h> 16 */ 17 import "C" 18 19 func (p *nativeProcess) MemoryMap() ([]proc.MemoryMapEntry, error) { 20 var cnt C.int 21 vmentries := C.kinfo_getvmmap(C.int(p.pid), &cnt) 22 if vmentries == nil { 23 return nil, errors.New("kinfo_getvmmap call failed") 24 } 25 defer C.free(unsafe.Pointer(vmentries)) 26 r := make([]proc.MemoryMapEntry, 0, int(cnt)) 27 base := uintptr(unsafe.Pointer(vmentries)) 28 sz := unsafe.Sizeof(C.struct_kinfo_vmentry{}) 29 for i := 0; i < int(cnt); i++ { 30 vmentry := (*C.struct_kinfo_vmentry)(unsafe.Pointer(base + sz*uintptr(i))) 31 switch vmentry.kve_type { 32 case C.KVME_TYPE_DEFAULT, C.KVME_TYPE_VNODE, C.KVME_TYPE_SWAP, C.KVME_TYPE_PHYS: 33 r = append(r, proc.MemoryMapEntry{ 34 Addr: uint64(vmentry.kve_start), 35 Size: uint64(vmentry.kve_end - vmentry.kve_start), 36 37 Read: vmentry.kve_protection&C.KVME_PROT_READ != 0, 38 Write: vmentry.kve_protection&C.KVME_PROT_WRITE != 0, 39 Exec: vmentry.kve_protection&C.KVME_PROT_EXEC != 0, 40 }) 41 } 42 } 43 return r, nil 44 } 45 46 func (p *nativeProcess) DumpProcessNotes(notes []elfwriter.Note, threadDone func()) (threadsDone bool, notesout []elfwriter.Note, err error) { 47 return false, notes, nil 48 }