62 lines
1.9 KiB
C
62 lines
1.9 KiB
C
#ifndef VM_PAGE_H
|
|
#define VM_PAGE_H
|
|
|
|
#include "threads/thread.h"
|
|
#include "filesys/off_t.h"
|
|
|
|
struct hash shared_files;
|
|
|
|
enum page_type {
|
|
PAGE_EXECUTABLE,
|
|
PAGE_EMPTY
|
|
};
|
|
|
|
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). */
|
|
|
|
/* 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_entry {
|
|
struct file *file; /* Pointer to the file. */
|
|
struct hash pages;
|
|
int ref_count;
|
|
|
|
struct hash_elem elem;
|
|
};
|
|
|
|
struct shared_page_entry {
|
|
void *upage;
|
|
void *frame;
|
|
|
|
struct hash_elem elem;
|
|
};
|
|
|
|
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 (struct file *file, off_t ofs, void *upage,
|
|
uint32_t read_bytes, uint32_t zero_bytes,
|
|
bool writable, enum page_type type);
|
|
struct page_entry *page_get (void *upage);
|
|
bool page_load (struct page_entry *page, bool writable);
|
|
void page_cleanup (struct hash_elem *e, void *aux);
|
|
|
|
unsigned shared_file_hash (const struct hash_elem *e, void *aux);
|
|
bool shared_file_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
|
void *aux);
|
|
struct shared_page_entry *shared_page_get (struct file *file, void *upage);
|
|
|
|
void page_set_swap (struct thread *, void *, size_t);
|
|
size_t page_get_swap (struct thread *, void *);
|
|
|
|
#endif /* vm/frame.h */
|