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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile
index c8e33c5..09debed 100644
--- a/mach-defpager/Makefile
+++ b/mach-defpager/Makefile
@@ -29,6 +29,7 @@ OBJS := $(SRCS:.c=.o) \
memory_object default_pager memory_object_default exc) \
default_pager_replyUser.o
+HURDLIBS:= ihash
OTHERLIBS:= -lpthread
LDFLAGS += -static
diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c
index eb444a6..f514ea6 100644
--- a/mach-defpager/default_pager.c
+++ b/mach-defpager/default_pager.c
@@ -38,10 +38,13 @@
#include <mach/default_pager_types.h>
#include <pthread.h>
+#include <stddef.h>
#include <device/device_types.h>
#include <device/device.h>
+#include <hurd/ihash.h>
+
#include "queue.h"
#include "wiring.h"
#include "kalloc.h"
@@ -1781,25 +1784,14 @@ default_has_page(ds, offset)
#define dstruct_unlock(ds)
#endif /* PARALLEL */
-/*
- * List of all pagers. A specific pager is
- * found directly via its port, this list is
- * only used for monitoring purposes by the
- * default_pager_object* calls
- */
-struct pager_port {
- queue_head_t queue;
- pthread_mutex_t lock;
- int count; /* saves code */
- queue_head_t leak_queue;
-} all_pagers;
+struct pager_port all_pagers;
#define pager_port_list_init() \
{ \
pthread_mutex_init(&all_pagers.lock, NULL); \
- queue_init(&all_pagers.queue); \
+ hurd_ihash_init (&all_pagers.htable, \
+ offsetof (struct dstruct, htable_locp)); \
queue_init(&all_pagers.leak_queue); \
- all_pagers.count = 0; \
}
void pager_port_list_insert(port, ds)
@@ -1807,8 +1799,9 @@ void pager_port_list_insert(port, ds)
default_pager_t ds;
{
pthread_mutex_lock(&all_pagers.lock);
- queue_enter(&all_pagers.queue, ds, default_pager_t, links);
- all_pagers.count++;
+ hurd_ihash_add (&all_pagers.htable,
+ (hurd_ihash_key_t) port,
+ (hurd_ihash_value_t) ds);
pthread_mutex_unlock(&all_pagers.lock);
}
@@ -1816,8 +1809,8 @@ void pager_port_list_delete(ds)
default_pager_t ds;
{
pthread_mutex_lock(&all_pagers.lock);
- queue_remove(&all_pagers.queue, ds, default_pager_t, links);
- all_pagers.count--;
+ hurd_ihash_locp_remove (&all_pagers.htable,
+ ds->htable_locp);
pthread_mutex_unlock(&all_pagers.lock);
}
@@ -1864,7 +1857,8 @@ dprintf("Partition x%x (id x%x) for %s, all_ok %d\n", part, id, name, all_ok);
pthread_mutex_lock(&part->p_lock);
pthread_mutex_lock(&all_pagers.lock);
- queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
+ HURD_IHASH_ITERATE (&all_pagers.htable, val) {
+ entry = (default_pager_t) val;
dstruct_lock(entry);
@@ -2238,7 +2232,6 @@ seqnos_memory_object_create(old_pager, seqno, new_pager, new_size,
vm_size_t new_page_size;
{
default_pager_t ds;
- kern_return_t kr;
assert(old_pager == default_pager_default_port);
assert(MACH_PORT_VALID(new_pager_request));
@@ -2246,24 +2239,6 @@ seqnos_memory_object_create(old_pager, seqno, new_pager, new_size,
assert(new_page_size == vm_page_size);
ds = pager_port_alloc(new_size);
-rename_it:
- kr = mach_port_rename( default_pager_self,
- new_pager, (mach_port_t)pnameof(ds));
- if (kr != KERN_SUCCESS) {
- default_pager_t ds1;
-
- if (kr != KERN_NAME_EXISTS)
- panic("%s m_o_create", my_name);
- ds1 = (default_pager_t) kalloc(sizeof *ds1);
- *ds1 = *ds;
- pthread_mutex_lock(&all_pagers.lock);
- queue_enter(&all_pagers.leak_queue, ds, default_pager_t, links);
- pthread_mutex_unlock(&all_pagers.lock);
- ds = ds1;
- goto rename_it;
- }
-
- new_pager = (mach_port_t) pnameof(ds);
/*
* Set up associations between these ports
@@ -3195,23 +3170,14 @@ S_default_pager_object_create (mach_port_t pager,
return KERN_INVALID_ARGUMENT;
ds = pager_port_alloc(size);
-rename_it:
- port = (mach_port_t) pnameof(ds);
- result = mach_port_allocate_name(default_pager_self,
- MACH_PORT_RIGHT_RECEIVE, port);
- if (result != KERN_SUCCESS) {
- default_pager_t ds1;
-
- if (result != KERN_NAME_EXISTS) return (result);
-
- ds1 = (default_pager_t) kalloc(sizeof *ds1);
- *ds1 = *ds;
- pthread_mutex_lock(&all_pagers.lock);
- queue_enter(&all_pagers.leak_queue, ds, default_pager_t, links);
- pthread_mutex_unlock(&all_pagers.lock);
- ds = ds1;
- goto rename_it;
- }
+ result = mach_port_allocate (default_pager_self,
+ MACH_PORT_RIGHT_RECEIVE,
+ &port);
+ if (result != KERN_SUCCESS)
+ {
+ kfree ((char *) ds, sizeof *ds);
+ return result;
+ }
/*
* Set up associations between these ports
@@ -3285,7 +3251,7 @@ S_default_pager_objects (mach_port_t pager,
/*
* We will send no more than this many
*/
- actual = all_pagers.count;
+ actual = all_pagers.htable.nr_items;
pthread_mutex_unlock(&all_pagers.lock);
if (opotential < actual) {
@@ -3327,7 +3293,8 @@ S_default_pager_objects (mach_port_t pager,
pthread_mutex_lock(&all_pagers.lock);
num_pagers = 0;
- queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
+ HURD_IHASH_ITERATE (&all_pagers.htable, val) {
+ entry = (default_pager_t) val;
mach_port_t port;
vm_size_t size;
@@ -3505,7 +3472,8 @@ S_default_pager_object_pages (mach_port_t pager,
default_pager_t entry;
pthread_mutex_lock(&all_pagers.lock);
- queue_iterate(&all_pagers.queue, entry, default_pager_t, links) {
+ HURD_IHASH_ITERATE (&all_pagers.htable, val) {
+ entry = (default_pager_t) val;
dstruct_lock(entry);
if (entry->pager_name == object) {
pthread_mutex_unlock(&all_pagers.lock);
diff --git a/mach-defpager/mig-decls.h b/mach-defpager/mig-decls.h
index f63fef2..8118d61 100644
--- a/mach-defpager/mig-decls.h
+++ b/mach-defpager/mig-decls.h
@@ -27,11 +27,8 @@
static inline struct dstruct * __attribute__ ((unused))
begin_using_default_pager (mach_port_t port)
{
- if (! MACH_PORT_VALID(port)
- || ((default_pager_t) dnameof(port))->pager != (port))
- return DEFAULT_PAGER_NULL;
-
- return (default_pager_t) dnameof(port);
+ return (default_pager_t) hurd_ihash_find (&all_pagers.htable,
+ (hurd_ihash_key_t) port);
}
#endif /* __MACH_DEFPAGER_MIG_DECLS_H__ */
diff --git a/mach-defpager/priv.h b/mach-defpager/priv.h
index 20711b2..3684565 100644
--- a/mach-defpager/priv.h
+++ b/mach-defpager/priv.h
@@ -29,6 +29,7 @@
#include <mach.h>
#include <queue.h>
+#include <hurd/ihash.h>
/*
* Bitmap allocation.
@@ -150,6 +151,7 @@ typedef struct dpager *dpager_t;
* Mapping between pager port and paging object.
*/
struct dstruct {
+ hurd_ihash_locp_t htable_locp; /* for the ihash table */
queue_chain_t links; /* Link in pager-port list */
pthread_mutex_t lock; /* Lock for the structure */
@@ -180,9 +182,19 @@ struct dstruct {
typedef struct dstruct * default_pager_t;
#define DEFAULT_PAGER_NULL ((default_pager_t)0)
-/* given a data structure return a good port-name to associate it to */
-#define pnameof(_x_) (((vm_offset_t) (_x_)) + 1)
-/* reverse, assumes no-odd-pointers */
-#define dnameof(_x_) (((vm_offset_t) (_x_)) & ~1)
+/*
+ * List of all pagers. A specific pager is
+ * found directly via its port, this list is
+ * only used for monitoring purposes by the
+ * default_pager_object* calls
+ */
+struct pager_port {
+ struct hurd_ihash htable;
+ pthread_mutex_t lock;
+ queue_head_t leak_queue;
+};
+
+/* The list of pagers. */
+extern struct pager_port all_pagers;
#endif /* __MACH_DEFPAGER_PRIV_H__ */
|