View | Details | Raw Unified | Return to bug 242533 | Differences between
and this patch

Collapse All | Expand All

(-)devel/libgtop/files/patch-sysdeps_freebsd_procmap.c (-12 / +112 lines)
Lines 1-5 Link Here
1
--- sysdeps/freebsd/procmap.c.orig	2015-08-17 18:59:37 UTC
1
--- sysdeps/freebsd/procmap.c.orig	2017-08-07 18:43:41.000000000 -0400
2
+++ sysdeps/freebsd/procmap.c
2
+++ sysdeps/freebsd/procmap.c	2020-01-10 22:59:48.661882000 +0900
3
@@ -52,6 +52,8 @@
3
@@ -52,6 +52,8 @@
4
 #include <sys/mount.h>
4
 #include <sys/mount.h>
5
 #include <ufs/ufs/quota.h>
5
 #include <ufs/ufs/quota.h>
Lines 9-15 Link Here
9
 #include <fs/devfs/devfs.h>
9
 #include <fs/devfs/devfs.h>
10
 #if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
10
 #if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
11
 #include <fs/devfs/devfs_int.h>
11
 #include <fs/devfs/devfs_int.h>
12
@@ -86,6 +88,8 @@ _glibtop_sysdeps_freebsd_dev_inode (glib
12
@@ -95,12 +97,14 @@ _glibtop_sysdeps_freebsd_dev_inode (glibtop *server, s
13
         struct cdev_priv priv;
13
         struct cdev_priv priv;
14
 #if __FreeBSD_version < 800039
14
 #if __FreeBSD_version < 800039
15
         struct cdev si;
15
         struct cdev si;
Lines 18-31 Link Here
18
 #endif
18
 #endif
19
 
19
 
20
         *inum = 0;
20
         *inum = 0;
21
@@ -167,7 +171,9 @@ _glibtop_sysdeps_freebsd_dev_inode (glib
21
         *dev = 0;
22
 
22
 
23
-        if (kvm_read (server->machine->kd, (gulong) &vnode->v_tag,
24
+        if (kvm_read (server->machine->kd, (gulong) &vnode->v_lock.lock_object.lo_name,
25
  	             (char *) &tagptr, sizeof (tagptr)) != sizeof (tagptr) ||
26
             kvm_read (server->machine->kd, (gulong) tagptr,
27
 		     (char *) tagstr, sizeof (tagstr)) != sizeof (tagstr))
28
@@ -231,6 +235,32 @@ _glibtop_init_proc_map_p (glibtop *server)
29
         server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
30
 }
23
 
31
 
24
 #if (__FreeBSD_version >= 800039) || (__FreeBSD_kernel_version >= 800039)
32
+static int
25
-        if (kvm_read (server->machine->kd, (gulong) cdev2priv(inode.i_dev), (char *) &priv,
33
+vm_map_reader(void *token, vm_map_entry_t addr, vm_map_entry_t dest)
26
+        if (kvm_read (server->machine->kd, (gulong) inode.i_ump, (char *) &um,
34
+{
27
+		      sizeof (um)) != sizeof (um) ||
35
+	kvm_t *kd;
28
+            kvm_read (server->machine->kd, (gulong) cdev2priv(um.um_dev), (char *) &priv,
36
+
29
 		      sizeof (priv))
37
+	kd = (kvm_t *)token;
30
 #else
38
+	return (kvm_read (kd, (gulong) addr, dest, sizeof(*dest)) == sizeof(*dest));
31
         if (kvm_read (server->machine->kd, (gulong) inode.i_dev, (char *) &si,
39
+}
40
+
41
+#if (__FreeBSD_version < 1300062)
42
+typedef int vm_map_entry_reader(void *token, vm_map_entry_t addr,
43
+    vm_map_entry_t dest);
44
+
45
+static inline vm_map_entry_t
46
+vm_map_entry_read_succ(void *token, struct vm_map_entry *const clone,
47
+     vm_map_entry_reader reader)
48
+{
49
+	vm_map_entry_t next;
50
+
51
+	next = clone->next;
52
+	if (!reader (token, next, clone))
53
+		return (NULL);
54
+	return (next);
55
+}
56
+#endif
57
+
58
 /* Provides detailed information about a process. */
59
 
60
 glibtop_map_entry *
61
@@ -238,13 +268,12 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_
62
                         pid_t pid)
63
 {
64
         struct kinfo_proc *pinfo;
65
-        struct vm_map_entry entry, *first;
66
+        struct vm_map_entry entry;
67
         struct vmspace vmspace;
68
         struct vm_object object;
69
         GArray *maps;
70
         struct vnode vnode;
71
-        int count;
72
-        int update = 0;
73
+        int i, count;
74
 
75
         memset (buf, 0, sizeof (glibtop_proc_map));
76
 
77
@@ -273,16 +302,6 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_
78
                 return NULL;
79
         }
80
 
81
-        first = vmspace.vm_map.header.next;
82
-
83
-        if (kvm_read (server->machine->kd,
84
-                        (gulong) vmspace.vm_map.header.next,
85
-                        (char *) &entry, sizeof (entry)) != sizeof (entry)) {
86
-                glibtop_warn_io_r (server, "kvm_read (entry)");
87
-		glibtop_suid_leave (server);
88
-                return NULL;
89
-        }
90
-
91
         /* Walk through the `vm_map_entry' list ... */
92
 
93
         /* I tested this a few times with `mmap'; as soon as you write
94
@@ -292,21 +311,17 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_
95
         maps = g_array_sized_new(FALSE, FALSE, sizeof(glibtop_map_entry),
96
                                  vmspace.vm_map.nentries);
97
 
98
-        do {
99
+	entry = vmspace.vm_map.header;
100
+        for (i = 0; i < vmspace.vm_map.nentries; i++) {
101
                 glibtop_map_entry *mentry;
102
                 guint64 inum, dev;
103
                 guint len;
104
 
105
-                if (update) {
106
-                        if (kvm_read (server->machine->kd,
107
-                                        (gulong) entry.next,
108
-                                        (char *) &entry, sizeof (entry)) != sizeof (entry)) {
109
-                                glibtop_warn_io_r (server, "kvm_read (entry)");
110
-                                continue;
111
-                        }
112
-                } else {
113
-                        update = 1;
114
-                }
115
+		if (!vm_map_entry_read_succ(server->machine->kd, &entry, vm_map_reader)) {
116
+			glibtop_warn_io_r (server, "kvm_read (entry)");
117
+			glibtop_suid_leave (server);
118
+			return NULL;
119
+		}
120
 
121
                 if (entry.eflags & (MAP_ENTRY_IS_SUB_MAP))
122
                         continue;
123
@@ -377,7 +392,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_
124
                 if (entry.protection & VM_PROT_EXECUTE)
125
                         mentry->perm |= GLIBTOP_MAP_PERM_EXECUTE;
126
 
127
-        } while (entry.next != first);
128
+        }
129
 
130
         glibtop_suid_leave (server);
131
 

Return to bug 242533