#ifndef KERNEL_VM_OBJECT_H_ #define KERNEL_VM_OBJECT_H_ #include #include #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. */ 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( 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); 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); DEFINE_OBJECT_LOCK_FUNCTION(vm_object, vo_base) #endif