반응형
Project2 키워드 정리
[정글] Week09-10 PintOS 키워드 정리
Week09-10 PintOS 키워드 정리 User Mode VS Kernel Mode컴퓨터의 프로세서는 실행 중인 코드 유형에 따라 User Mode 와 Kernel Mode 두 가지 모드로 작동한다 어플리케이션은 User Mode 에서 작동하고, 핵심 운영
helloahram.tistory.com
Project2 에서 우리가 해야 할 것
* Read the Executable file from the disk
- Filesystem Issue
* Allocate Memory for the Program to Run
- Virtual Memory Allocation
* Pass the Parameters to the Program
- Set up User Stack
Context Switch to the User Program
* OS should wait for the Program to exit
01-1. process_create_initd()
file_name 을 parsing 해서 맨 앞 토큰을 thread_create() 에 인자를 전달하는 내용을 추가했다
/* Path - userprog/process.c */
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);
/* file_name 을 parsing 해서 맨 앞 토큰을 thread_create() 에 인자 전달 */
char *save_ptr;
strtok_r(file_name, " ", &save_ptr);
/* Create a new thread to execute FILE_NAME. */
tid = thread_create(file_name, PRI_DEFAULT, initd, fn_copy);
if (tid == TID_ERROR)
palloc_free_page(fn_copy);
return tid;
}
01-2. process_exec()
process_cleanup() 해 준 이후에 인자 Parsing 내용 추가
/* Path - userprog/process.c */
int process_exec(void *f_name) { /* 인자 - 실행하려는 이진 파일 이름 */
...
process_cleanup();
/* 인자 Parsing */
char *parse[64];
char *token, *save_ptr;
int count = 0;
for (token = strtok_r(file_name, " ", &save_ptr); token != NULL;
token = strtok_r(NULL, " ", &save_ptr))
parse[count++] = token;
/* And then load the binary */
success = load(file_name, &_if);
...
}
User stack에 parse[] 배열을 전달해서 내용을 적재하는 argument_stack() 함수를 추가하고
process.h 에 함수원형도 추가한다
/* Path - userprog/process.c */
void
argument_stack(char **parse, int count, void **rsp){
for (int i = count - 1; i > -1; i--)
{
for (int j = strlen(parse[i]); j>-1; j--)
{
(*rsp)--;
**(char **)rsp = parse[i][j];
}
parse[i] = *(char **)rsp;
}
int padding = (int)*rsp % 8;
for (int i = 0; i < padding; i++)
{
(*rsp)--;
**(uint8_t **)rsp = 0;
}
(*rsp) -= 8;
**(char ***)rsp = 0;
for (int i = count-1; i>-1; i--)
{
(*rsp) -= 8;
**(char ***)rsp = parse[i];
}
(*rsp) -= 8;
**(void ***)rsp = 0;
}
argument_stack 함수를 process_exec 에 추가한다
반응형
'크래프톤정글 > PintOS' 카테고리의 다른 글
[정글] Week11-12 PintOS 키워드 정리 (1) | 2024.11.23 |
---|---|
[정글] PintOS Project1 #3 Priority Scheduling 2/2 (3) | 2024.11.11 |
[정글] PintOS Project1 #2 Priority Scheduling 1/2 (5) | 2024.11.10 |
[정글] PintOS Project1 #1 Alarm Clock (7) | 2024.11.07 |
[정글] 정글 PintOS 주차 퀴즈 (0) | 2024.11.05 |