2 /* This file implements the methods of physically contiguous anonymous memory. */
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
)
40 phys_bytes new_pages
, new_page_cl
, cur_ph
;
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
;
53 pr
= pb_reference(pb
, p
* VM_PAGE_SIZE
, region
);
61 assert(physregions(region
) == pages
);
63 if((new_page_cl
= alloc_mem(pages
, allocflags
)) == NO_MEM
) {
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
);
74 assert(pr
->ph
->phys
== MAP_NONE
);
75 assert(pr
->offset
== p
* VM_PAGE_SIZE
);
76 pr
->ph
->phys
= cur_ph
+ pr
->offset
;
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");
88 static int anon_contig_reference(struct phys_region
*pr
)
90 printf("VM: cannot fork with physically contig memory.\n");
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
);