vm: region: refactor to use offsets rather than absolute addresses
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
#include <mango/pmap.h>
|
||||
#include <mango/vm.h>
|
||||
|
||||
#define VM_REGION_NAME_MAX 64
|
||||
#define VM_REGION_NAME_MAX 64
|
||||
|
||||
#define VM_REGION_ANY_MAP_ADDRESS ((virt_addr_t) - 1)
|
||||
#define VM_REGION_ANY_OFFSET ((off_t) - 1)
|
||||
|
||||
struct vm_region;
|
||||
struct vm_object;
|
||||
@@ -22,8 +22,8 @@ struct vm_region_entry {
|
||||
struct btree_node e_node;
|
||||
struct vm_region_entry *e_parent;
|
||||
enum vm_region_entry_type e_type;
|
||||
/* absolute virtual address of the entry */
|
||||
virt_addr_t e_base_address;
|
||||
/* offset in bytes of this entry within its immediate parent. */
|
||||
off_t e_offset;
|
||||
/* size of the entry in bytes */
|
||||
size_t e_size;
|
||||
};
|
||||
@@ -66,59 +66,48 @@ struct vm_region {
|
||||
|
||||
extern kern_status_t vm_region_type_init(void);
|
||||
|
||||
/* create a new vm-region, optionally within a parent region.
|
||||
* `offset` is the byte offset within the parent region where the new region
|
||||
* should start.
|
||||
* if no parent is specified, `offset` is the absolute virtual address of the
|
||||
* start of the region.
|
||||
* in both cases, `len` is the length of the new region in bytes. */
|
||||
extern kern_status_t vm_region_create(
|
||||
struct vm_region *parent,
|
||||
const char *name,
|
||||
virt_addr_t base,
|
||||
off_t offset,
|
||||
size_t len,
|
||||
enum vm_prot prot,
|
||||
struct vm_region **out);
|
||||
|
||||
/* find the child region that has jurisdiction over the specified virtual
|
||||
* address. returns the lowest-nested region that covers the specified virtual
|
||||
* address. */
|
||||
extern struct vm_region *vm_region_find_child(
|
||||
struct vm_region *region,
|
||||
virt_addr_t addr);
|
||||
|
||||
/* find the child region that has jurisdiction over the specified virtual
|
||||
* address area. returns the lowest-nested region that covers the specified
|
||||
* virtual address area. the area must be fully contained within a region, with
|
||||
* no partial overlaps. if an area is covered by multiple regions, or is only
|
||||
* partially within a region, returns NULL. */
|
||||
extern struct vm_region *vm_region_find_child_for_area(
|
||||
struct vm_region *region,
|
||||
virt_addr_t addr,
|
||||
size_t len);
|
||||
extern struct vm_region_mapping *vm_region_find_mapping(
|
||||
struct vm_region *region,
|
||||
virt_addr_t addr);
|
||||
|
||||
/* map a vm-object into a vm-region.
|
||||
* [region_offset,length] must fall within exactly one region, and cannot span
|
||||
* multiple sibling regions.
|
||||
* if [region_offset,length] falls within a child region, the map operation
|
||||
* will be transparently redirected to the relevant region.
|
||||
* `prot` must be allowed both by the region into which the mapping is being
|
||||
* created AND the vm-object being mapped. */
|
||||
extern kern_status_t vm_region_map_object(
|
||||
struct vm_region *region,
|
||||
virt_addr_t map_address,
|
||||
off_t region_offset,
|
||||
struct vm_object *object,
|
||||
off_t object_offset,
|
||||
size_t length,
|
||||
enum vm_prot prot,
|
||||
virt_addr_t *out);
|
||||
|
||||
/* returns true if the memory area defined by [base, base+len] contains:
|
||||
* - no child regions
|
||||
* - no vm_object mappings
|
||||
* if any child regions or mappings exist in the memory area, returns false.
|
||||
* if the memory area exceeds the bounds of the region, returns false.
|
||||
*/
|
||||
extern bool vm_region_is_area_free(
|
||||
const struct vm_region *region,
|
||||
virt_addr_t base,
|
||||
size_t len);
|
||||
|
||||
/* find the mapping corresponding to the given virtual address, and page-in the
|
||||
* necessary vm_page to allow the memory access to succeed. if the relevant
|
||||
* vm-object page hasn't been allocated yet, it will be allocated here. */
|
||||
extern kern_status_t vm_region_demand_map(
|
||||
struct vm_region *region,
|
||||
virt_addr_t addr,
|
||||
enum pmap_fault_flags flags);
|
||||
|
||||
/* get the absolute base virtual address of a region within its
|
||||
* parent/ancestors. */
|
||||
extern virt_addr_t vm_region_get_base_address(const struct vm_region *region);
|
||||
|
||||
extern void vm_region_dump(struct vm_region *region, int depth);
|
||||
|
||||
DEFINE_OBJECT_LOCK_FUNCTION(vm_region, vr_base)
|
||||
|
||||
Reference in New Issue
Block a user