1 /* Copyright (c) 2009, 2010 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * Memory management for processes: syscall related functions, virtual memory
11 #include <ros/common.h>
14 #include <sys/queue.h>
18 struct proc; /* preprocessor games */
20 /* Basic structure defining a region of a process's virtual memory. Note we
21 * don't refcnt these. Either they are in the TAILQ/tree, or they should be
22 * freed. There should be no other references floating around. We still need
23 * to sort out how we share memory and how we'll do private memory with these
26 TAILQ_ENTRY(vm_region) vm_link;
27 TAILQ_ENTRY(vm_region) vm_pm_link;
28 struct proc *vm_proc; /* owning process, for now */
36 TAILQ_HEAD(vmr_tailq, vm_region); /* Declares 'struct vmr_tailq' */
38 /* VM Region Management Functions. For now, these just maintain themselves -
39 * anything related to mapping needs to be done by the caller. */
41 struct vm_region *create_vmr(struct proc *p, uintptr_t va, size_t len);
42 struct vm_region *split_vmr(struct vm_region *vmr, uintptr_t va);
43 int merge_vmr(struct vm_region *first, struct vm_region *second);
44 struct vm_region *merge_me(struct vm_region *vmr);
45 int grow_vmr(struct vm_region *vmr, uintptr_t va);
46 int shrink_vmr(struct vm_region *vmr, uintptr_t va);
47 void destroy_vmr(struct vm_region *vmr);
48 struct vm_region *find_vmr(struct proc *p, uintptr_t va);
49 struct vm_region *find_first_vmr(struct proc *p, uintptr_t va);
50 void isolate_vmrs(struct proc *p, uintptr_t va, size_t len);
51 void unmap_and_destroy_vmrs(struct proc *p);
52 int duplicate_vmrs(struct proc *p, struct proc *new_p);
53 void print_vmrs(struct proc *p);
55 /* mmap() related functions. These manipulate VMRs and change the hardware page
56 * tables. Any requests below the LOWEST_VA will silently be upped. This may
57 * be a dynamic proc-specific variable later. */
58 #define MMAP_LOWEST_VA MiB
59 void *mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
60 int fd, size_t offset);
61 void *do_mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
62 struct file *f, size_t offset);
63 int mprotect(struct proc *p, uintptr_t addr, size_t len, int prot);
64 int munmap(struct proc *p, uintptr_t addr, size_t len);
65 int handle_page_fault(struct proc *p, uintptr_t va, int prot);
66 unsigned long populate_va(struct proc *p, uintptr_t va, unsigned long nr_pgs);
68 /* These assume the mm_lock is held already */
69 int __do_mprotect(struct proc *p, uintptr_t addr, size_t len, int prot);
70 int __do_munmap(struct proc *p, uintptr_t addr, size_t len);
72 /* Kernel Dynamic Memory Mappings */
73 /* These two are just about reserving VA space */
74 uintptr_t get_vmap_segment(unsigned long num_pages);
75 uintptr_t put_vmap_segment(uintptr_t vaddr, unsigned long num_pages);
76 /* These two are about actually mapping stuff in some reserved space */
77 int map_vmap_segment(uintptr_t vaddr, uintptr_t paddr, unsigned long num_pages,
79 int unmap_vmap_segment(uintptr_t vaddr, unsigned long num_pages);
80 /* Helper wrappers, since no one will probably call the *_segment funcs */
81 uintptr_t vmap_pmem(uintptr_t paddr, size_t nr_bytes);
82 uintptr_t vmap_pmem_nocache(uintptr_t paddr, size_t nr_bytes);
83 int vunmap_vmem(uintptr_t vaddr, size_t nr_bytes);
85 #endif /* !ROS_KERN_MM_H */