2-1. Systemcall 구현 중 (2/13)
오늘은 Argument Passing 을 빨리 마무리 할 수 있어서 Systemcall 까지 시작할 수 있었다. 그 과정에서 애 먹었던 문제가 하나 있었다.
마지막 exit
에 호출된 파일 이름을 보면, 파싱해준 이름이 아닌 원래의 파일 이름과 인자 값이 그대로 들어가 있는 형태이다.
이 프로세스를 create
및 init
하는 과정에서, file_name 을 그대로 사용하는 것이 문제였다.
따라서 다음과 같이 const char
로 된 file_name 에서 실제 파일만 분리하는 과정이 필요했다.
tid_t
process_create_initd (const char *file_name) {
char *fn_copy;
tid_t tid;
/* Make a copy of FILE_NAME.
* Otherwise there's a race between the caller and load(). */
fn_copy = palloc_get_page (0);
if (fn_copy == NULL)
return TID_ERROR;
strlcpy (fn_copy, file_name, PGSIZE);
/* Project 2 - Syscall */
char *save_ptr; // 추가된 코드
char *f_name = strtok_r ((char *)file_name, " ", &save_ptr); // 추가된 코드
/* Create a new thread to execute FILE_NAME. */
tid = thread_create (f_name, PRI_DEFAULT, initd, fn_copy); // create 할 때 인자를 파싱한 이름으로 변경
if (tid == TID_ERROR)
palloc_free_page (fn_copy);
return tid;
}