vm: reduce noise in merged pagetable.c
[minix.git] / servers / vm / mem_anon_contig.c
blobec61ceadcabfb099aa645f52e3291759b72a0464
2 /* This file implements the methods of physically contiguous anonymous memory. */
4 #include <assert.h>
6 #include "proto.h"
7 #include "vm.h"
8 #include "region.h"
9 #include "glo.h"
11 static int anon_contig_reference(struct phys_region *pr);
12 static int anon_contig_unreference(struct phys_region *pr);
13 static int anon_contig_pagefault(struct vmproc *vmp, struct vir_region *region,
14 struct phys_region *ph, int write);
15 static int anon_contig_sanitycheck(struct phys_region *pr, char *file, int line);
16 static int anon_contig_writable(struct phys_region *pr);
17 static int anon_contig_resize(struct vmproc *vmp, struct vir_region *vr, vir_bytes l);
18 static int anon_contig_new(struct vir_region *vr);
20 struct mem_type mem_type_anon_contig = {
21 .name = "anonymous memory (physically contiguous)",
22 .ev_new = anon_contig_new,
23 .ev_reference = anon_contig_reference,
24 .ev_unreference = anon_contig_unreference,
25 .ev_pagefault = anon_contig_pagefault,
26 .ev_resize = anon_contig_resize,
27 .ev_sanitycheck = anon_contig_sanitycheck,
28 .writable = anon_contig_writable
31 static int anon_contig_pagefault(struct vmproc *vmp, struct vir_region *region,
32 struct phys_region *ph, int write)
34 panic("anon_contig_pagefault: pagefault cannot happen");
37 static int anon_contig_new(struct vir_region *region)
39 u32_t allocflags;
40 phys_bytes new_pages, new_page_cl, cur_ph;
41 int p, pages;
42 physr_iter iter;
44 allocflags = vrallocflags(region->flags);
46 pages = region->length/VM_PAGE_SIZE;
48 assert(physregions(region) == 0);
50 for(p = 0; p < pages; p++) {
51 struct phys_block *pb = pb_new(MAP_NONE);
52 struct phys_region *pr = NULL;
53 if(pb)
54 pr = pb_reference(pb, p * VM_PAGE_SIZE, region);
55 if(!pr) {
56 if(pb) pb_free(pb);
57 map_free(region);
58 return ENOMEM;
62 assert(physregions(region) == pages);
64 if((new_page_cl = alloc_mem(pages, allocflags)) == NO_MEM) {
65 map_free(region);
66 return ENOMEM;
69 cur_ph = new_pages = CLICK2ABS(new_page_cl);
71 physr_start_iter_least(region->phys, &iter);
73 for(p = 0; p < pages; p++) {
74 struct phys_region *pr = physr_get_iter(&iter);
75 assert(pr);
76 assert(pr->ph);
77 assert(pr->ph->phys == MAP_NONE);
78 assert(pr->offset == p * VM_PAGE_SIZE);
79 pr->ph->phys = cur_ph + pr->offset;
80 physr_incr_iter(&iter);
83 assert(!physr_get_iter(&iter));
85 return OK;
88 static int anon_contig_resize(struct vmproc *vmp, struct vir_region *vr, vir_bytes l)
90 printf("VM: cannot resize physically contiguous memory.\n");
91 return ENOMEM;
94 static int anon_contig_reference(struct phys_region *pr)
96 printf("VM: cannot fork with physically contig memory.\n");
97 return ENOMEM;
100 /* Methods inherited from the anonymous memory methods. */
102 static int anon_contig_unreference(struct phys_region *pr)
104 return mem_type_anon.ev_unreference(pr);
107 static int anon_contig_sanitycheck(struct phys_region *pr, char *file, int line)
109 return mem_type_anon.ev_sanitycheck(pr, file, line);
112 static int anon_contig_writable(struct phys_region *pr)
114 return mem_type_anon.writable(pr);