62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
#pragma once
|
|
|
|
#include <zinnia/errno.h>
|
|
#include <zinnia/mman.h>
|
|
#include <zinnia/mutex.h>
|
|
#include <zinnia/pmap.h>
|
|
#include <zinnia/spin.h>
|
|
#include <zinnia/tailq.h>
|
|
#include <zinnia/vmo.h>
|
|
|
|
struct vma_mapping {
|
|
size_t start_page;
|
|
size_t end_page;
|
|
size_t offset_page;
|
|
struct vmo* object;
|
|
enum prot_flags prot;
|
|
tailq_link(struct vma_mapping) link;
|
|
};
|
|
|
|
// Virtual address space.
|
|
struct vma {
|
|
// Architecture-specific virtual memory map implementation.
|
|
struct pmap pmap;
|
|
tailq_head(struct vma_mapping) mappings;
|
|
struct spinlock lock;
|
|
};
|
|
|
|
// Try to create a new, empty virtual address space.
|
|
errno_t vma_new(struct vma** out);
|
|
|
|
// Delete a virtual address space.
|
|
void vma_free(struct vma* v);
|
|
|
|
errno_t vma_map(
|
|
struct vma* vma,
|
|
struct vmo* vmo,
|
|
uintptr_t addr,
|
|
size_t len,
|
|
enum prot_flags flags,
|
|
uintptr_t vmo_offset
|
|
);
|
|
|
|
// Remove any mappings in the given address range.
|
|
errno_t vma_unmap(struct vma* v, uintptr_t vaddr, size_t size);
|
|
|
|
// Change the protection of an existing mapping.
|
|
errno_t vma_protect(struct vma* v, uintptr_t vaddr, size_t size, enum prot_flags flags);
|
|
|
|
struct vma_fault_info {
|
|
uintptr_t ip;
|
|
uintptr_t addr;
|
|
bool caused_by_user:1;
|
|
bool caused_by_write:1;
|
|
bool caused_by_fetch:1;
|
|
bool page_was_present:1;
|
|
};
|
|
|
|
// Try to handle a page fault.
|
|
bool vma_page_fault(struct vma* v, const struct vma_fault_info* info);
|
|
|
|
extern struct vma kernel_vma;
|