sw사관학교정글 59

[week11] PintOS - Project 3(Virtual Memory) : Anonymous Page

Project 3 : Anonymous Page 구현 무엇을 하는가? anonymous page를 구현하는 것이 목표이다. anonymous page가 무엇인가? anonymous page는 file-backed page와 달리 contents를 가져올 file이나 device가 없는 page를 말한다. 이들은 프로세스 자체에서 런타임 때 만들어지고 사용된다. stack 과 heap 영역의 메모리들이 여기에 해당된다. vm_alloc_page_with_initializer()를 구현해야 한다. 이 함수의 역할은 전달된 vm_type에 따라 적절한 initializer를 가져와서 uninit_new를 호출하는 역할이다. // vm/vm.c /* Create the pending page object wit..

[week10] PintOS - Project 3(Virtual Memory) : Memory Management

Project 3 : Memory Management 구현 우리가 무엇을 하는가? PintOS는 메모리의 가상 및 물리적 매핑을 관리하기 위한 page table(pml4)이 있다. 하지만 이것만으로는 충분하지 않다. page fault 및 resource management를 처리하기 위해 각 page에 대한 추가 정보를 저장할 수 있는 supplementary page table이 필요하다. supplemental_page_table 구현 supplemental_page_table을 hash table을 사용해서 구현해보자. hash 구조체는 다음과 같다. // include/lib/kernel/hash.h /* Hash table. */ struct hash { size_t elem_cnt; /* ..

[week09] PintOS - Project 2(User Programs) : System Calls All Pass 받기 위한 험난한 과정

앞선 게시물과 중복되는 코드가 있을 수 있다. 왜냐하면 All Pass 를 받고나서 정리를 했기 때문이다. 그래도 혹시 같은 문제로 고생하는 사람들을 위해 내가 어떻게 문제를 해결했는지 정리해 놓은 것을 공유한다. 확실히 fail을 pass로 만드는 과정에서 더 알아보게 되고, 더 남는게 많은 것 같다. 현재 8개 fail FAIL tests/userprog/open-twice FAIL tests/userprog/read-stdout FAIL tests/userprog/write-stdin FAIL tests/userprog/exec-read FAIL tests/userprog/rox-simple FAIL tests/userprog/rox-child FAIL tests/userprog/rox-multic..

[week09] PintOS - Project 2(User Programs) : System Calls 나머지

Project 2 : System call 나머지 나머지 system call들을 구현해보도록 하자! syscall.c 헤더파일 추가 및 함수의 원형 선언 // userprog/syscall.c #include "threads/init.h" #include "threads/synch.h" #include "threads/palloc.h" #include "filesys/filesys.h" #include "filesys/file.h" #include "userprog/process.h" static struct file *find_file_by_fd(int fd); void check_address(uaddr); void halt(void); void exit(int status); bool create..

[week09] PintOS - Project 2(User Programs) : System Calls 개요 및 File Descriptor 구현

Implement system call infrastructure userprog/syscall.c에 있는 system call handler를 구현하라. system call 번호를 검색한 다음 시스템 호출 인수를 검색하고 적절한 작업을 수행해야 한다. System Call Details 첫 번째 프로젝트는 운영 체제가 사용자 프로그램으로부터 제어권을 되찾을 수 있는 한 가지 방법을 이미 다루었다: 타이머와 입출력 장치로부터의 인터럽트. 이것들은 CPU 외부의 엔티티에 의해 발생하므로 "외부(external)" 인터럽트이다. 운영 체제는 프로그램 코드에서 발생하는 이벤트인 소프트웨어 예외도 처리한다. 그것들은 page fault 또는 division by zero와 같은 error일 수 있다. 예외(E..

[week09] PintOS - Project 2(User Programs) : Argument Passing

x86-64 calling convention calling convention의 규칙 중 하나는 함수 인수와 반환값이 전달되는 방법을 제어한다. x86-64 Linux에서 처음 6개의 함수 인수(function arguments)들은 각각 %rdi, %rsi, %rdx, %rcx, %r8, %r9 레지스터에 전달된다. 일곱 번째 인자와 그 이후의 인수는 stack에 전달된다. 그리고 반환값은 %rax 레지스터에 전달된다. 전체 규칙은 이것보다 더 복잡하다. 몇 가지 주요 사항들을 살펴보자. single machine word(64 bits/8 bytes)에 맞는 structure argument는 single register에 전달됨 Example: struct small { char a1, a2; }..

[week09] PintOS - Project 2(User Programs) : Introduction

Project 2 : User Programs The base code already supports loading and running user programs, but no I/O or interactivity is possible. 기본 코드는 이미 사용자 프로그램 로드 및 실행을 지원하지만 I/O 또는 상호 작용은 불가능하다. In this project, you will enable programs to interact with the OS via system calls. 이 프로젝트에서는 프로그램이 시스템 호출을 통해 OS와 상호 작용할 수 있도록 한다. Background 지금까지 핀토스에서 실행했던 모든 코드는 운영 체제 커널의 일부였다. 운영 체제 위에서 사용자 프로그램을 실행하기 시작하..