update lsof to work with vmmap
Hi, The following diff, originally from Ariane, updates lsof to work with our new vmmap. Please test/comment, I'd like to have it committed... Ciao, David Index: Makefile === RCS file: /cvs/ports/sysutils/lsof/Makefile,v retrieving revision 1.83 diff -u -p -r1.83 Makefile --- Makefile16 Nov 2011 00:25:05 - 1.83 +++ Makefile14 Mar 2012 09:22:22 - @@ -5,7 +5,7 @@ COMMENT=list information about open fil VERSION= 4.83 DISTNAME= lsof_${VERSION} PKGNAME= ${DISTNAME:S/_/-/} -REVISION= 7 +REVISION= 8 CATEGORIES=sysutils MASTER_SITES= http://www.mirrorservice.org/sites/vic.cc.purdue.edu/pub/tools/unix/lsof/OLD/ \ ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ \ @@ -22,7 +22,7 @@ PERMIT_PACKAGE_CDROM= Yes PERMIT_PACKAGE_FTP=Yes PERMIT_DISTFILES_CDROM=Yes PERMIT_DISTFILES_FTP= Yes -WANTLIB= c kvm +WANTLIB= c kvm=13 MAKE_FLAGS=DEBUG=${CFLAGS} Index: patches/patch-dialects_n+obsd_dlsof_h === RCS file: /cvs/ports/sysutils/lsof/patches/patch-dialects_n+obsd_dlsof_h,v retrieving revision 1.3 diff -u -p -r1.3 patch-dialects_n+obsd_dlsof_h --- patches/patch-dialects_n+obsd_dlsof_h 23 Feb 2008 23:45:23 - 1.3 +++ patches/patch-dialects_n+obsd_dlsof_h 14 Mar 2012 09:22:22 - @@ -1,6 +1,6 @@ $OpenBSD: patch-dialects_n+obsd_dlsof_h,v 1.3 2008/02/23 23:45:23 sturm Exp $ dialects/n+obsd/dlsof.h.orig Fri Feb 22 22:18:35 2008 -+++ dialects/n+obsd/dlsof.hFri Feb 22 22:19:24 2008 +--- dialects/n+obsd/dlsof.h.orig Tue Mar 28 23:54:15 2006 dialects/n+obsd/dlsof.hWed Mar 14 10:04:34 2012 @@ -150,6 +150,7 @@ struct uio;/* dummy for function prototype in sys/bu struct nameidata; /* to satisfy a function prototype in msdosfsmount.h */ #include msdosfs/msdosfsmount.h @@ -9,3 +9,13 @@ $OpenBSD: patch-dialects_n+obsd_dlsof_h, #include msdosfs/direntry.h #include msdosfs/denode.h # endif /* defined(HASMSDOSFS) */ +@@ -416,8 +417,7 @@ struct vop_advlock_args; + + # if defined(UVM) + # if defined(OPENBSDV) +-#define _UVM_UVM_FAULT_I_H_ 1 /* avoid OpenBSD's +- /* uvm/uvm_fault_i.h */ ++#define _UVM_UVM_FAULT_I_H_ 1 /* avoid OpenBSD's uvm/uvm_fault_i.h */ + # endif /* defined(OPENBSDV) */ + #define FALSE 0 + #define TRUE1 Index: patches/patch-dialects_n+obsd_dproc_c === RCS file: /cvs/ports/sysutils/lsof/patches/patch-dialects_n+obsd_dproc_c,v retrieving revision 1.1 diff -u -p -r1.1 patch-dialects_n+obsd_dproc_c --- patches/patch-dialects_n+obsd_dproc_c 20 Jul 2011 13:50:08 - 1.1 +++ patches/patch-dialects_n+obsd_dproc_c 14 Mar 2012 09:22:22 - @@ -1,6 +1,6 @@ $OpenBSD: patch-dialects_n+obsd_dproc_c,v 1.1 2011/07/20 13:50:08 sthen Exp $ dialects/n+obsd/dproc.c.orig Wed May 11 13:54:00 2005 -+++ dialects/n+obsd/dproc.cTue Jul 19 10:27:27 2011 +--- dialects/n+obsd/dproc.c.orig Wed May 11 14:54:00 2005 dialects/n+obsd/dproc.cSun Jan 8 20:40:43 2012 @@ -172,7 +172,10 @@ gather_proc_info() static int pofb = 0; #endif/* defined(HASFSTRUCT) */ @@ -29,3 +29,149 @@ $OpenBSD: patch-dialects_n+obsd_dproc_c, if (!P) { (void) fprintf(stderr, %s: can't read process table: %s\n, +@@ -503,19 +508,98 @@ kread(addr, buf, len) + return((br == len) ? 0 : 1); + } + ++/* ++ * Download vmmap_entries from the kernel into our address space. ++ * We fix up the addr tree while downloading. ++ * ++ * Returns: the size of the tree on success, or -1 on failure. ++ * On failure, *rptr needs to be passed to unload_vmmap_entries to free ++ * the lot. ++ */ ++ssize_t ++load_vmmap_entries(KA_T kptr, struct vm_map_entry **rptr, ++struct vm_map_entry *parent) ++{ ++ struct vm_map_entry *entry; ++ KA_T left_kptr, right_kptr; ++ ssize_t left_sz; ++ ssize_t right_sz; + ++ if (kptr == 0) ++ return 0; ++ ++ /* Need space. */ ++ entry = malloc(sizeof(*entry)); ++ if (entry == NULL) ++ return -1; ++ ++ /* Download entry at kptr. */ ++ if (!kread(kptr, (char *)entry, sizeof(*entry))) { ++ free(entry); ++ return -1; ++ } ++ ++ /* ++ * Update addr pointers to have sane values in this address space. ++ * We save the kernel pointers in {left,right}_kptr, so we have them ++ * available to download children. ++ */ ++ left_kptr = (KA_T) RB_LEFT(entry, daddrs.addr_entry); ++ right_kptr = (KA_T) RB_RIGHT(entry, daddrs.addr_entry); ++ RB_LEFT(entry, daddrs.addr_entry) = ++ RB_RIGHT(entry, daddrs.addr_entry) =
Re: update lsof to work with vmmap
On 03/14/12 09:28, David Coppa wrote: Hi, The following diff, originally from Ariane, updates lsof to work with our new vmmap. Please test/comment, I'd like to have it committed... Ciao, David Built and runs on amd64/i386. Ok. Nigel
Re: update lsof to work with vmmap
On Wed, Mar 14, 2012 at 03:28:03AM -0600, David Coppa wrote: Hi, The following diff, originally from Ariane, updates lsof to work with our new vmmap. Please test/comment, I'd like to have it committed... build/runs i386 Ciao, David Index: Makefile === RCS file: /cvs/ports/sysutils/lsof/Makefile,v retrieving revision 1.83 diff -u -p -r1.83 Makefile --- Makefile 16 Nov 2011 00:25:05 - 1.83 +++ Makefile 14 Mar 2012 09:22:22 - @@ -5,7 +5,7 @@ COMMENT= list information about open fil VERSION= 4.83 DISTNAME=lsof_${VERSION} PKGNAME= ${DISTNAME:S/_/-/} -REVISION=7 +REVISION=8 CATEGORIES= sysutils MASTER_SITES= http://www.mirrorservice.org/sites/vic.cc.purdue.edu/pub/tools/unix/lsof/OLD/ \ ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ \ @@ -22,7 +22,7 @@ PERMIT_PACKAGE_CDROM= Yes PERMIT_PACKAGE_FTP= Yes PERMIT_DISTFILES_CDROM= Yes PERMIT_DISTFILES_FTP=Yes -WANTLIB= c kvm +WANTLIB= c kvm=13 MAKE_FLAGS= DEBUG=${CFLAGS} Index: patches/patch-dialects_n+obsd_dlsof_h === RCS file: /cvs/ports/sysutils/lsof/patches/patch-dialects_n+obsd_dlsof_h,v retrieving revision 1.3 diff -u -p -r1.3 patch-dialects_n+obsd_dlsof_h --- patches/patch-dialects_n+obsd_dlsof_h 23 Feb 2008 23:45:23 - 1.3 +++ patches/patch-dialects_n+obsd_dlsof_h 14 Mar 2012 09:22:22 - @@ -1,6 +1,6 @@ $OpenBSD: patch-dialects_n+obsd_dlsof_h,v 1.3 2008/02/23 23:45:23 sturm Exp $ dialects/n+obsd/dlsof.h.orig Fri Feb 22 22:18:35 2008 -+++ dialects/n+obsd/dlsof.h Fri Feb 22 22:19:24 2008 +--- dialects/n+obsd/dlsof.h.orig Tue Mar 28 23:54:15 2006 dialects/n+obsd/dlsof.h Wed Mar 14 10:04:34 2012 @@ -150,6 +150,7 @@ struct uio; /* dummy for function prototype in sys/bu struct nameidata; /* to satisfy a function prototype in msdosfsmount.h */ #include msdosfs/msdosfsmount.h @@ -9,3 +9,13 @@ $OpenBSD: patch-dialects_n+obsd_dlsof_h, #include msdosfs/direntry.h #include msdosfs/denode.h # endif /* defined(HASMSDOSFS) */ +@@ -416,8 +417,7 @@ struct vop_advlock_args; + + # ifdefined(UVM) + # if defined(OPENBSDV) +-#define _UVM_UVM_FAULT_I_H_ 1 /* avoid OpenBSD's +-/* uvm/uvm_fault_i.h */ ++#define _UVM_UVM_FAULT_I_H_ 1 /* avoid OpenBSD's uvm/uvm_fault_i.h */ + # endif/* defined(OPENBSDV) */ + #define FALSE 0 + #define TRUE1 Index: patches/patch-dialects_n+obsd_dproc_c === RCS file: /cvs/ports/sysutils/lsof/patches/patch-dialects_n+obsd_dproc_c,v retrieving revision 1.1 diff -u -p -r1.1 patch-dialects_n+obsd_dproc_c --- patches/patch-dialects_n+obsd_dproc_c 20 Jul 2011 13:50:08 - 1.1 +++ patches/patch-dialects_n+obsd_dproc_c 14 Mar 2012 09:22:22 - @@ -1,6 +1,6 @@ $OpenBSD: patch-dialects_n+obsd_dproc_c,v 1.1 2011/07/20 13:50:08 sthen Exp $ dialects/n+obsd/dproc.c.orig Wed May 11 13:54:00 2005 -+++ dialects/n+obsd/dproc.c Tue Jul 19 10:27:27 2011 +--- dialects/n+obsd/dproc.c.orig Wed May 11 14:54:00 2005 dialects/n+obsd/dproc.c Sun Jan 8 20:40:43 2012 @@ -172,7 +172,10 @@ gather_proc_info() static int pofb = 0; #endif /* defined(HASFSTRUCT) */ @@ -29,3 +29,149 @@ $OpenBSD: patch-dialects_n+obsd_dproc_c, if (!P) { (void) fprintf(stderr, %s: can't read process table: %s\n, +@@ -503,19 +508,98 @@ kread(addr, buf, len) + return((br == len) ? 0 : 1); + } + ++/* ++ * Download vmmap_entries from the kernel into our address space. ++ * We fix up the addr tree while downloading. ++ * ++ * Returns: the size of the tree on success, or -1 on failure. ++ * On failure, *rptr needs to be passed to unload_vmmap_entries to free ++ * the lot. ++ */ ++ssize_t ++load_vmmap_entries(KA_T kptr, struct vm_map_entry **rptr, ++struct vm_map_entry *parent) ++{ ++struct vm_map_entry *entry; ++KA_T left_kptr, right_kptr; ++ssize_t left_sz; ++ssize_t right_sz; + ++if (kptr == 0) ++return 0; ++ ++/* Need space. */ ++entry = malloc(sizeof(*entry)); ++if (entry == NULL) ++return -1; ++ ++/* Download entry at kptr. */ ++if (!kread(kptr, (char *)entry, sizeof(*entry))) { ++free(entry); ++return -1; ++} ++ ++/* ++ * Update addr pointers to have sane values in this address space. ++ * We save the kernel pointers in {left,right}_kptr, so we have them ++ * available to download children. ++ */ ++left_kptr = (KA_T) RB_LEFT(entry, daddrs.addr_entry); ++right_kptr = (KA_T)