Files
pintos_22/src/vm/page.h
2024-12-06 00:56:03 +00:00

48 lines
1.8 KiB
C

#ifndef VM_PAGE_H
#define VM_PAGE_H
#include "threads/thread.h"
#include "threads/synch.h"
#include "filesys/off_t.h"
enum page_type {
PAGE_FILE,
PAGE_MMAP
};
struct page_entry {
enum page_type type; /* Type of Data that should go into the page */
void *upage; /* Start Address of the User Page (Key of hash table). */
/* Data for swapped pages */
struct lock lock; /* Enforces mutual exclusion in accessing the page
referenced by the entry between its owning process
and any thread performing page eviction. */
/* File Data */
struct file *file; /* Pointer to the file for executables. */
off_t offset; /* Offset of the page content within the file. */
uint32_t read_bytes; /* Number of bytes to read within the page. */
uint32_t zero_bytes; /* Number of bytes to zero within the page. */
bool writable; /* Flag for whether this page is writable or not. */
struct hash_elem elem; /* An elem for the hash table. */
};
unsigned page_hash (const struct hash_elem *e, void *aux);
bool page_less (const struct hash_elem *a_, const struct hash_elem *b_,
void *aux);
struct page_entry *page_insert_swapped (void *upage, void* kpage,
struct thread *owner);
struct page_entry *page_insert_file (struct file *file, off_t ofs, void *upage,
uint32_t read_bytes, uint32_t zero_bytes,
bool writable, enum page_type);
struct page_entry *page_get (struct thread *thread, void *upage);
bool page_load_file (struct page_entry *page, bool writable);
void page_cleanup (struct hash_elem *e, void *aux);
bool page_in_swap (struct thread *, void *);
size_t page_get_swap (struct thread *owner, void *upage);
#endif /* vm/frame.h */