-
핀토스 코드 비교 정리programming/pintos 2018. 12. 31. 00:17
내가 들은 운영체제 수업에서는 스탠포트 컴퓨터과학과에서 공식적으로 배포하는 핀토스 대신 일부 수정한 버전을 쓴다. 스탠포드의 원본 코드(이하 "스탠포드 핀토스")와 내가 배포 받은 수정 코드("서강대 핀토스")의 차이점을 비교한다. 스탠포드 핀토스는 2018년 12월 30일에 다운로드 받았고, 서강대 핀토스는 2018년 12월 30일 현재 링크가 살아있음이 확인된다. 일일히 수작업으로 할 수는 없어서, 다음과 같은 파이썬 코드를 돌렸다.
import subprocess import os from collections import deque DIR1 = "/home/taegyung/Downloads/pintos" DIR2 = "/home/taegyung/Downloads/pintos_modified" q = deque(os.listdir(DIR1)) while True: try: curr = q.popleft() except IndexError: break fullpath1 = os.path.join(DIR1, curr) if os.path.isdir(fullpath1): for sub in os.listdir(os.path.join(DIR1, curr)): q.append(os.path.join(curr, sub)) else: fullpath2 = os.path.join(DIR2, curr) if not os.path.exists(fullpath2): print(fullpath2, "DOES NOT EXIST") else: command = "diff " + fullpath1 + " " + fullpath2 try: diff = subprocess.check_output(command, shell=True) except subprocess.CalledProcessError as e: diff = e.output if diff not in [None, b'']: print(curr) print(diff.decode('utf-8')) q = deque(os.listdir(DIR2)) while True: try: curr = q.popleft() except IndexError: break fullpath2 = os.path.join(DIR2, curr) if os.path.isdir(fullpath2): for sub in os.listdir(os.path.join(DIR2, curr)): q.append(os.path.join(curr, sub)) else: fullpath1 = os.path.join(DIR1, curr) if not os.path.exists(fullpath2): print(fullpath1, "DOES NOT EXIST")
그 결과는 다음과 같다. 대부분은 변수 이름이 바뀌거나 띄어쓰기에 차이가 있는 수준이다. 일부는 프로그램의 흐름이 아예 달라진다. 추측하기로는 서강대 핀토스가 스탠포드 핀토스의 옛 버전에서 갈라져 나온 것 같지만, 정확히 언제 분기 되었는지를 파악하기는 쉽지 않다. 일단 내 핀토스 프로젝트는 스탠포드 핀토스로 진행하고, 내가 작성한 부분을 그대로 서강대 핀토스에 붙여넣어 작동하는지를 확인해보겠다.
src/Make.config 13,19d12 < < # Pintos doesn't compile/run properly using gcc 4.3+. Force 4.1 for now. < CCPROG = /usr/class/cs140/x86_64/bin/i586-elf-gcc < ifeq ($(strip $(shell command -v $(CCPROG) 2> /dev/null)),) < CCPROG = gcc < endif < 21c14 < CC = $(CCPROG) --- > CC = gcc 26c19 < CC = $(CCPROG) -m32 --- > CC = gcc -m32 55c48 < ifeq ($(strip $(shell $(LD) --help | grep -q build-id; echo $$?)),0) --- > ifeq ($(strip $(shell $(LD) --build-id=none -e 0 /dev/null -o /dev/null 2>&1; echo $$?)),0) src/threads/init.c 160c160 < uint32_t *pd, *pt; --- > uint32_t *pd, *pt_; 165c165 < pt = NULL; --- > pt_ = NULL; 176,177c176,177 < pt = palloc_get_page (PAL_ASSERT | PAL_ZERO); < pd[pde_idx] = pde_create (pt); --- > pt_ = palloc_get_page (PAL_ASSERT | PAL_ZERO); > pd[pde_idx] = pde_create (pt_); 180c180 < pt[pte_idx] = pte_create_kernel (vaddr, !in_kernel_text); --- > pt_[pte_idx] = pte_create_kernel (vaddr, !in_kernel_text); src/threads/thread.c 109,111c109,111 < struct semaphore idle_started; < sema_init (&idle_started, 0); < thread_create ("idle", PRI_MIN, idle, &idle_started); --- > struct semaphore start_idle; > sema_init (&start_idle, 0); > thread_create ("idle", PRI_MIN, idle, &start_idle); 117c117 < sema_down (&idle_started); --- > sema_down (&start_idle); src/threads/pte.h 102,103c102,103 < static inline void *pte_get_page (uint32_t pte) { < return ptov (pte & PTE_ADDR); --- > static inline void *pte_get_page (uint32_t pte_) { > return ptov (pte_ & PTE_ADDR); src/userprog/process.c 214c214 < off_t file_ofs; --- > off_t file_ofset; 246c246 < file_ofs = ehdr.e_phoff; --- > file_ofset = ehdr.e_phoff; 251c251 < if (file_ofs < 0 || file_ofs > file_length (file)) --- > if (file_ofset < 0 || file_ofset > file_length (file)) 253c253 < file_seek (file, file_ofs); --- > file_seek (file, file_ofset); 257c257 < file_ofs += sizeof phdr; --- > file_ofset += sizeof phdr; 400,401c400,401 < uint8_t *kpage = palloc_get_page (PAL_USER); < if (kpage == NULL) --- > uint8_t *knpage = palloc_get_page (PAL_USER); > if (knpage == NULL) 405c405 < if (file_read (file, kpage, page_read_bytes) != (int) page_read_bytes) --- > if (file_read (file, knpage, page_read_bytes) != (int) page_read_bytes) 407c407 < palloc_free_page (kpage); --- > palloc_free_page (knpage); 410c410 < memset (kpage + page_read_bytes, 0, page_zero_bytes); --- > memset (knpage + page_read_bytes, 0, page_zero_bytes); 413c413 < if (!install_page (upage, kpage, writable)) --- > if (!install_page (upage, knpage, writable)) 415c415 < palloc_free_page (kpage); --- > palloc_free_page (knpage); 459c459 < struct thread *t = thread_current (); --- > struct thread *th = thread_current (); 463,464c463,464 < return (pagedir_get_page (t->pagedir, upage) == NULL < && pagedir_set_page (t->pagedir, upage, kpage, writable)); --- > return (pagedir_get_page (th->pagedir, upage) == NULL > && pagedir_set_page (th->pagedir, upage, kpage, writable)); src/userprog/gdt.c 46c46 < gdt[SEL_TSS / sizeof *gdt] = make_tss_desc (tss_get ()); --- > gdt[SEL_TSS / sizeof *gdt] = make_tss_desc (tss_get_ ()); src/userprog/tss.c 93c93 < tss_get (void) --- > tss_get_ (void) src/userprog/tss.h 8c8 < struct tss *tss_get (void); --- > struct tss *tss_get_ (void); src/utils/squish-pty.c 80,81c80,82 < Sets *FD to -1 if the fd is no longer readable or writable. */ < static void --- > Returns true if processing may continue, false if we're all > done. */ > static bool 91c92 < *fd = -1; --- > return false; 95a97,98 > else > return true; 102a106 > return true; 141c145 < while (pipes[1].in != -1) --- > while (pipes[0].in != -1 || pipes[1].in != -1) 175c179,206 < break; --- > { > /* Child died. Do final relaying. */ > struct pipe *p = &pipes[1]; > if (p->out == -1) > return; > make_nonblocking (STDOUT_FILENO, false); > for (;;) > { > ssize_t n; > > /* Write buffer. */ > while (p->size > 0) > { > n = write (p->out, p->buf + p->ofs, p->size); > if (n < 0) > fail_io ("write"); > else if (n == 0) > fail_io ("zero-length write"); > p->ofs += n; > p->size -= n; > } > p->ofs = 0; > > p->size = n = read (p->in, p->buf, sizeof p->buf); > if (n <= 0) > return; > } > } 194,195c225,226 < else < handle_error (n, &p->in, p->in == pty, "read"); --- > else if (!handle_error (n, &p->in, p->in == pty, "read")) > return; 207,208c238,239 < else < handle_error (n, &p->out, p->out == pty, "write"); --- > else if (!handle_error (n, &p->out, p->out == pty, "write")) > return; 212,238d242 < < if (pipes[1].out == -1) < return; < < make_nonblocking (STDOUT_FILENO, false); < for (;;) < { < struct pipe *p = &pipes[1]; < ssize_t n; < < /* Write buffer. */ < while (p->size > 0) < { < n = write (p->out, p->buf + p->ofs, p->size); < if (n < 0) < fail_io ("write"); < else if (n == 0) < fail_io ("zero-length write"); < p->ofs += n; < p->size -= n; < } < p->ofs = 0; < < p->size = n = read (p->in, p->buf, sizeof p->buf); < if (n <= 0) < return; < } src/utils/pintos 2a3,4 > # modified by myunjong! > 116,117d117 < < $kill_on_failure = 0; 623a624 > push (@cmd, '-no-kqemu'); 824c825 < do { print $buf } while sysread ($in, $buf, 4096) > 0; --- > print $buf while sysread ($in, $buf, 4096) > 0; 945a947,948 > > #yeah! modified! src/filesys/inode.c 75c75 < struct inode_disk *disk_inode = NULL; --- > struct inode_disk *inode_disk = NULL; 82c82 < ASSERT (sizeof *disk_inode == BLOCK_SECTOR_SIZE); --- > ASSERT (sizeof *inode_disk == BLOCK_SECTOR_SIZE); 84,85c84,85 < disk_inode = calloc (1, sizeof *disk_inode); < if (disk_inode != NULL) --- > inode_disk = calloc (1, sizeof *inode_disk); > if (inode_disk != NULL) 88,90c88,90 < disk_inode->length = length; < disk_inode->magic = INODE_MAGIC; < if (free_map_allocate (sectors, &disk_inode->start)) --- > inode_disk->length = length; > inode_disk->magic = INODE_MAGIC; > if (free_map_allocate (sectors, &inode_disk->start)) 92c92 < block_write (fs_device, sector, disk_inode); --- > block_write (fs_device, sector, inode_disk); 99c99 < block_write (fs_device, disk_inode->start + i, zeros); --- > block_write (fs_device, inode_disk->start + i, zeros); 103c103 < free (disk_inode); --- > free (inode_disk); src/filesys/fsutil.c 27d26 < dir_close (dir); 39c38 < char *buffer; --- > char *buf; 45c44 < buffer = palloc_get_page (PAL_ASSERT); --- > buf = palloc_get_page (PAL_ASSERT); 49c48 < off_t n = file_read (file, buffer, PGSIZE); --- > off_t n = file_read (file, buf, PGSIZE); 53c52 < hex_dump (pos, buffer, n, true); --- > hex_dump (pos, buf, n, true); 55c54 < palloc_free_page (buffer); --- > palloc_free_page (buf); src/filesys/file.c 71,73c71,73 < off_t bytes_read = inode_read_at (file->inode, buffer, size, file->pos); < file->pos += bytes_read; < return bytes_read; --- > off_t readed_bytes = inode_read_at (file->inode, buffer, size, file->pos); > file->pos += readed_bytes; > return readed_bytes; src/filesys/free-map.c 25,26c25,26 < sectors were available or if the free_map file could not be < written. */ --- > sectors were available or if the free_map file could not be > written. */ src/devices/block.c 169c169 < for (i = 0; i < BLOCK_ROLE_CNT; i++) --- > for (i = 0; i < BLOCK_CNT; i++) src/lib/kernel/list.c 330c330 < struct list_elem *e; --- > struct list_elem *e_; 332,333c332,333 < for (e = list_begin (list); e != list_end (list); e = e->prev) < swap (&e->prev, &e->next); --- > for (e_ = list_begin (list); e_ != list_end (list); e_ = e_->prev) > swap (&e_->prev, &e_->next);
'programming > pintos' 카테고리의 다른 글
핀토스 설치하기 (0) 2018.12.31 핀토스 다시 하기 (0) 2018.12.28 댓글