kernel: restore setting KTS_NONE
[minix.git] / servers / vm / mem_anon_contig.c
blobf11adc6767e5b508582765d8e5646cfaa30ab79e
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;
43 allocflags = vrallocflags(region->flags);
45 pages = region->length/VM_PAGE_SIZE;
47 assert(physregions(region) == 0);
49 for(p = 0; p < pages; p++) {
50 struct phys_block *pb = pb_new(MAP_NONE);
51 struct phys_region *pr = NULL;
52 if(pb)
53 pr = pb_reference(pb, p * VM_PAGE_SIZE, region);
54 if(!pr) {
55 if(pb) pb_free(pb);
56 map_free(region);
57 return ENOMEM;
61 assert(physregions(region) == pages);
63 if((new_page_cl = alloc_mem(pages, allocflags)) == NO_MEM) {
64 map_free(region);
65 return ENOMEM;
68 cur_ph = new_pages = CLICK2ABS(new_page_cl);
70 for(p = 0; p < pages; p++) {
71 struct phys_region *pr = physblock_get(region, p * VM_PAGE_SIZE);
72 assert(pr);
73 assert(pr->ph);
74 assert(pr->ph->phys == MAP_NONE);
75 assert(pr->offset == p * VM_PAGE_SIZE);
76 pr->ph->phys = cur_ph + pr->offset;
79 return OK;
82 static int anon_contig_resize(struct vmproc *vmp, struct vir_region *vr, vir_bytes l)
84 printf("VM: cannot resize physically contiguous memory.\n");
85 return ENOMEM;
88 static int anon_contig_reference(struct phys_region *pr)
90 printf("VM: cannot fork with physically contig memory.\n");
91 return ENOMEM;
94 /* Methods inherited from the anonymous memory methods. */
96 static int anon_contig_unreference(struct phys_region *pr)
98 return mem_type_anon.ev_unreference(pr);
101 static int anon_contig_sanitycheck(struct phys_region *pr, char *file, int line)
103 return mem_type_anon.ev_sanitycheck(pr, file, line);
106 static int anon_contig_writable(struct phys_region *pr)
108 return mem_type_anon.writable(pr);