5 #define PGMASK (PGSIZE - 1)
7 #define MSETLEN (1 << 15)
14 static struct mset
*pool
;
16 static int mk_pool(void)
18 if (pool
&& !pool
->refs
) {
19 pool
->size
= sizeof(*pool
);
22 pool
= mmap(NULL
, MSETLEN
, PROT_READ
| PROT_WRITE
,
23 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
24 if (pool
== MAP_FAILED
) {
28 pool
->size
= sizeof(*pool
);
37 m
= mmap(NULL
, n
+ PGSIZE
, PROT_READ
| PROT_WRITE
,
38 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
41 *(long *) m
= n
+ PGSIZE
; /* store length in the first page */
44 if (!pool
|| MSETLEN
- pool
->size
< n
+ sizeof(void *))
47 m
= (void *) pool
+ pool
->size
;
48 *(void **) m
= pool
; /* the address of the owning mset */
50 pool
->size
+= (n
+ sizeof(void *) + 7) & ~7;
51 if (!((pool
+ pool
->size
+ sizeof(void *)) & PGMASK
))
52 pool
->size
+= sizeof(long);
53 return m
+ sizeof(void *);
61 struct mset
*mset
= *(void **) (v
- sizeof(void *));
63 if (!mset
->refs
&& mset
!= pool
)
64 munmap(mset
, mset
->size
);
66 munmap(v
- PGSIZE
, *(long *) (v
- PGSIZE
));