implement NetBSD support, and some build problems on FreeBSD (Closes:

2004-03-09  Bastien Nocera  <hadess@hadess.net>

	* Makefile.am:
	* cpu.c: (glibtop_init_cpu_p), (glibtop_get_cpu_p):
	* glibtop_machine.h:
	* mem.c:
	* netload.c: (glibtop_get_netload_p):
	* prockernel.c: (glibtop_get_proc_kernel_p):
	* proclist.c: (glibtop_get_proclist_p):
	* procmap.c: (glibtop_get_proc_map_p):
	* procmem.c: (glibtop_get_proc_mem_p):
	* procsignal.c: (glibtop_get_proc_signal_p):
	* procstate.c: (glibtop_get_proc_state_p):
	* proctime.c:
	* procuid.c: (glibtop_get_proc_uid_p):
	* uptime.c: (glibtop_get_uptime_p): implement NetBSD support, and
	some build problems on FreeBSD (Closes: #135674)
This commit is contained in:
Bastien Nocera
2004-03-09 23:13:31 +00:00
committed by Bastien Nocera
parent a795ff4847
commit 4bd9752d52
15 changed files with 420 additions and 83 deletions

View File

@@ -34,12 +34,10 @@
#if (!defined __OpenBSD__) && (!defined __bsdi__)
#include <sys/user.h>
#endif
#if !defined(__bsdi__) && !(defined(__FreeBSD__) && defined(__alpha__))
#if !defined(__bsdi__) && !(defined(__FreeBSD__) && defined(__alpha__)) && \
!defined(__NetBSD__)
#include <machine/pcb.h>
#endif
#if defined(__FreeBSD__) && !defined(__alpha__)
#include <machine/tss.h>
#endif
#include <unistd.h>
#include <fcntl.h>
@@ -48,6 +46,23 @@
#include <osreldate.h>
#endif
#ifdef __NetBSD__
#include <machine/vmparam.h>
#include <machine/pmap.h>
#ifdef __arm32__
#define KERNBASE KERNEL_BASE
#endif
#endif
#ifdef __NetBSD__
#include <machine/vmparam.h>
#include <machine/pmap.h>
#ifdef __arm32__
#define KERNBASE KERNEL_BASE
#endif
#endif
static const unsigned long _glibtop_sysdeps_proc_kernel_pstats =
(1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
@@ -78,9 +93,11 @@ glibtop_get_proc_kernel_p (glibtop *server,
pid_t pid)
{
struct kinfo_proc *pinfo;
#ifndef __FreeBSD__
struct user *u_addr = (struct user *)USRSTACK;
struct pstats pstats;
struct pcb pcb;
#endif
int count;
char filename [BUFSIZ];
@@ -101,17 +118,36 @@ glibtop_get_proc_kernel_p (glibtop *server,
if ((pinfo == NULL) || (count != 1))
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
buf->nwchan = (unsigned long) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
#if defined(__FreeBSD__) && (__FreeBSD_version >= 500013)
#define PROC_WCHAN ki_wchan
#define PROC_WMESG ki_wmesg
#define PROC_WMESG ki_wmesg
#else
#define PROC_WCHAN kp_proc.p_wchan
#define PROC_WMESG kp_proc.p_wmesg
#define PROC_WMESG kp_eproc.e_wmesg
#endif
#if !defined(__NetBSD__) || !defined(SACTIVE)
buf->nwchan = (unsigned long) pinfo [0].PROC_WCHAN &~ KERNBASE;
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_NWCHAN);
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
if (pinfo [0].PROC_WCHAN && pinfo [0].PROC_WMESG) {
strncpy (buf->wchan, pinfo [0].PROC_WMESG,
sizeof (buf->wchan) - 1);
buf->wchan [sizeof (buf->wchan) - 1] = 0;
buf->flags |= (1L << GLIBTOP_PROC_KERNEL_WCHAN);
} else {
buf->wchan [0] = 0;
}
#endif
#ifndef __FreeBSD__
/* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
@@ -129,8 +165,17 @@ glibtop_get_proc_kernel_p (glibtop *server,
glibtop_suid_enter (server);
#if !defined(__NetBSD__) || !defined(SACTIVE)
#ifdef __NetBSD__
/* On NetBSD, there is no kvm_uread(), and kvm_read() always reads
* from kernel memory. */
if (kvm_read (server->machine.kd,
#else
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
#endif
(unsigned long) &u_addr->u_stats,
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
{
@@ -149,8 +194,12 @@ glibtop_get_proc_kernel_p (glibtop *server,
buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
}
#ifdef __NetBSD__
if (kvm_read (server->machine.kd,
#else
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
#endif
(unsigned long) &u_addr->u_pcb,
(char *) &pcb, sizeof (pcb)) == sizeof (pcb))
{
@@ -167,18 +216,52 @@ glibtop_get_proc_kernel_p (glibtop *server,
/*xxx FreeBSD/Alpha? */
#endif
#else
#ifdef __i386__
buf->kstk_esp = (guint64) pcb.pcb_tss.tss_esp0;
#ifdef __bsdi__
buf->kstk_eip = (guint64) pcb.pcb_tss.tss_eip;
#else
buf->kstk_eip = (guint64) pcb.pcb_tss.__tss_eip;
#endif
#else
#if defined(__NetBSD__)
#if defined(__m68k__)
buf->kstk_esp = (u_int64_t) pcb.pcb_usp;
buf->kstk_eip = (u_int64_t) 0;
#elif (defined(__arm32__) || defined(__powerpc__))
buf->kstk_esp = (u_int64_t) pcb.pcb_sp;
buf->kstk_eip = (u_int64_t) 0;
#elif defined(__mipsel__)
buf->kstk_esp = (u_int64_t) pcb.pcb_context[8];
buf->kstk_eip = (u_int64_t) 0;
#elif defined(__sparc__)
buf->kstk_esp = (u_int64_t) pcb.pcb_sp;
buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
#elif defined(__alpha__)
buf->kstk_esp = (u_int64_t) pcb.pcb_context[9];
buf->kstk_eip = (u_int64_t) pcb.pcb_context[8];
#else
/* provide some defaults for other platforms */
buf->kstk_esp = (u_int64_t) 0;
buf->kstk_eip = (u_int64_t) 0;
#endif /* ${MACHINE_ARCH} */
#endif /* __NetBSD__ */
buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
#endif
#endif
}
#endif
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
glibtop_suid_leave (server);
#else
/* XXX: the code here was, quite frankly, junk, and almost
* certainly wrong - remove it all, leave these fields
* unpopulated, and give up until such time as the right
* code is produced for both FreeBSD 4.x and 5.x
*/
return;
#endif /* __FreeBSD__ */
}