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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
|
diff --git a/hurd/default_pager.defs b/hurd/default_pager.defs
index 8ad82dc..4885503 100644
--- a/hurd/default_pager.defs
+++ b/hurd/default_pager.defs
@@ -36,6 +36,10 @@ subsystem default_pager 2275;
import <hurd/default_pager_types.h>; /* XXX */
+#ifdef DEFAULT_PAGER_IMPORTS
+DEFAULT_PAGER_IMPORTS
+#endif
+
routine default_pager_object_create(
default_pager : mach_port_t;
out memory_object : memory_object_t =
@@ -90,6 +94,6 @@ routine default_pager_paging_storage(
to fix the object's maximum size. Any references to pages beyond the limit
will fail. */
routine default_pager_object_set_size(
- memory_object : mach_port_t;
+ memory_object : memory_object_t;
msgseqno seqno : mach_port_seqno_t;
object_size_limit : vm_size_t);
diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile
index e38a0be..c8e33c5 100644
--- a/mach-defpager/Makefile
+++ b/mach-defpager/Makefile
@@ -34,4 +34,4 @@ LDFLAGS += -static
include ../Makeconf
-MIGSFLAGS = -DSEQNOS
+MIGSFLAGS = -DSEQNOS -imacros $(srcdir)/mig-mutate.h
diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c
index 8f8e13e..b718262 100644
--- a/mach-defpager/default_pager.c
+++ b/mach-defpager/default_pager.c
@@ -60,6 +60,8 @@
#include "default_pager_S.h"
#include "exc_S.h"
+#include "priv.h"
+
#define debug 0
static char my_name[] = "(default pager):";
@@ -106,47 +108,6 @@ synchronized_printf (const char *fmt, ...)
#define ptoa(p) ((p)*vm_page_size)
#define atop(a) ((a)/vm_page_size)
-/*
- * Bitmap allocation.
- */
-typedef unsigned int bm_entry_t;
-#define NB_BM 32
-#define BM_MASK 0xffffffff
-
-#define howmany(a,b) (((a) + (b) - 1)/(b))
-
-/*
- * Value to indicate no block assigned
- */
-#define NO_BLOCK ((vm_offset_t)-1)
-
-/*
- * 'Partition' structure for each paging area.
- * Controls allocation of blocks within paging area.
- */
-struct part {
- pthread_mutex_t p_lock; /* for bitmap/free */
- vm_size_t total_size; /* total number of blocks */
- vm_size_t free; /* number of blocks free */
- unsigned int id; /* named lookup */
- bm_entry_t *bitmap; /* allocation map */
- boolean_t going_away; /* destroy attempt in progress */
- struct file_direct *file; /* file paged to */
-};
-typedef struct part *partition_t;
-
-struct {
- pthread_mutex_t lock;
- int n_partitions;
- partition_t *partition_list;/* array, for quick mapping */
-} all_partitions; /* list of all such */
-
-typedef unsigned char p_index_t;
-
-#define P_INDEX_INVALID ((p_index_t)-1)
-
-#define no_partition(x) ((x) == P_INDEX_INVALID)
-
partition_t partition_of(x)
int x;
{
@@ -632,81 +593,6 @@ ddprintf ("pager_dealloc_page(%d,%x,%d)\n",pindex,page,lock_it);
}
/*
- * Allocation info for each paging object.
- *
- * Most operations, even pager_write_offset and pager_put_checksum,
- * just need a read lock. Higher-level considerations prevent
- * conflicting operations on a single page. The lock really protects
- * the underlying size and block map memory, so pager_extend needs a
- * write lock.
- *
- * An object can now span multiple paging partitions. The allocation
- * info we keep is a pair (offset,p_index) where the index is in the
- * array of all partition ptrs, and the offset is partition-relative.
- * Size wise we are doing ok fitting the pair into a single integer:
- * the offset really is in pages so we have vm_page_size bits available
- * for the partition index.
- */
-#define DEBUG_READER_CONFLICTS 0
-
-#if DEBUG_READER_CONFLICTS
-int default_pager_read_conflicts = 0;
-#endif
-
-union dp_map {
-
- struct {
- unsigned int p_offset : 24,
- p_index : 8;
- } block;
-
- union dp_map *indirect;
-};
-typedef union dp_map *dp_map_t;
-
-/* quick check for part==block==invalid */
-#define no_block(e) ((e).indirect == (dp_map_t)NO_BLOCK)
-#define invalidate_block(e) ((e).indirect = (dp_map_t)NO_BLOCK)
-
-struct dpager {
- pthread_mutex_t lock; /* lock for extending block map */
- /* XXX should be read-write lock */
-#if DEBUG_READER_CONFLICTS
- int readers;
- boolean_t writer;
-#endif
- dp_map_t map; /* block map */
- vm_size_t size; /* size of paging object, in pages */
- vm_size_t limit; /* limit (bytes) allowed to grow to */
- vm_size_t byte_limit; /* limit, which wasn't
- rounded to page boundary */
- p_index_t cur_partition;
-#ifdef CHECKSUM
- vm_offset_t *checksum; /* checksum - parallel to block map */
-#define NO_CHECKSUM ((vm_offset_t)-1)
-#endif /* CHECKSUM */
-};
-typedef struct dpager *dpager_t;
-
-/*
- * A paging object uses either a one- or a two-level map of offsets
- * into a paging partition.
- */
-#define PAGEMAP_ENTRIES 64
- /* number of pages in a second-level map */
-#define PAGEMAP_SIZE(npgs) ((npgs)*sizeof(vm_offset_t))
-
-#define INDIRECT_PAGEMAP_ENTRIES(npgs) \
- ((((npgs)-1)/PAGEMAP_ENTRIES) + 1)
-#define INDIRECT_PAGEMAP_SIZE(npgs) \
- (INDIRECT_PAGEMAP_ENTRIES(npgs) * sizeof(vm_offset_t *))
-#define INDIRECT_PAGEMAP(size) \
- (size > PAGEMAP_ENTRIES)
-
-#define ROUNDUP_TO_PAGEMAP(npgs) \
- (((npgs) + PAGEMAP_ENTRIES - 1) & ~(PAGEMAP_ENTRIES - 1))
-
-/*
* Object sizes are rounded up to the next power of 2,
* unless they are bigger than a given maximum size.
*/
@@ -1885,40 +1771,6 @@ default_has_page(ds, offset)
return ( ! no_block(pager_read_offset(ds, offset)) );
}
-/*
- * Mapping between pager port and paging object.
- */
-struct dstruct {
- queue_chain_t links; /* Link in pager-port list */
-
- pthread_mutex_t lock; /* Lock for the structure */
- pthread_cond_t
- waiting_seqno, /* someone waiting on seqno */
- waiting_read, /* someone waiting on readers */
- waiting_write, /* someone waiting on writers */
- waiting_refs; /* someone waiting on refs */
-
- memory_object_t pager; /* Pager port */
- mach_port_seqno_t seqno; /* Pager port sequence number */
- mach_port_t pager_request; /* Request port */
- mach_port_urefs_t request_refs; /* Request port user-refs */
- mach_port_t pager_name; /* Name port */
- mach_port_urefs_t name_refs; /* Name port user-refs */
- boolean_t external; /* Is an external object? */
-
- unsigned int readers; /* Reads in progress */
- unsigned int writers; /* Writes in progress */
-
- /* This is the reply port of an outstanding
- default_pager_object_set_size call. */
- mach_port_t lock_request;
-
- unsigned int errors; /* Pageout error count */
- struct dpager dpager; /* Actual pager */
-};
-typedef struct dstruct * default_pager_t;
-#define DEFAULT_PAGER_NULL ((default_pager_t)0)
-
#if PARALLEL
#define dstruct_lock_init(ds) pthread_mutex_init(&ds->lock, NULL)
#define dstruct_lock(ds) pthread_mutex_lock(&ds->lock)
@@ -1960,17 +1812,6 @@ void pager_port_list_insert(port, ds)
pthread_mutex_unlock(&all_pagers.lock);
}
-/* 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)
-
-/* The magic typecast */
-#define pager_port_lookup(_port_) \
- ((! MACH_PORT_VALID(_port_) || \
- ((default_pager_t)dnameof(_port_))->pager != (_port_)) ? \
- DEFAULT_PAGER_NULL : (default_pager_t)dnameof(_port_))
-
void pager_port_list_delete(ds)
default_pager_t ds;
{
@@ -2450,15 +2291,14 @@ memory_object_copy_strategy_t default_pager_copy_strategy =
MEMORY_OBJECT_COPY_DELAY;
kern_return_t
-seqnos_memory_object_init(pager, seqno, pager_request, pager_name,
+seqnos_memory_object_init(ds, seqno, pager_request, pager_name,
pager_page_size)
- mach_port_t pager;
+ default_pager_t ds;
mach_port_seqno_t seqno;
mach_port_t pager_request;
mach_port_t pager_name;
vm_size_t pager_page_size;
{
- default_pager_t ds;
kern_return_t kr;
static char here[] = "%sinit";
@@ -2466,7 +2306,6 @@ seqnos_memory_object_init(pager, seqno, pager_request, pager_name,
assert(MACH_PORT_VALID(pager_name));
assert(pager_page_size == vm_page_size);
- ds = pager_port_lookup(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here, my_name);
pager_port_lock(ds, seqno);
@@ -2512,7 +2351,7 @@ seqnos_memory_object_terminate(pager, seqno, pager_request, pager_name)
* not send rights.
*/
- ds = pager_port_lookup(pager);
+ ds = begin_using_default_pager(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here, my_name);
ddprintf ("seqnos_memory_object_terminate <%p>: pager_port_lock: <%p>[s:%d,r:%d,w:%d,l:%d], %d\n",
@@ -2578,7 +2417,7 @@ void default_pager_no_senders(pager, seqno, mscount)
*/
- ds = pager_port_lookup(pager);
+ ds = begin_using_default_pager(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here,my_name);
pager_port_lock(ds, seqno);
@@ -2639,16 +2478,15 @@ int default_pager_pageout_count = 0;
static __thread default_pager_thread_t *dpt;
kern_return_t
-seqnos_memory_object_data_request(pager, seqno, reply_to, offset,
+seqnos_memory_object_data_request(ds, seqno, reply_to, offset,
length, protection_required)
- memory_object_t pager;
+ default_pager_t ds;
mach_port_seqno_t seqno;
mach_port_t reply_to;
vm_offset_t offset;
vm_size_t length;
vm_prot_t protection_required;
{
- default_pager_t ds;
vm_offset_t addr;
unsigned int errors;
kern_return_t rc;
@@ -2657,7 +2495,6 @@ seqnos_memory_object_data_request(pager, seqno, reply_to, offset,
if (length != vm_page_size)
panic(here,my_name);
- ds = pager_port_lookup(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here,my_name);
ddprintf ("seqnos_memory_object_data_request <%p>: pager_port_lock: <%p>[s:%d,r:%d,w:%d,l:%d], %d\n",
@@ -2742,9 +2579,9 @@ ddprintf ("seqnos_memory_object_data_request <%p>: pager_port_unlock: <%p>[s:%d,
* also assumes that the default_pager is single-threaded.
*/
kern_return_t
-seqnos_memory_object_data_initialize(pager, seqno, pager_request,
+seqnos_memory_object_data_initialize(ds, seqno, pager_request,
offset, addr, data_cnt)
- memory_object_t pager;
+ default_pager_t ds;
mach_port_seqno_t seqno;
mach_port_t pager_request;
register
@@ -2754,14 +2591,12 @@ seqnos_memory_object_data_initialize(pager, seqno, pager_request,
vm_size_t data_cnt;
{
vm_offset_t amount_sent;
- default_pager_t ds;
static char here[] = "%sdata_initialize";
#ifdef lint
pager_request++;
#endif /* lint */
- ds = pager_port_lookup(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here,my_name);
ddprintf ("seqnos_memory_object_data_initialize <%p>: pager_port_lock: <%p>[s:%d,r:%d,w:%d,l:%d], %d\n",
@@ -2804,9 +2639,9 @@ ddprintf ("seqnos_memory_object_data_initialize <%p>: pager_port_unlock: <%p>[s:
* into individual pages and pass them off to default_write.
*/
kern_return_t
-seqnos_memory_object_data_write(pager, seqno, pager_request,
+seqnos_memory_object_data_write(ds, seqno, pager_request,
offset, addr, data_cnt)
- memory_object_t pager;
+ default_pager_t ds;
mach_port_seqno_t seqno;
mach_port_t pager_request;
register
@@ -2817,7 +2652,6 @@ seqnos_memory_object_data_write(pager, seqno, pager_request,
{
register
vm_size_t amount_sent;
- default_pager_t ds;
static char here[] = "%sdata_write";
int err;
@@ -2828,7 +2662,6 @@ seqnos_memory_object_data_write(pager, seqno, pager_request,
if ((data_cnt % vm_page_size) != 0)
panic(here,my_name);
- ds = pager_port_lookup(pager);
if (ds == DEFAULT_PAGER_NULL)
panic(here,my_name);
@@ -2888,7 +2721,7 @@ seqnos_memory_object_data_write(pager, seqno, pager_request,
kern_return_t
seqnos_memory_object_copy(old_memory_object, seqno, old_memory_control,
offset, length, new_memory_object)
- memory_object_t old_memory_object;
+ default_pager_t old_memory_object;
mach_port_seqno_t seqno;
memory_object_control_t
old_memory_control;
@@ -2916,7 +2749,7 @@ seqnos_memory_object_lock_completed (memory_object_t pager,
kern_return_t
seqnos_memory_object_data_unlock(pager, seqno, pager_request,
offset, length, protection_required)
- memory_object_t pager;
+ default_pager_t pager;
mach_port_seqno_t seqno;
mach_port_t pager_request;
vm_offset_t offset;
@@ -2931,7 +2764,7 @@ kern_return_t
seqnos_memory_object_supply_completed(pager, seqno, pager_request,
offset, length,
result, error_offset)
- memory_object_t pager;
+ mach_port_t pager;
mach_port_seqno_t seqno;
mach_port_t pager_request;
vm_offset_t offset;
@@ -2949,10 +2782,10 @@ seqnos_memory_object_supply_completed(pager, seqno, pager_request,
* into individual pages and pass them off to default_write.
*/
kern_return_t
-seqnos_memory_object_data_return(pager, seqno, pager_request,
+seqnos_memory_object_data_return(ds, seqno, pager_request,
offset, addr, data_cnt,
dirty, kernel_copy)
- memory_object_t pager;
+ default_pager_t ds;
mach_port_seqno_t seqno;
mach_port_t pager_request;
vm_offset_t offset;
@@ -2962,7 +2795,7 @@ seqnos_memory_object_data_return(pager, seqno, pager_request,
boolean_t kernel_copy;
{
- return seqnos_memory_object_data_write (pager, seqno, pager_request,
+ return seqnos_memory_object_data_write (ds, seqno, pager_request,
offset, addr, data_cnt);
}
@@ -3756,14 +3589,12 @@ S_default_pager_object_pages (mach_port_t pager,
kern_return_t
-S_default_pager_object_set_size (mach_port_t pager,
+S_default_pager_object_set_size (default_pager_t ds,
mach_port_seqno_t seqno,
vm_size_t limit)
{
kern_return_t kr = KERN_SUCCESS;
- default_pager_t ds;
- ds = pager_port_lookup(pager);
if (ds == DEFAULT_PAGER_NULL)
return KERN_INVALID_ARGUMENT;
diff --git a/mach-defpager/mig-decls.h b/mach-defpager/mig-decls.h
new file mode 100644
index 0000000..f63fef2
--- /dev/null
+++ b/mach-defpager/mig-decls.h
@@ -0,0 +1,37 @@
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Justus Winter.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __MACH_DEFPAGER_MIG_DECLS_H__
+#define __MACH_DEFPAGER_MIG_DECLS_H__
+
+#include "priv.h"
+
+/* Called by server stub functions. */
+
+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);
+}
+
+#endif /* __MACH_DEFPAGER_MIG_DECLS_H__ */
diff --git a/mach-defpager/mig-mutate.h b/mach-defpager/mig-mutate.h
new file mode 100644
index 0000000..54aeeba
--- /dev/null
+++ b/mach-defpager/mig-mutate.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Justus Winter.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
+
+#define MEMORY_OBJECT_INTRAN default_pager_t begin_using_default_pager (mach_port_t)
+#define MEMORY_OBJECT_IMPORTS import "mig-decls.h";
+#define DEFAULT_PAGER_IMPORTS import "mig-decls.h";
diff --git a/mach-defpager/priv.h b/mach-defpager/priv.h
new file mode 100644
index 0000000..20711b2
--- /dev/null
+++ b/mach-defpager/priv.h
@@ -0,0 +1,188 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1993-1989 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+
+#ifndef __MACH_DEFPAGER_PRIV_H__
+#define __MACH_DEFPAGER_PRIV_H__
+
+#include <mach.h>
+#include <queue.h>
+
+/*
+ * Bitmap allocation.
+ */
+typedef unsigned int bm_entry_t;
+#define NB_BM 32
+#define BM_MASK 0xffffffff
+
+#define howmany(a,b) (((a) + (b) - 1)/(b))
+
+/*
+ * Value to indicate no block assigned
+ */
+#define NO_BLOCK ((vm_offset_t)-1)
+
+/*
+ * 'Partition' structure for each paging area.
+ * Controls allocation of blocks within paging area.
+ */
+struct part {
+ pthread_mutex_t p_lock; /* for bitmap/free */
+ vm_size_t total_size; /* total number of blocks */
+ vm_size_t free; /* number of blocks free */
+ unsigned int id; /* named lookup */
+ bm_entry_t *bitmap; /* allocation map */
+ boolean_t going_away; /* destroy attempt in progress */
+ struct file_direct *file; /* file paged to */
+};
+typedef struct part *partition_t;
+
+struct {
+ pthread_mutex_t lock;
+ int n_partitions;
+ partition_t *partition_list;/* array, for quick mapping */
+} all_partitions; /* list of all such */
+
+typedef unsigned char p_index_t;
+
+#define P_INDEX_INVALID ((p_index_t)-1)
+
+#define no_partition(x) ((x) == P_INDEX_INVALID)
+
+/*
+ * Allocation info for each paging object.
+ *
+ * Most operations, even pager_write_offset and pager_put_checksum,
+ * just need a read lock. Higher-level considerations prevent
+ * conflicting operations on a single page. The lock really protects
+ * the underlying size and block map memory, so pager_extend needs a
+ * write lock.
+ *
+ * An object can now span multiple paging partitions. The allocation
+ * info we keep is a pair (offset,p_index) where the index is in the
+ * array of all partition ptrs, and the offset is partition-relative.
+ * Size wise we are doing ok fitting the pair into a single integer:
+ * the offset really is in pages so we have vm_page_size bits available
+ * for the partition index.
+ */
+#define DEBUG_READER_CONFLICTS 0
+
+#if DEBUG_READER_CONFLICTS
+int default_pager_read_conflicts = 0;
+#endif
+
+union dp_map {
+
+ struct {
+ unsigned int p_offset : 24,
+ p_index : 8;
+ } block;
+
+ union dp_map *indirect;
+};
+typedef union dp_map *dp_map_t;
+
+/* quick check for part==block==invalid */
+#define no_block(e) ((e).indirect == (dp_map_t)NO_BLOCK)
+#define invalidate_block(e) ((e).indirect = (dp_map_t)NO_BLOCK)
+
+struct dpager {
+ pthread_mutex_t lock; /* lock for extending block map */
+ /* XXX should be read-write lock */
+#if DEBUG_READER_CONFLICTS
+ int readers;
+ boolean_t writer;
+#endif
+ dp_map_t map; /* block map */
+ vm_size_t size; /* size of paging object, in pages */
+ vm_size_t limit; /* limit (bytes) allowed to grow to */
+ vm_size_t byte_limit; /* limit, which wasn't
+ rounded to page boundary */
+ p_index_t cur_partition;
+#ifdef CHECKSUM
+ vm_offset_t *checksum; /* checksum - parallel to block map */
+#define NO_CHECKSUM ((vm_offset_t)-1)
+#endif /* CHECKSUM */
+};
+typedef struct dpager *dpager_t;
+
+/*
+ * A paging object uses either a one- or a two-level map of offsets
+ * into a paging partition.
+ */
+#define PAGEMAP_ENTRIES 64
+ /* number of pages in a second-level map */
+#define PAGEMAP_SIZE(npgs) ((npgs)*sizeof(vm_offset_t))
+
+#define INDIRECT_PAGEMAP_ENTRIES(npgs) \
+ ((((npgs)-1)/PAGEMAP_ENTRIES) + 1)
+#define INDIRECT_PAGEMAP_SIZE(npgs) \
+ (INDIRECT_PAGEMAP_ENTRIES(npgs) * sizeof(vm_offset_t *))
+#define INDIRECT_PAGEMAP(size) \
+ (size > PAGEMAP_ENTRIES)
+
+#define ROUNDUP_TO_PAGEMAP(npgs) \
+ (((npgs) + PAGEMAP_ENTRIES - 1) & ~(PAGEMAP_ENTRIES - 1))
+
+/*
+ * Mapping between pager port and paging object.
+ */
+struct dstruct {
+ queue_chain_t links; /* Link in pager-port list */
+
+ pthread_mutex_t lock; /* Lock for the structure */
+ pthread_cond_t
+ waiting_seqno, /* someone waiting on seqno */
+ waiting_read, /* someone waiting on readers */
+ waiting_write, /* someone waiting on writers */
+ waiting_refs; /* someone waiting on refs */
+
+ memory_object_t pager; /* Pager port */
+ mach_port_seqno_t seqno; /* Pager port sequence number */
+ mach_port_t pager_request; /* Request port */
+ mach_port_urefs_t request_refs; /* Request port user-refs */
+ mach_port_t pager_name; /* Name port */
+ mach_port_urefs_t name_refs; /* Name port user-refs */
+ boolean_t external; /* Is an external object? */
+
+ unsigned int readers; /* Reads in progress */
+ unsigned int writers; /* Writes in progress */
+
+ /* This is the reply port of an outstanding
+ default_pager_object_set_size call. */
+ mach_port_t lock_request;
+
+ unsigned int errors; /* Pageout error count */
+ struct dpager dpager; /* Actual pager */
+};
+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)
+
+#endif /* __MACH_DEFPAGER_PRIV_H__ */
|