Pintos week02 User Programs

과제 4 : Process Termination Messages

목표

‘exit’ 함수 호출이나 다른 이유로 프로세스가 종료될 때 마다 프로세스의 이름과 exit 코드 출력

과정

exit 함수 수정

  • 수정 파일 : userprog/syscall.c

  • 개선 방향

    • 출력하는 코드 추가

정답 코드

1
2
3
4
5
6
void exit(int status){
    struct thread *curr = thread_current();
    curr->exit_status = status;
    printf ("%s: exit(%d)\n", thread_name(), status);
    thread_exit();
}

과제 5 : Denying Writes on Excutables

목표

실행중인 파일에 쓰기를 거부하는 코드 작성

과정

file_deny_write() 함수 작성

  • 수정 파일 : filesys/file.c

  • 개선 방향

    • 파일 구조체 안의 deny_write가 참이 아니라면 참으로 만든다.
    • inode 구조체의 deny_write_cnt도 더해준다.

정답 코드

1
2
3
4
5
6
7
void file_deny_write (struct file *file) {
	ASSERT (file != NULL);
	if (!file->deny_write) {
		file->deny_write = true;
		inode_deny_write (file->inode);
	}
}

file_allow_write() 함수 작성

  • 수정 파일 : filesys/file.c
  • 개선 방향
    • 위와 반대

정답 코드

1
2
3
4
5
6
7
void file_allow_write (struct file *file) {
	ASSERT (file != NULL);
	if (file->deny_write) {
		file->deny_write = false;
		inode_allow_write (file->inode);
	}
}

소감

지옥이였다. 도대체 뭐가 뭔지 파악하는데 한참이나 걸렸다. 괜히 1.5주 짜리 프로젝트가 아니였다. 오히려 짧았다.. 혹시 이 허접한 퀄리티의 글을 보고 도움을 받는 사람이 있다면 매일 매일 기록하는것을 진심으로 추천한다. 오늘 뭘 했는데 뭐가 안됐고 어디가 막혔는지를 파악하는 게 정말 중요했다. 다음 방향이 아니라 내가 지금 어느 위치에 있는지도 까먹어서 힘들었다.. 내가 뭘 모르는지 모르는 게 참 웃기기도 하고..

꼭 다시 한번 복습할 필요성 을 느낀다.

참고 자료

  1. 한양대 Pintos PPT
  2. 카이스트 Pintos PPT
  3. https://github.com/PintOS-secondhalf-team3/pintos_kaist_jungle