1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
$NetBSD: patch-al,v 1.12 2001/08/10 10:25:58 martin Exp $
--- sysdeps/freebsd/prockernel.c.orig Sat Oct 16 20:31:43 1999
+++ sysdeps/freebsd/prockernel.c Fri Aug 10 12:21:52 2001
@@ -34,7 +34,7 @@
#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__)
@@ -48,6 +48,13 @@
#include <osreldate.h>
#endif
+#ifdef __NetBSD__
+#include <machine/vmparam.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) +
@@ -129,8 +136,15 @@
glibtop_suid_enter (server);
+#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 +163,12 @@
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,14 +185,39 @@
/*xxx FreeBSD/Alpha? */
#endif
#else
+#ifdef __i386__
buf->kstk_esp = (u_int64_t) pcb.pcb_tss.tss_esp0;
#ifdef __bsdi__
buf->kstk_eip = (u_int64_t) pcb.pcb_tss.tss_eip;
#else
buf->kstk_eip = (u_int64_t) 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
}
|