[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
vm.h
Go to the documentation of this file.
1#ifndef VM_VM_H
2#define VM_VM_H
3#include <stdbool.h>
4#include "threads/palloc.h"
5
6#include <hash.h> // need to hash
7
8enum vm_type {
9 /* page not initialized */
10 /* uninit.c */
12 /* page not related to the file, aka anonymous page */
13 /* anon.c */
15 /* page that realated to the file */
16 /* file.c */
18 /* page that hold the page cache, for project 4 */
19 /* 프로젝트 4에서 다룰 것 */
21
22 /* Bit flags to store state */
23
24 /* Auxillary bit flag marker for store information. You can add more
25 * markers, until the value is fit in the int. */
26 VM_MARKER_0 = (1 << 3),
27 VM_MARKER_1 = (1 << 4),
28
29 /* DO NOT EXCEED THIS VALUE. */
30 VM_MARKER_END = (1 << 31),
31};
32
33#include "vm/uninit.h"
34#include "vm/anon.h"
35#include "vm/file.h"
36#ifdef EFILESYS
37#include "filesys/page_cache.h"
38#endif
39
40struct page_operations;
41struct thread;
42
43#define VM_TYPE(type) ((type) & 7)
44
45/* The representation of "page".
46 * This is kind of "parent class", which has four "child class"es, which are
47 * uninit_page, file_page, anon_page, and page cache (project4).
48 * DO NOT REMOVE/MODIFY PREDEFINED MEMBER OF THIS STRUCTURE. */
49/* "페이지"를 나타낸다.
50 * uninit_page, file_page, anon_page, page cache의 4개의 자녀 클래스를 가지고 있다. */
51struct page {
53 void *va; /* Address in terms of user space */
54 struct frame *frame; /* Back reference for frame */
55
56 /* Your implementation */
57 /*-------------------------[P3]hash table---------------------------------*/
58 struct hash_elem hash_elem; // 해쉬 테이블 element(page와 해쉬테이블 연결해주는 element)
59 // key : page->va, value : struct page
60 bool writable; // 페이지의 R/W 여부 (ref. pml4_set_page)
61 /*-------------------------[P3]hash table---------------------------------*/
62
63 /* Per-type data are binded into the union.
64 * Each function automatically detects the current union */
65 // page type에 맞는 구조체 형식을 가질 수 있도록 정의
66 union {
70#ifdef EFILESYS
72#endif
73 };
74};
75
76/* The representation of "frame" */
77struct frame {
78 void *kva;
79 struct page *page;
80 /*-------------------------[P3]frame table---------------------------------*/
81 struct list_elem frame_elem; // frame을 리스트 형태로 구현했기 때문에 list_elem을 추가한다.
82 /*-------------------------[P3]frame table---------------------------------*/
83
84};
85
86
87
88
89
90/* The function table for page operations.
91 * This is one way of implementing "interface" in C.
92 * Put the table of "method" into the struct's member, and
93 * call it whenever you needed. */
94/*
95 * 함수 포인터들과 type 멤버로 이루어져 있음
96 * swap in,swap out,destroy를 사용할 때 해당 page의 타입에 따라 구조체로 정의된 함수를 사용하도록 구성
97 * page type에 따라 구조체, 사용함수를 구분해 놓는 목적
98*/
100 bool (*swap_in) (struct page *, void *);
101 bool (*swap_out) (struct page *);
102 void (*destroy) (struct page *);
104};
105
106#define swap_in(page, v) (page)->operations->swap_in ((page), v)
107#define swap_out(page) (page)->operations->swap_out (page)
108#define destroy(page) \
109 if ((page)->operations->destroy) (page)->operations->destroy (page)
110
111/* Representation of current process's memory space.
112 * We don't want to force you to obey any specific design for this struct.
113 * All designs up to you for this. */
114/* 보조 페이지 테이블에 대해 구현한다. */
116 /*-------------------------[P3]hash table---------------------------------*/
118 /*-------------------------[P3]hash table---------------------------------*/
119};
120
121#include "threads/thread.h"
124 struct supplemental_page_table *src);
127 void *va);
129void spt_remove_page (struct supplemental_page_table *spt, struct page *page);
130
131void vm_init (void);
132bool vm_try_handle_fault (struct intr_frame *f, void *addr, bool user,
133 bool write, bool not_present);
134
135#define vm_alloc_page(type, upage, writable) \
136 vm_alloc_page_with_initializer ((type), (upage), (writable), NULL, NULL)
137bool vm_alloc_page_with_initializer (enum vm_type type, void *upage,
138 bool writable, vm_initializer *init, void *aux);
139void vm_dealloc_page (struct page *page);
140bool vm_claim_page (void *va);
141enum vm_type page_get_type (struct page *page);
142
143#endif /* VM_VM_H */
int write(int fd, const void *buffer, unsigned length)
열린 파일에 데이터를 쓰는 시스템 콜
Definition: syscall.c:336
#define bool
Definition: stdbool.h:4
Definition: anon.h:7
Definition: file.h:9
Definition: file.c:7
Definition: vm.h:77
struct list_elem frame_elem
Definition: vm.h:81
struct page * page
Definition: vm.h:79
void * kva
Definition: vm.h:78
Definition: hash.h:29
Definition: hash.h:58
Definition: interrupt.h:37
Definition: list.h:87
Definition: page_cache.h:8
Definition: vm.h:99
enum vm_type type
Definition: vm.h:103
bool(* swap_in)(struct page *, void *)
Definition: vm.h:100
void(* destroy)(struct page *)
Definition: vm.h:102
bool(* swap_out)(struct page *)
Definition: vm.h:101
Definition: vm.h:51
const struct page_operations * operations
Definition: vm.h:52
bool writable
Definition: vm.h:60
void * va
Definition: vm.h:53
struct frame * frame
Definition: vm.h:54
struct uninit_page uninit
Definition: vm.h:67
struct anon_page anon
Definition: vm.h:68
Definition: vm.h:115
struct hash spt_hash
Definition: vm.h:117
Definition: thread.h:100
Definition: uninit.h:12
bool vm_initializer(struct page *, void *aux)
Definition: uninit.h:8
static void init(void)
Definition: vga.c:36
bool supplemental_page_table_copy(struct supplemental_page_table *dst, struct supplemental_page_table *src)
bool vm_try_handle_fault(struct intr_frame *f, void *addr, bool user, bool write, bool not_present)
struct page * spt_find_page(struct supplemental_page_table *spt, void *va)
void vm_init(void)
Definition: vm.c:25
bool vm_alloc_page_with_initializer(enum vm_type type, void *upage, bool writable, vm_initializer *init, void *aux)
Definition: vm.c:74
bool vm_claim_page(void *va)
vm_type
Definition: vm.h:8
@ VM_UNINIT
Definition: vm.h:11
@ VM_MARKER_0
Definition: vm.h:26
@ VM_MARKER_END
Definition: vm.h:30
@ VM_PAGE_CACHE
Definition: vm.h:20
@ VM_FILE
Definition: vm.h:17
@ VM_ANON
Definition: vm.h:14
@ VM_MARKER_1
Definition: vm.h:27
void supplemental_page_table_init(struct supplemental_page_table *spt)
enum vm_type page_get_type(struct page *page)
Definition: vm.c:43
void spt_remove_page(struct supplemental_page_table *spt, struct page *page)
Definition: vm.c:163
void vm_dealloc_page(struct page *page)
Definition: vm.c:309
bool spt_insert_page(struct supplemental_page_table *spt, struct page *page)
void supplemental_page_table_kill(struct supplemental_page_table *spt)