[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
file.h File Reference
#include "filesys/file.h"
#include "vm/vm.h"
Include dependency graph for file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  file_page
 

Functions

void vm_file_init (void)
 
bool file_backed_initializer (struct page *page, enum vm_type type, void *kva)
 
void * do_mmap (void *addr, size_t length, int writable, struct file *file, off_t offset)
 
void do_munmap (void *va)
 

Function Documentation

◆ do_mmap()

void * do_mmap ( void *  addr,
size_t  length,
int  writable,
struct file file,
off_t  offset 
)
90 {
91 struct file *re_file = file_reopen(file);
92
93 void * mmap_addr = addr; // 페이지 확장 시, 리턴 주소 값 변경 방지
94 size_t read_bytes = length > file_length(file) ? file_length(file) : length; // 실제 읽어올 바이트 수
95 size_t zero_bytes = PGSIZE - (read_bytes % PGSIZE); // 페이지에서 read_bytes를 제외한 공간은 0으로 채운다.
96
97 // 읽으려는 바이트 수만큼 페이지를 할당한다.
98 while (read_bytes > 0 || zero_bytes > 0) {
99 size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE;
100 size_t page_zero_bytes = page_read_bytes == PGSIZE ? 0 : PGSIZE - page_read_bytes;
101
102 struct segment_aux *segment_aux = (struct segment_aux*)malloc(sizeof(struct segment_aux));
103 segment_aux->file = re_file;
106
107 // vm_alloc_page가 안되는 이유? -> aux(segment_aux) 값으로 파일에 대한 정보를 넘겨줘야한다.
109 free(mmap_addr); // 안전장치
110 return NULL;
111 }
112 read_bytes -= page_read_bytes;
113 zero_bytes -= page_zero_bytes;
114
115 // 페이지 하나 할당에 따른 주소값, 오프셋 변경
116 mmap_addr += PGSIZE;
118 }
119 return addr;
120}
struct file * file_reopen(struct file *file)
Definition: file.c:34
off_t file_length(struct file *file)
Definition: file.c:141
void * malloc(size_t) __attribute__((malloc))
Definition: malloc.c:85
void free(void *)
Definition: malloc.c:202
bool lazy_load_segment(struct page *page, void *aux)
#define NULL
Definition: stddef.h:4
Definition: file.c:7
Definition: process.h:15
struct file * file
Definition: process.h:16
off_t offset
Definition: process.h:17
size_t page_read_bytes
Definition: process.h:18
#define PGSIZE
Definition: vaddr.h:20
bool vm_alloc_page_with_initializer(enum vm_type type, void *upage, bool writable, vm_initializer *init, void *aux)
Definition: vm.c:74
@ VM_FILE
Definition: vm.h:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_munmap()

void do_munmap ( void *  va)
124 {
125 while (true) {
126 struct page* page = spt_find_page(&thread_current()->spt, addr);
127
128 if (page == NULL)
129 break;
130
131 struct segment_aux * segment_aux = (struct segment_aux *) page->uninit.aux;
132
133 // dirty bit(사용된 적이 있으면) -> 파일에 다시 쓰고 dirty bit를 0으로 만들어줌
134 if(pml4_is_dirty(thread_current()->pml4, page->va)) {
135 file_write_at(segment_aux->file, addr, segment_aux->page_read_bytes, segment_aux->offset); // ? i-node에 내가 쓰던 파일이 해제됨을 알린다고 보면 될 듯?
136 pml4_set_dirty (thread_current()->pml4, page->va, 0);
137 }
138
140 addr += PGSIZE;
141 }
142}
off_t file_write_at(struct file *file, const void *buffer, off_t size, off_t file_ofs)
Definition: file.c:111
bool pml4_is_dirty(uint64_t *pml4, const void *upage)
Definition: mmu.c:277
void pml4_clear_page(uint64_t *pml4, void *upage)
Definition: mmu.c:258
void pml4_set_dirty(uint64_t *pml4, const void *upage, bool dirty)
Definition: mmu.c:285
Definition: vm.h:51
void * va
Definition: vm.h:53
struct uninit_page uninit
Definition: vm.h:67
void * aux
Definition: uninit.h:16
struct thread * thread_current(void)
Definition: thread.c:301
struct page * spt_find_page(struct supplemental_page_table *spt, void *va)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_backed_initializer()

bool file_backed_initializer ( struct page page,
enum vm_type  type,
void *  kva 
)
26 {
27 /* Set up the handler */
29
30 struct file_page *file_page = &page->file;
31
32 return true;
33}
Definition: file.h:9
const struct page_operations * operations
Definition: vm.h:52
struct file_page file
Definition: vm.h:69
static const struct page_operations file_ops
Definition: file.c:12
Here is the caller graph for this function:

◆ vm_file_init()

void vm_file_init ( void  )
21 {
22}
Here is the caller graph for this function: