b8ccffd2d4
vm-object can be used to demand-allocate non-contiguous physical memory, and will provide an api for userspace programs to do the same. unless a vm-object is created in-place (i.e. to represent a specific area of physical memory), its memory pages are only allocated when the object is mapped AND someone attempts to access the memory.
69 lines
1.9 KiB
C
69 lines
1.9 KiB
C
#ifndef MANGO_VM_OBJECT_H_
|
|
#define MANGO_VM_OBJECT_H_
|
|
|
|
#include <mango/locks.h>
|
|
#include <mango/object.h>
|
|
|
|
#define VM_OBJECT_NAME_MAX 64
|
|
|
|
enum vm_object_flags {
|
|
/* the memory behind this vm-object wasn't allocated by us, and
|
|
* therefore shouldn't be freed by us */
|
|
VMO_IN_PLACE = 0x01u,
|
|
};
|
|
|
|
struct vm_object {
|
|
struct object vo_base;
|
|
|
|
char vo_name[VM_OBJECT_NAME_MAX];
|
|
enum vm_object_flags vo_flags;
|
|
|
|
/* queue of struct vm_region_mapping */
|
|
struct queue vo_mappings;
|
|
|
|
/* memory protection flags. mappings of this vm_object can only use
|
|
* a subset of the flags set in this mask. */
|
|
enum vm_prot vo_prot;
|
|
|
|
/* btree of vm_pages that have been allocated to this vm_object.
|
|
* vm_page->p_vmo_offset and the size of each page is the bst key. */
|
|
struct btree vo_pages;
|
|
/* total length of the vm_object in bytes. */
|
|
size_t vo_size;
|
|
};
|
|
|
|
extern kern_status_t vm_object_type_init(void);
|
|
|
|
/* create a vm_object with the specified length in bytes and protection flags.
|
|
* the length will be automatically rounded up to the nearest vm_object page
|
|
* order size. the actual page frames themselves won't be allocated until
|
|
* they are mapped and accessed. */
|
|
extern struct vm_object *vm_object_create(
|
|
const char *name,
|
|
size_t len,
|
|
enum vm_prot prot);
|
|
|
|
/* create a vm_object that represents the specified range of physical memory.
|
|
* the length will be automatically rounded up to the nearest vm_object page
|
|
* order size.
|
|
* NOTE this function assumes that the physical memory has already been
|
|
* reserved, and is not in use by any other kernel component. */
|
|
extern struct vm_object *vm_object_create_in_place(
|
|
const char *name,
|
|
phys_addr_t base,
|
|
size_t len,
|
|
enum vm_prot prot);
|
|
|
|
extern struct vm_page *vm_object_get_page(
|
|
const struct vm_object *vo,
|
|
off_t offset);
|
|
|
|
extern struct vm_page *vm_object_alloc_page(
|
|
struct vm_object *vo,
|
|
off_t offset,
|
|
enum vm_page_order size);
|
|
|
|
DEFINE_OBJECT_LOCK_FUNCTION(vm_object, vo_base)
|
|
|
|
#endif
|