70 lines
2.5 KiB
C
70 lines
2.5 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_EXECUTABLE,
|
|
PAGE_MMAP,
|
|
PAGE_SHARED
|
|
};
|
|
|
|
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. */
|
|
};
|
|
|
|
struct shared_file_page
|
|
{
|
|
struct file *file; /* The shared file page's source file, used for indexing
|
|
the table. */
|
|
void *upage; /* The shared page's upage which is the same across all process
|
|
using it. Used for indexing the table. */
|
|
void *frame; /* Set to the frame address of the page when it is in memory.
|
|
Set to NULL when the page is in swap. */
|
|
size_t swap_slot; /* Set to the swap_slot of the shared paged if it is
|
|
currently in swap. Should not be used when frame is not
|
|
NULL.*/
|
|
int ref_count; /* Number of processes that are using this shared page. */
|
|
|
|
struct hash_elem elem; /* AN elem for the hash table. */
|
|
};
|
|
|
|
bool init_pages (struct hash *pages);
|
|
bool page_insert_swapped (void *upage, void *kpage, struct list *owners,
|
|
struct thread *cur);
|
|
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);
|
|
void page_cleanup (struct hash_elem *e, void *aux);
|
|
|
|
bool page_in_swap (struct thread *, void *);
|
|
bool page_in_swap_pte (uint32_t *pte);
|
|
size_t page_get_swap (struct thread *owner, void *upage);
|
|
size_t page_get_swap_pte (uint32_t *pte);
|
|
|
|
bool page_is_shared_pte (uint32_t *pte);
|
|
void shared_file_pages_init (void);
|
|
|
|
#endif
|