int
process_wait (tid_t child_tid UNUSED) {
/* XXX: Hint) The pintos exit if process_wait (initd), we recommend you
* XXX: to add infinite loop here before
* XXX: implementing the process_wait. */
// while (1){
// int data = 1;
// }
struct thread *child = get_child(child_tid);
return -1;
}
process_wait를 구현하려고 보니까 자식 프로세르를 찾아서 pid를 반환해줘야 함.
(gdb) p child_tid
$1 = 3
디버깅해서 보니까 child_tid는 3인 걸 확인.
struct thread *get_child(pid_t pid){
struct thread *cur = thread_current();
// for (struct list_elem *list_begin())
}
(gdb) p pid
$2 = 3
역시 pid는 3.
struct thread {
/* Owned by thread.c. */
tid_t tid; /* Thread identifier. */
enum thread_status status; /* Thread state. */
char name[16]; /* Name (for debugging purposes). */
int priority; /* Priority. */
int64_t weakeup_tick; /* wake up time (깨어나야 할 시간) */
int exit_status;
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */
/* Priority Donation Field */
int init_priority; /* 원래 우선순위 */
struct list donations; /* 이 스레드에게 우선순위를 기부한 스레드의 목록 */
struct list_elem donations_elem; /* 다른 스레드의 donations 리스트에 포함되기 위한 요소 */
struct lock *wait_on_lock; /* 이 스레드가 기다리고 있는 락 */
/* MLFQ */
int niceness;
int recent_cpu;
struct list_elem all_elem; /** project1-Advanced Scheduler */
/* file descripter */
struct file **fdt[64];
int next_fd;
#ifdef USERPROG
/* Owned by userprog/process.c. */
uint64_t *pml4; /* Page map level 4 */
#endif
#ifdef VM
/* Table for whole virtual memory owned by thread. */
struct supplemental_page_table spt;
#endif
/* Owned by thread.c. */
struct intr_frame tf; /* Information for switching */
unsigned magic; /* Detects stack overflow. */
};
그리고 thread구조체에 어떤 값이 들어가는 지 확인하려고 다 찍어봤다.
(gdb) p t->tid
$9 = 1
(gdb) p t->status
$10 = THREAD_RUNNING
(gdb) p t->name
$11 = "main", '\000' <repeats 11 times>
(gdb) p t->priority
$12 = 31
(gdb) p t->exit_status
$13 = 0
(gdb) p t->elem
$14 = {prev = 0x8004227b00 <ready_list>, next = 0x8004227b10 <ready_list+16>}
여기서 내가 생각한 것.
어떻게 pid는 3인데 t->tid는 1이다. 이게 뭘 의미하는 거지??
(gdb) p t->tf
$20 = {R = {r15 = 0, r14 = 0, r13 = 0, r12 = 0, r11 = 0, r10 = 0, r9 = 69246279, r8 = 549822926556,
rsi = 549822922800, rdi = 549825261568, rbp = 549822926336, rdx = 549825265664, rcx = 0,
rbx = 2114560, rax = 0}, es = 16, __pad1 = 0, __pad2 = 0, ds = 16, __pad3 = 0, __pad4 = 0,
vec_no = 0, error_code = 0, rip = 549825051324, cs = 8, __pad5 = 0, __pad6 = 0, eflags = 2097154,
rsp = 549822926288, ss = 16, __pad7 = 0, __pad8 = 0}
여기서 보면 인터럽트 프레임의 값이 다 쓰레기 값으로 저장되어 있음.
struct thread *get_child(pid_t pid){
struct thread *cur = thread_current();
struct thread *t;
struct list_elem *e;
for (e = list_begin(&cur->child_list); e != list_end(&cur->child_list); e = list_next(e)){
t = list_entry(e, struct thread, child_elem);
printf("\n");
}
}
child_list에서 인자로 받은 pid와 같은 스레드를 찾는 과정인 것 같은데...
(gdb) p cur->child_list
$4 = {head = {prev = 0x0, next = 0x0}, tail = {prev = 0x0, next = 0x0}}
// for문 돌기전에 e값
(gdb) p e
$7 = (struct list_elem *) 0x800421bce4 <process_create_initd+155>
(gdb) n
249 t = list_entry(e, struct thread, child_elem);
(gdb) p e
$8 = (struct list_elem *) 0x0
(gdb) n
250 printf("\n");
(gdb) p t
$9 = (struct thread *) 0xfffffffffffffd40
(gdb) n
248 for (e = list_begin(&cur->child_list); e != list_end(&cur->child_list); e = list_next(e)){
(gdb) p e
$10 = (struct list_elem *) 0x0
(gdb) n
Remote connection closed
Kernel PANIC at ../../lib/kernel/list.c:78 in list_next(): assertion `is_head (elem) || is_interior (elem)' failed.
원인은 잘 모르겠지만 돌리다가 터져버림...
Putting 'exec-arg' into the file system...
Executing 'exec-arg':
(exec-arg) begin
(exec-arg) I'm your father
Page fault at 0x404330: not present error reading page in kernel context.
Interrupt 0x0e (#PF Page-Fault Exception) at rip=80042179a0
cr2=0000000000404330 error= 0
rax 0000000000404330 rbx 0000000000000000 rcx 0000000000000039 rdx 00000080042b8a48
rsp 00000080042b89f0 rbp 00000080042b8a10 rsi 00000080042b8a48 rdi 0000000000404330
rip 00000080042179a0 r8 0000000000000000 r9 0000000000000000 r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000206
es: 001b ds: 001b cs: 0008 ss: 0010
Kernel PANIC at ../../userprog/exception.c:97 in kill(): Kernel bug - unexpected interrupt in kernel
Call stack: 0x80042186d4 0x800421cfae 0x800421d12d 0x8004209680 0x8004209a9e 0x800421f40b 0x800421f545 0x800421debb 0x800421c48d 0x800421c04f 0x800421da30 0x800421d38d 0x800421d1a2Page fault at 0x4747ff80: not present error reading page in Kernel PANIC recursion at ../../threads/thread.c:302 in thread_current().
Interrupt 0x0d (#GP General Protection Exception) at rip=80042201cb
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004221a8d rdx 0000000000000025
rsp 00000080042b7fd0 rbp 00000080042b7fe0 rsi 00000000000000c7 rdi cccccccccccccccc
rip 00000080042201cb r8 0000008004221aba r9 00000080042185f9 r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000002
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 000000000000002e
rsp 00000080042b7dc0 rbp 00000080042b7dd0 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000037
rsp 00000080042b7bb0 rbp 00000080042b7bc0 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000000
rsp 00000080042b79a0 rbp 00000080042b79b0 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000009
rsp 00000080042b7790 rbp 00000080042b77a0 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000012
rsp 00000080042b7580 rbp 00000080042b7590 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 000000000000001b
rsp 00000080042b7370 rbp 00000080042b7380 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000024
rsp 00000080042b7160 rbp 00000080042b7170 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 000000000000002d
rsp 00000080042b6f50 rbp 00000080042b6f60 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000036
rsp 00000080042b6d40 rbp 00000080042b6d50 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 000000000000003f
rsp 00000080042b6b30 rbp 00000080042b6b40 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000008
rsp 00000080042b6920 rbp 00000080042b6930 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 0000000000000011
rsp 00000080042b6710 rbp 00000080042b6720 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
Interrupt 0x0d (#GP General Protection Exception) at rip=800421fcb1
cr2=000000004747ff80 error= 0
rax cccccccccccccccc rbx 0000000000000000 rcx 0000008004225b18 rdx 000000000000001a
rsp 00000080042b6500 rbp 00000080042b6510 rsi 000000000000000a rdi cccccccccccccccc
rip 000000800421fcb1 r8 00000080042185f9 r9 000000800421bb4d r10 0000000000000000
r11 0000000000000212 r12 000000800421d2f5 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000086
es: 0010 ds: 0010 cs: 0008 ss: 0010
일단 바로 테스트 돌려봤는데 이렇게 찍힘..
Page fault at 0x404330: not present error reading page in kernel context.
Interrupt 0x0e (#PF Page-Fault Exception) at rip=80042179a0
??
int exec(const char *cmd_line){
int process_fail = process_exec(cmd_line);
if (process_fail < 0){
return -1;
}
}
일단 이렇게 하고 진행해봄
(gdb) p buffer[0]
$5 = 0x404330 "child-args"
(gdb) p buffer[1]
$6 = 0x40433b "childarg"
버퍼에 파싱돼서 저장되는 거 확인
하지만 file을 파싱해서 넣었는데 load에서 문제가 발생함.
(gdb) p _if
$8 = {R = {r15 = 549825282048, r14 = 549825285152,
r13 = 549825182464, r12 = 549825285184,
r11 = 549825122637, r10 = 549825285184,
r9 = 549825182464, r8 = 575, rsi = 549822922800,
rdi = 549825285216, rbp = 6, rdx = 549825285248,
rcx = 549822923480, rbx = 549825285280,
rax = 549825051324}, es = 27, __pad1 = 0, __pad2 = 0,
ds = 27, __pad3 = 1024, __pad4 = 128,
vec_no = 549825285280, error_code = 549825285232,
rip = 549822923480, cs = 35, __pad5 = 0, __pad6 = 0,
eflags = 514, rsp = 253403070470, ss = 27, __pad7 = 1060,
__pad8 = 128}
왜 전부 쓰레기 값으로 채워져 있는거지??
아니 rsp 값이 이런 값이 들어가는데??
이거 왜 이런거지?? 완전 쓰레기 값이잖아??
(gdb) p file_name
$1 = 0x800423f000 "exec-arg"
(gdb) p _if
$2 = {R = {r15 = 0, r14 = 0, r13 = 0, r12 = 0, r11 = 0, r10 = 0, r9 = 0, r8 = 0, rsi = 0, rdi = 0,
rbp = 0, rdx = 0, rcx = 0, rbx = 0, rax = 0}, es = 27, __pad1 = 0, __pad2 = 0, ds = 27,
__pad3 = 0, __pad4 = 0, vec_no = 0, error_code = 0, rip = 0, cs = 35, __pad5 = 0, __pad6 = 0,
eflags = 0, rsp = 0, ss = 27, __pad7 = 0, __pad8 = 0}
이거는 load()함수가 동작될 때의 _if 값을 출력해 봤음…
int exec(const char *cmd_line){
char *copy = palloc_get_page(PAL_ZERO);
strlcpy(copy, cmd_line, PGSIZE);
int process_fail = process_exec(copy);
if (process_fail < 0){
return -1;
}
}
이렇게 코드를 수정한 결과
Putting 'exec-arg' into the file system...
Executing 'exec-arg':
(exec-arg) begin
(exec-arg) I'm your father
load: child-args: open failed
Page fault at 0x4033b4: not present error reading page in user context.
exec-arg: dying due to interrupt 0x0e (#PF Page-Fault Exception).
Interrupt 0x0e (#PF Page-Fault Exception) at rip=4033b4
cr2=00000000004033b4 error= 4
rax ffffffffffffffff rbx 0000000000000000 rcx 00000000004033b4 rdx 0000000000000000
rsp 000000004747ff38 rbp 000000004747ff80 rsi 0000000000000000 rdi 0000000000404330
rip 00000000004033b4 r8 0000000000000000 r9 0000000000000000 r10 0000000000000000
r11 0000000000000212 r12 0000000000000000 r13 0000000000000000 r14 0000000000000000
r15 0000000000000000 rflags 00000212
es: 001b ds: 001b cs: 0023 ss: 001b
위와 같은 오류가 발생
load: child-args: open failed????????
왜??
file_name 정상적으로 들어가는 거 봤는데...
하지만 여전히 _if.rsp 값에 쓰레기 주소가 들어가 있었음... 이제 어떻게 해야 될까?