2026-02-19 19:13:44 +00:00
|
|
|
#ifndef KERNEL_VM_OBJECT_H_
|
|
|
|
|
#define KERNEL_VM_OBJECT_H_
|
|
|
|
|
|
|
|
|
|
#include <kernel/locks.h>
|
|
|
|
|
#include <kernel/object.h>
|
|
|
|
|
|
|
|
|
|
#define VM_OBJECT_NAME_MAX 64
|
|
|
|
|
|
2026-03-14 22:39:14 +00:00
|
|
|
struct vm_controller;
|
|
|
|
|
|
2026-02-19 19:13:44 +00:00
|
|
|
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,
|
2026-03-14 22:39:14 +00:00
|
|
|
/* this vm-object is/was attached to a vm-controller */
|
|
|
|
|
VMO_CONTROLLER = 0x02u,
|
|
|
|
|
|
|
|
|
|
/* these flags are for use with vm_object_get_page */
|
|
|
|
|
/**************************************************/
|
|
|
|
|
|
|
|
|
|
/* if the relevant page hasn't been allocated yet, it will be allocated
|
|
|
|
|
* and returned. if this flag isn't specified, NULL will be returned. */
|
|
|
|
|
VMO_ALLOCATE_MISSING_PAGE = 0x04u,
|
|
|
|
|
/* if the vm-object is attached to a vm-controller, and the relevant
|
|
|
|
|
* page is uncommitted, send a request to the vm-controller to provide
|
|
|
|
|
* the missing page. will result in the vm-object being unlocked and
|
|
|
|
|
* the current thread sleeping until the request is fulfilled. the
|
|
|
|
|
* vm-object will be re-locked before the function returns. */
|
|
|
|
|
VMO_REQUEST_MISSING_PAGE = 0x08u,
|
2026-02-19 19:13:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2026-03-14 22:39:14 +00:00
|
|
|
struct vm_controller *vo_ctrl;
|
|
|
|
|
equeue_key_t vo_key;
|
|
|
|
|
struct btree_node vo_ctrl_node;
|
|
|
|
|
|
|
|
|
|
/* memory protection flags. mappings of this vm_object can only
|
|
|
|
|
* use a subset of the flags set in this mask. */
|
2026-02-19 19:13:44 +00:00
|
|
|
vm_prot_t 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);
|
|
|
|
|
extern struct vm_object *vm_object_cast(struct object *obj);
|
|
|
|
|
|
|
|
|
|
/* 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 name_len,
|
|
|
|
|
size_t data_len,
|
|
|
|
|
vm_prot_t 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,
|
|
|
|
|
size_t name_len,
|
|
|
|
|
phys_addr_t base,
|
|
|
|
|
size_t data_len,
|
|
|
|
|
vm_prot_t prot);
|
|
|
|
|
|
|
|
|
|
extern struct vm_page *vm_object_get_page(
|
|
|
|
|
struct vm_object *vo,
|
|
|
|
|
off_t offset,
|
2026-03-14 22:39:14 +00:00
|
|
|
enum vm_object_flags flags,
|
|
|
|
|
unsigned long *irq_flags);
|
2026-02-19 19:13:44 +00:00
|
|
|
|
|
|
|
|
extern kern_status_t vm_object_read(
|
|
|
|
|
struct vm_object *vo,
|
|
|
|
|
void *dst,
|
|
|
|
|
off_t offset,
|
|
|
|
|
size_t count,
|
|
|
|
|
size_t *nr_read);
|
|
|
|
|
extern kern_status_t vm_object_write(
|
|
|
|
|
struct vm_object *vo,
|
|
|
|
|
const void *dst,
|
|
|
|
|
off_t offset,
|
|
|
|
|
size_t count,
|
|
|
|
|
size_t *nr_written);
|
|
|
|
|
extern kern_status_t vm_object_copy(
|
|
|
|
|
struct vm_object *dst,
|
|
|
|
|
off_t dst_offset,
|
|
|
|
|
struct vm_object *src,
|
|
|
|
|
off_t src_offset,
|
|
|
|
|
size_t count,
|
|
|
|
|
size_t *nr_copied);
|
2026-03-14 22:36:21 +00:00
|
|
|
extern kern_status_t vm_object_transfer(
|
|
|
|
|
struct vm_object *dst,
|
|
|
|
|
off_t dst_offset,
|
|
|
|
|
struct vm_object *src,
|
|
|
|
|
off_t src_offset,
|
|
|
|
|
size_t count,
|
|
|
|
|
size_t *nr_moved);
|
2026-02-19 19:13:44 +00:00
|
|
|
|
|
|
|
|
DEFINE_OBJECT_LOCK_FUNCTION(vm_object, vo_base)
|
|
|
|
|
|
|
|
|
|
#endif
|