summaryrefslogtreecommitdiffstats
path: root/vm/page.h
blob: 9cea048607332db2fd1a081cf05c6a1ec47bf57f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef VM_PAGE_H
#define VM_PAGE_H

#include <debug.h>
#include "hash.h"
#include "filesys/off_t.h"

/* supplemental page table entry */
struct page_table_entry
{
  void *upage;            /* virtual address of page */
  bool loaded;            /* indicates if page is loaded */
  enum
    {
      PAGE_SEGMENT,
      PAGE_MEMORY_MAPPED_FILE,
    } type;               /* type of page */

  union
    {
      /* structure needed for lazy loading of data segments */
      struct segment
        {
          struct file *file;
          off_t ofs;
          uint32_t read_bytes;
          uint32_t zero_bytes;
          bool writable;
        } segment;
    };

  struct hash_elem elem;  /* Hash element. */
};

void page_table_init (struct hash *ht);
void page_table_free (struct hash *ht);
struct page_table_entry *page_table_fetch (struct hash *ht, void *upage);
bool page_table_insert_segment (struct file *file, off_t ofs, uint8_t *upage,
    uint32_t read_bytes, uint32_t zero_bytes, bool writable);
bool page_load (struct page_table_entry *pte);

#endif