1 /* Function prototypes. */ 2 3 struct vmproc; 4 struct stat; 5 struct memory; 6 struct vir_region; 7 struct phys_region; 8 9 #include <minix/ipc.h> 10 #include <minix/endpoint.h> 11 #include <minix/safecopies.h> 12 #include <minix/vm.h> 13 #include <minix/timers.h> 14 #include <stdio.h> 15 16 #include "pt.h" 17 #include "vm.h" 18 19 /* acl.c */ 20 void acl_init(void); 21 int acl_check(struct vmproc *vmp, int call); 22 void acl_set(struct vmproc *vmp, bitchunk_t *mask, int sys_proc); 23 void acl_fork(struct vmproc *vmp); 24 void acl_clear(struct vmproc *vmp); 25 26 /* alloc.c */ 27 void *reservedqueue_new(int, int, int, int); 28 int reservedqueue_alloc(void *, phys_bytes *, void **); 29 void reservedqueue_add(void *, void *, phys_bytes); 30 void alloc_cycle(void); 31 void mem_sanitycheck(const char *file, int line); 32 phys_clicks alloc_mem(phys_clicks clicks, u32_t flags); 33 void memstats(int *nodes, int *pages, int *largest); 34 void printmemstats(void); 35 void usedpages_reset(void); 36 int usedpages_add_f(phys_bytes phys, phys_bytes len, const char *file, int 37 line); 38 void free_mem(phys_clicks base, phys_clicks clicks); 39 void mem_add_total_pages(int pages); 40 #define usedpages_add(a, l) usedpages_add_f(a, l, __FILE__, __LINE__) 41 42 void mem_init(struct memory *chunks); 43 44 /* utility.c */ 45 void get_mem_chunks(struct memory *mem_chunks); 46 int vm_isokendpt(endpoint_t ep, int *proc); 47 int get_stack_ptr(int proc_nr, vir_bytes *sp); 48 int do_info(message *); 49 int swap_proc_slot(struct vmproc *src_vmp, struct vmproc *dst_vmp); 50 int swap_proc_dyn_data(struct vmproc *src_vmp, struct vmproc *dst_vmp, 51 int sys_upd_flags); 52 void adjust_proc_refs(void); 53 int do_getrusage(message *m); 54 55 /* exit.c */ 56 void clear_proc(struct vmproc *vmp); 57 int do_exit(message *msg); 58 int do_willexit(message *msg); 59 int do_procctl(message *msg, int transid); 60 void free_proc(struct vmproc *vmp); 61 62 /* fork.c */ 63 int do_fork(message *msg); 64 65 /* break.c */ 66 int do_brk(message *msg); 67 int real_brk(struct vmproc *vmp, vir_bytes v); 68 69 /* map_mem.c */ 70 int map_memory(endpoint_t sour, endpoint_t dest, vir_bytes virt_s, 71 vir_bytes virt_d, vir_bytes length, int flag); 72 int unmap_memory(endpoint_t sour, endpoint_t dest, vir_bytes virt_s, 73 vir_bytes virt_d, vir_bytes length, int flag); 74 75 /* mmap.c */ 76 int do_mmap(message *msg); 77 int do_munmap(message *msg); 78 int do_map_phys(message *msg); 79 int do_unmap_phys(message *msg); 80 int do_remap(message *m); 81 int do_get_phys(message *m); 82 int do_get_refcount(message *m); 83 int do_vfs_mmap(message *m); 84 85 /* pagefaults.c */ 86 void do_pagefaults(message *m); 87 void do_memory(void); 88 char *pf_errstr(u32_t err); 89 int handle_memory_start(struct vmproc *vmp, vir_bytes mem, vir_bytes len, 90 int wrflag, endpoint_t caller, endpoint_t requestor, int transid, 91 int vfs_avail); 92 int handle_memory_once(struct vmproc *vmp, vir_bytes mem, vir_bytes len, 93 int wrflag); 94 95 /* $(ARCH)/pagetable.c */ 96 void pt_init(void); 97 void vm_freepages(vir_bytes vir, int pages); 98 void pt_init_mem(void); 99 void pt_check(struct vmproc *vmp); 100 int pt_new(pt_t *pt); 101 void pt_free(pt_t *pt); 102 int pt_map_in_range(struct vmproc *src_vmp, struct vmproc *dst_vmp, 103 vir_bytes start, vir_bytes end); 104 int pt_ptmap(struct vmproc *src_vmp, struct vmproc *dst_vmp); 105 int pt_ptalloc_in_range(pt_t *pt, vir_bytes start, vir_bytes end, u32_t 106 flags, int verify); 107 void pt_clearmapcache(void); 108 int pt_writemap(struct vmproc * vmp, pt_t *pt, vir_bytes v, phys_bytes 109 physaddr, size_t bytes, u32_t flags, u32_t writemapflags); 110 int pt_checkrange(pt_t *pt, vir_bytes v, size_t bytes, int write); 111 int pt_bind(pt_t *pt, struct vmproc *who); 112 void *vm_mappages(phys_bytes p, int pages); 113 void *vm_allocpage(phys_bytes *p, int cat); 114 void *vm_allocpages(phys_bytes *p, int cat, int pages); 115 void *vm_allocpagedir(phys_bytes *p); 116 int pt_mapkernel(pt_t *pt); 117 void vm_pagelock(void *vir, int lockflag); 118 int vm_addrok(void *vir, int write); 119 int get_vm_self_pages(void); 120 int pt_writable(struct vmproc *vmp, vir_bytes v); 121 void pt_assert(pt_t *pt); 122 123 #if SANITYCHECKS 124 void pt_sanitycheck(pt_t *pt, const char *file, int line); 125 #endif 126 127 /* slaballoc.c */ 128 void *slaballoc(int bytes); 129 void slabfree(void *mem, int bytes); 130 void slabstats(void); 131 void slab_sanitycheck(const char *file, int line); 132 #define SLABALLOC(var) (var = slaballoc(sizeof(*var))) 133 #define SLABFREE(ptr) do { slabfree(ptr, sizeof(*(ptr))); (ptr) = NULL; } while(0) 134 #if SANITYCHECKS 135 136 void slabunlock(void *mem, int bytes); 137 void slablock(void *mem, int bytes); 138 int slabsane_f(const char *file, int line, void *mem, int bytes); 139 #endif 140 141 /* region.c */ 142 void map_region_init(void); 143 struct vir_region * map_page_region(struct vmproc *vmp, vir_bytes min, 144 vir_bytes max, vir_bytes length, u32_t flags, int mapflags, 145 mem_type_t *memtype); 146 struct vir_region * map_proc_kernel(struct vmproc *dst); 147 int map_region_extend(struct vmproc *vmp, struct vir_region *vr, 148 vir_bytes delta); 149 int map_region_extend_upto_v(struct vmproc *vmp, vir_bytes vir); 150 int map_unmap_region(struct vmproc *vmp, struct vir_region *vr, 151 vir_bytes offset, vir_bytes len); 152 int map_unmap_range(struct vmproc *vmp, vir_bytes, vir_bytes); 153 int map_free_proc(struct vmproc *vmp); 154 int map_proc_copy(struct vmproc *dst, struct vmproc *src); 155 int map_proc_copy_range(struct vmproc *dst, struct vmproc *src, struct 156 vir_region *start_src_vr, struct vir_region *end_src_vr); 157 struct vir_region *map_lookup(struct vmproc *vmp, vir_bytes addr, 158 struct phys_region **pr); 159 int map_pf(struct vmproc *vmp, struct vir_region *region, vir_bytes 160 offset, int write, vfs_callback_t pf_callback, void *state, int len, 161 int *io); 162 int map_pin_memory(struct vmproc *vmp); 163 int map_handle_memory(struct vmproc *vmp, struct vir_region *region, 164 vir_bytes offset, vir_bytes len, int write, vfs_callback_t cb, 165 void *state, int statelen); 166 void map_printmap(struct vmproc *vmp); 167 int map_writept(struct vmproc *vmp); 168 void printregionstats(struct vmproc *vmp); 169 void map_setparent(struct vmproc *vmp); 170 u32_t vrallocflags(u32_t flags); 171 int map_free(struct vir_region *region); 172 struct phys_region *physblock_get(struct vir_region *region, vir_bytes offset); 173 void physblock_set(struct vir_region *region, vir_bytes offset, 174 struct phys_region *newphysr); 175 int map_ph_writept(struct vmproc *vmp, struct vir_region *vr, 176 struct phys_region *pr); 177 178 struct vir_region* map_region_lookup_type(struct vmproc *vmp, u32_t flags); 179 int map_get_phys(struct vmproc *vmp, vir_bytes addr, phys_bytes *r); 180 int map_get_ref(struct vmproc *vmp, vir_bytes addr, u8_t *cnt); 181 unsigned int physregions(struct vir_region *vr); 182 183 void get_usage_info(struct vmproc *vmp, struct vm_usage_info *vui); 184 void get_usage_info_kernel(struct vm_usage_info *vui); 185 int get_region_info(struct vmproc *vmp, struct vm_region_info *vri, int 186 count, vir_bytes *nextp); 187 int copy_abs2region(phys_bytes abs, struct vir_region *destregion, 188 phys_bytes offset, phys_bytes len); 189 #if SANITYCHECKS 190 void map_sanitycheck(const char *file, int line); 191 #endif 192 193 /* rs.c */ 194 int do_rs_set_priv(message *m); 195 int do_rs_update(message *m); 196 int do_rs_memctl(message *m); 197 198 /* queryexit.c */ 199 int do_query_exit(message *m); 200 int do_watch_exit(message *m); 201 int do_notify_sig(message *m); 202 void init_query_exit(void); 203 204 /* pb.c */ 205 struct phys_block *pb_new(phys_bytes phys); 206 void pb_free(struct phys_block *); 207 struct phys_region *pb_reference(struct phys_block *newpb, 208 vir_bytes offset, struct vir_region *region, mem_type_t *); 209 void pb_unreferenced(struct vir_region *region, struct phys_region *pr, int rm); 210 void pb_link(struct phys_region *newphysr, struct phys_block *newpb, 211 vir_bytes offset, struct vir_region *parent); 212 int mem_cow(struct vir_region *region, 213 struct phys_region *ph, phys_bytes new_page_cl, phys_bytes new_page); 214 215 /* mem_directphys.c */ 216 void phys_setphys(struct vir_region *vr, phys_bytes startaddr); 217 218 /* mem_shared.c */ 219 void shared_setsource(struct vir_region *vr, endpoint_t ep, struct vir_region *src); 220 221 /* mem_cache.c */ 222 int do_mapcache(message *m); 223 int do_setcache(message *m); 224 int do_forgetcache(message *m); 225 int do_clearcache(message *m); 226 227 /* cache.c */ 228 struct cached_page *find_cached_page_bydev(dev_t dev, u64_t dev_off, 229 ino_t ino, u64_t ino_off, int touchlru); 230 struct cached_page *find_cached_page_byino(dev_t dev, ino_t ino, u64_t ino_off, int touchlru); 231 int addcache(dev_t dev, u64_t def_off, ino_t ino, u64_t ino_off, int flags, 232 struct phys_block *pb); 233 void cache_sanitycheck_internal(void); 234 int cache_freepages(int pages); 235 void get_stats_info(struct vm_stats_info *vsi); 236 void cache_lru_touch(struct cached_page *hb); 237 void rmcache(struct cached_page *cp); 238 void clear_cache_bydev(dev_t dev); 239 240 /* vfs.c */ 241 int vfs_request(int reqno, int fd, struct vmproc *vmp, u64_t offset, 242 u32_t len, vfs_callback_t reply_callback, void *cbarg, void *state, 243 int statelen); 244 int do_vfs_reply(message *m); 245 246 /* mem_file.c */ 247 int mappedfile_setfile(struct vmproc *owner, struct vir_region *region, 248 int fd, u64_t offset, 249 dev_t dev, ino_t ino, u16_t clearend, int prefill, int mayclose); 250 251 /* fdref.c */ 252 struct fdref *fdref_new(struct vmproc *owner, ino_t ino, dev_t dev, int fd); 253 struct fdref *fdref_dedup_or_new(struct vmproc *owner, ino_t ino, dev_t dev, 254 int fd, int mayclose); 255 void fdref_ref(struct fdref *ref, struct vir_region *region); 256 void fdref_deref(struct vir_region *region); 257 void fdref_sanitycheck(void); 258