From b1e908e6b64b5aab66058eebc9899bcccb342e40 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Wed, 26 May 1999 13:21:19 +0000 Subject: [PATCH] More NetBSD 1.4 fixes. 1999-05-26 Martin Baulig More NetBSD 1.4 fixes. * mem.c, procmap.c, procmem.c: Make this work with the new UVM code. [FIXME: This following most likely works on all BSD systems, but this needs to be tested; I made it conditional to NetBSD 1.4 at the moment. Please extend the conditionals to any other systems where this works ...] * procstate.c: Added `ruid' and `rgid' for LibGTop >= 1.1.0. * procuid.c: Added `ngroups' and `groups' for LibGTop >= 1.1.0. --- sysdeps/freebsd/ChangeLog | 14 ++++++++++++ sysdeps/freebsd/mem.c | 1 + sysdeps/freebsd/procmap.c | 45 +++++++++++++++++++++++++++++++++++++ sysdeps/freebsd/procmem.c | 45 ++++++++++++++++++++++++++----------- sysdeps/freebsd/procstate.c | 18 +++++++++++++-- sysdeps/freebsd/procuid.c | 45 ++++++++++++++++++++++++++++++++++++- 6 files changed, 152 insertions(+), 16 deletions(-) diff --git a/sysdeps/freebsd/ChangeLog b/sysdeps/freebsd/ChangeLog index 7503cc43..8fa3675c 100644 --- a/sysdeps/freebsd/ChangeLog +++ b/sysdeps/freebsd/ChangeLog @@ -1,3 +1,17 @@ +1999-05-26 Martin Baulig + + More NetBSD 1.4 fixes. + + * mem.c, procmap.c, procmem.c: Make this work with the new UVM code. + + [FIXME: This following most likely works on all BSD systems, but + this needs to be tested; I made it conditional to NetBSD 1.4 at + the moment. Please extend the conditionals to any other systems + where this works ...] + + * procstate.c: Added `ruid' and `rgid' for LibGTop >= 1.1.0. + * procuid.c: Added `ngroups' and `groups' for LibGTop >= 1.1.0. + 1999-05-25 Martin Baulig * ppp.c: Make this work on NetBSD. diff --git a/sysdeps/freebsd/mem.c b/sysdeps/freebsd/mem.c index 39b76e7a..0afafc0c 100644 --- a/sysdeps/freebsd/mem.c +++ b/sysdeps/freebsd/mem.c @@ -174,6 +174,7 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf) #else #if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) v_total_count = uvmexp.reserve_kernel + + uvmexp.reserve_pagedaemon + uvmexp.free + uvmexp.wired + uvmexp.active + uvmexp.inactive; fprintf (stderr, "TEST: %d - %d\n", v_total_count, diff --git a/sysdeps/freebsd/procmap.c b/sysdeps/freebsd/procmap.c index 1090d4b2..f29445b5 100644 --- a/sysdeps/freebsd/procmap.c +++ b/sysdeps/freebsd/procmap.c @@ -48,6 +48,14 @@ #include #include +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) +/* Fixme ... */ +#undef _KERNEL +#define _UVM_UVM_AMAP_I_H_ 1 +#define _UVM_UVM_MAP_I_H_ 1 +#include +#endif + static const unsigned long _glibtop_sysdeps_proc_map = (1L << GLIBTOP_PROC_MAP_TOTAL) + (1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_SIZE); @@ -74,11 +82,18 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, struct kinfo_proc *pinfo; struct vm_map_entry entry, *first; struct vmspace vmspace; +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + struct vnode vnode; + struct inode inode; +#else struct vm_object object; +#endif glibtop_map_entry *maps; +#if defined __FreeBSD__ struct vnode vnode; struct inode inode; struct mount mount; +#endif int count, i = 0; int update = 0; @@ -149,6 +164,8 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, #endif #else #if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + if (UVM_ET_ISSUBMAP (&entry)) + continue; #else if (entry.is_a_map || entry.is_sub_map) continue; @@ -173,6 +190,17 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, i++; #if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + if (!entry.object.uvm_obj) + continue; + + /* We're only interested in vnodes */ + + if (kvm_read (server->machine.kd, + (unsigned long) entry.object.uvm_obj, + &vnode, sizeof (vnode)) != sizeof (vnode)) { + glibtop_warn_io_r (server, "kvm_read (vnode)"); + return NULL; + } #else if (!entry.object.vm_object) continue; @@ -185,6 +213,23 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, glibtop_error_io_r (server, "kvm_read (object)"); #endif +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID) + continue; + + if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) || + !vnode.v_data) continue; + + if (kvm_read (server->machine.kd, + (unsigned long) vnode.v_data, + &inode, sizeof (inode)) != sizeof (inode)) + glibtop_error_io_r (server, "kvm_read (inode)"); + + maps [i-1].inode = inode.i_number; + maps [i-1].device = inode.i_dev; +#endif + + #ifdef __FreeBSD__ /* If the object is of type vnode, add its size */ diff --git a/sysdeps/freebsd/procmem.c b/sysdeps/freebsd/procmem.c index 9492ba6d..05f66001 100644 --- a/sysdeps/freebsd/procmem.c +++ b/sysdeps/freebsd/procmem.c @@ -56,11 +56,19 @@ static const unsigned long _glibtop_sysdeps_proc_mem = (1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) + -(1L << GLIBTOP_PROC_MEM_SHARE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS) + (1L << GLIBTOP_PROC_MEM_RSS_RLIM); +static const unsigned long _glibtop_sysdeps_proc_mem_share = +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) +(1L << GLIBTOP_PROC_MEM_SHARE); +#elif defined(__FreeBSD__) +(1L << GLIBTOP_PROC_MEM_SHARE); +#else +0; +#endif + #ifndef LOG1024 #define LOG1024 10 #endif @@ -90,7 +98,8 @@ glibtop_init_proc_mem_p (glibtop *server) /* we only need the amount of log(2)1024 for our conversion */ pageshift -= LOG1024; - server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem; + server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem | + _glibtop_sysdeps_proc_mem_share; } /* Provides detailed information about a process. */ @@ -103,7 +112,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, struct vm_map_entry entry, *first; struct vmspace *vms, vmspace; #if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) - struct uvm_object object; + struct vnode vnode; + struct inode inode; #else struct vm_object object; #endif @@ -199,12 +209,12 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, if (!entry.object.uvm_obj) continue; - /* We're only interested in `uvm_obj's */ + /* We're only interested in vnodes */ if (kvm_read (server->machine.kd, (unsigned long) entry.object.uvm_obj, - &object, sizeof (object)) != sizeof (object)) { - glibtop_warn_io_r (server, "kvm_read (object)"); + &vnode, sizeof (vnode)) != sizeof (vnode)) { + glibtop_warn_io_r (server, "kvm_read (vnode)"); return; } #else @@ -222,19 +232,28 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf, #endif /* If the object is of type vnode, add its size */ +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID) + continue; + + if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) || + !vnode.v_data) continue; + + /* Reference count must be at least two. */ + if (vnode.v_uvm.u_obj.uo_refs <= 1) + continue; + + buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024; +#endif + #ifdef __FreeBSD__ if (object.type != OBJT_VNODE) continue; buf->share += object.un_pager.vnp.vnp_size; -#else -#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) - buf->share += pagetok (object.uo_npages) << LOG1024; -#else - buf->share += object.size; -#endif #endif } - buf->flags = _glibtop_sysdeps_proc_mem; + buf->flags = _glibtop_sysdeps_proc_mem | + _glibtop_sysdeps_proc_mem_share; } diff --git a/sysdeps/freebsd/procstate.c b/sysdeps/freebsd/procstate.c index b04df0fc..35cff52d 100644 --- a/sysdeps/freebsd/procstate.c +++ b/sysdeps/freebsd/procstate.c @@ -36,12 +36,20 @@ static const unsigned long _glibtop_sysdeps_proc_state = (1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID); +static const unsigned long _glibtop_sysdeps_proc_state_new = +#if LIBGTOP_VERSION_CODE >= 1001000 +(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID); +#else +0; +#endif + /* Init function. */ void glibtop_init_proc_state_p (glibtop *server) { - server->sysdeps.proc_state = _glibtop_sysdeps_proc_state; + server->sysdeps.proc_state = _glibtop_sysdeps_proc_state | + _glibtop_sysdeps_proc_state_new; } /* Provides detailed information about a process. */ @@ -74,8 +82,14 @@ glibtop_get_proc_state_p (glibtop *server, buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid; buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid; +#if LIBGTOP_VERSION_CODE >= 1001000 + buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid; + buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid; +#endif + /* Set the flags for the data we're about to return*/ - buf->flags = _glibtop_sysdeps_proc_state; + buf->flags = _glibtop_sysdeps_proc_state | + _glibtop_sysdeps_proc_state_new; switch (pinfo [0].kp_proc.p_stat) { case SIDL: diff --git a/sysdeps/freebsd/procuid.c b/sysdeps/freebsd/procuid.c index 3f68a3b1..4ef63375 100644 --- a/sysdeps/freebsd/procuid.c +++ b/sysdeps/freebsd/procuid.c @@ -34,12 +34,22 @@ static const unsigned long _glibtop_sysdeps_proc_uid = (1L << GLIBTOP_PROC_UID_TPGID) + (1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE); +static const unsigned long _glibtop_sysdeps_proc_uid_groups = +#if LIBGTOP_VERSION_CODE >= 1001000 +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) +(1L << GLIBTOP_PROC_UID_NGROUPS) + (1L << GLIBTOP_PROC_UID_GROUPS); +#endif +#else +0; +#endif + /* Init function. */ void glibtop_init_proc_uid_p (glibtop *server) { - server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid; + server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid | + _glibtop_sysdeps_proc_uid_groups; } /* Provides detailed information about a process. */ @@ -51,6 +61,13 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, struct kinfo_proc *pinfo; int count = 0; +#if LIBGTOP_VERSION_CODE >= 1001000 +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + struct ucred ucred; + void *ucred_ptr; +#endif +#endif + glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0); memset (buf, 0, sizeof (glibtop_proc_uid)); @@ -80,4 +97,30 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf, /* Set the flags for the data we're about to return*/ buf->flags = _glibtop_sysdeps_proc_uid; + /* Use LibGTop conditionals here so we can more easily merge this + * code into the LIBGTOP_STABLE_1_0 branch. */ +#if LIBGTOP_VERSION_CODE >= 1001000 + /* This probably also works with other versions, but not yet + * tested. Please remove the conditional if this is true. */ +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000) + ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred; + + if (ucred_ptr) { + if (kvm_read (server->machine.kd, (unsigned long) ucred_ptr, + &ucred, sizeof (ucred)) != sizeof (ucred)) { + glibtop_warn_io_r (server, "kvm_read (ucred)"); + } else { + int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ? + ucred.cr_ngroups : GLIBTOP_MAX_GROUPS; + int i; + + for (i = 0; i < count; i++) + buf->groups [i] = ucred.cr_groups [i]; + buf->ngroups = count; + + buf->flags |= _glibtop_sysdeps_proc_uid_groups; + } + } +#endif +#endif }