Usertext

일단 생각없이 user- 폴더가서 make test를 해봤다. 싹 다 박살이나있더라

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Kernel command line: -f -q
Kernel PANIC at ../../threads/vaddr.h:84 in vtop(): assertion `is_kernel_vaddr (vaddr)' failed.
Call stack: 0xc0028a4c 0xc002b2df 0xc002a960 0xc0020cdc 0xc00210e5 0xc0021172 0xc0022c8b 0xc0022f53 0xc002145d 0xc00217a2 0xc00205aa.
The `backtrace' program can make call stacks useful.
Read "Backtraces" in the "Debugging Tools" chapter
of the Pintos documentation for more information.
Timer: 0 ticks
Thread: 0 idle ticks, 0 kernel ticks, 0 user ticks
Console: 477 characters output
Keyboard: 0 keys pressed
Exception: 0 page faults
Powering off...
========================================================================
Bochs is exiting with the following message:
[UNMAP ] Shutdown port: shutdown requested
========================================================================

치우고 개요,명세부터 읽으러갔다. 고통.

  1. 처음으로 해줄거는 utils에서 pintosPintos.pm 파일에서 처음 안되면서 수정해주었던 절대경로들을 userprog/build/filename으로 싹 수정해주는 것이다. thread 폴더 내의 build는 f 옵션자체가 지원이 안된다

  2. 절대경로대신에 예전 경로로 바꿔주고 kernel, loader가 존재하는 build 폴더에서 실행하면 딱히 문제가 없다.

아무튼 물론 그럼에도 테스트는 싹다 박살이 나있다.

1
2
3
4
5
6
7
8
9
10
11
12
euns@DESKTOP-6VB35LS:~/pintos/userprog/build$ backtrace kernel.o Call stack: 0xc0028a4c 0xc002b2df 0xc002a960 0xc0020cdc 0xc00210e5 0xc0021172 0xc0022c8b 0xc0022f53 0xc002145d 0xc00217a2 0xc00205aa.
0xc0028a4c: debug_panic (.../../lib/kernel/debug.c:38)
0xc002b2df: pagedir_activate (...../userprog/pagedir.c:230)
0xc002a960: process_activate (...../userprog/process.c:132)
0xc0020cdc: thread_schedule_tail (..../../threads/thread.c:709)
0xc00210e5: schedule (..../../threads/thread.c:738)
0xc0021172: thread_yield (..../../threads/thread.c:398)
0xc0022c8b: sema_up (...../../threads/synch.c:126)
0xc0022f53: lock_release (...../../threads/synch.c:265)
0xc002145d: allocate_tid (..../../threads/thread.c:752)
0xc00217a2: thread_init (..../../threads/thread.c:107)
0xc00205aa: main (...d/../../threads/init.c:91)

다른방법으로 해결하려다가 결국 아래의 방법을 그대로 가져와서 적용하니 해결됐 다.

stackoverflow

system call

1 . lib/user/syscall.h.에 대충 구현이 되어있다고 한다.

  1. lib/syscall-nr.h에 시스템 콜 숫자가 정의되어있다고 한다. enum값이니 그냥 숫자 상관없이 그대로 써도 상관없을듯하다.
  2. To implement syscalls, you need to provide ways to read and write data in user virtual address space.
  3. an invalid pointer, a pointer into kernel memory, or a block partially in one of those regions : terminating the user process < 먼저 구현할것.
  4. lib/user/syscall.c의 각 시스템 호출에 대해 사용자 수준 기능을 제공했습니다.
  5. In the 80x86 architecture, the int instruction is the most commonly used means for invoking system calls. This instruction is handled in the same way as other software exceptions. In Pintos, user programs invoke int $0x30 to make a system call.
  6. Thus, when the system call handler syscall_handler() gets control, the system call number is in the 32-bit word at the caller’s stack pointer, the first argument is in the 32-bit word at the next higher address, and so on. The caller’s stack pointer is accessible to syscall_handler() as the esp member of the struct intr_frame passed to it.
  7. The 80x86 convention for function return values is to place them in the EAX register. System calls that return a value can do so by modifying the eax member of struct intr_frame.

대충 나열된 함수들을 구현하면 될것같다. 그이전에 구현할 함수들이 어디서부터 불러오는지 알아봐야할것같다,

일단 lib/user/syscall.h의 코드를 봤다.

매크로 syscall 의 코드가 잘 이해가지않았다.

1
2
3
4
5
    asm volatile                                          \
            ("pushl %[number]; int $0x30; addl $4, %%esp"       \
               : "=a" (retval)                                  \
               : [number] "i" (NUMBER)                          \
               : "memory");  

아무래도 asm 보는 법을 익혀야할거같다.. 이 site를 참고했다

$0x30 이 이해가 잘 가지않았다. intsection 3.5.2에 설명이 나와있었다. (못보고 지나쳐서 직접 구글링해서 알아냈다.)

0x30syscall_init 에서 또 등장했다. intr_register_int 의 주석을 읽으면 완전히 이해 할수있었다. 0x30syscall_handler와 동일하다고 보면 될것같다.

그럼 syscall_handler에서 각 함수를 호출하는 식으로 하면 될거같다. enum이 있으니 switch문이 적당해 보인다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
FAIL tests/filesys/base/syn-write
Run didn't produce any output
FAIL tests/userprog/args-none
FAIL tests/userprog/args-single
FAIL tests/userprog/args-multiple
FAIL tests/userprog/args-many
FAIL tests/userprog/args-dbl-space
FAIL tests/userprog/sc-bad-sp
FAIL tests/userprog/sc-bad-arg
FAIL tests/userprog/sc-boundary
FAIL tests/userprog/sc-boundary-2
FAIL tests/userprog/halt
FAIL tests/userprog/exit
FAIL tests/userprog/create-normal
FAIL tests/userprog/create-empty
FAIL tests/userprog/create-null
FAIL tests/userprog/create-bad-ptr
FAIL tests/userprog/create-long
FAIL tests/userprog/create-exists
FAIL tests/userprog/create-bound
FAIL tests/userprog/open-normal
FAIL tests/userprog/open-missing
FAIL tests/userprog/open-boundary
FAIL tests/userprog/open-empty
FAIL tests/userprog/open-null
FAIL tests/userprog/open-bad-ptr
FAIL tests/userprog/open-twice
FAIL tests/userprog/close-normal
FAIL tests/userprog/close-twice
FAIL tests/userprog/close-stdin
FAIL tests/userprog/close-stdout
FAIL tests/userprog/close-bad-fd
FAIL tests/userprog/read-normal
FAIL tests/userprog/read-bad-ptr
FAIL tests/userprog/read-boundary
FAIL tests/userprog/read-zero
FAIL tests/userprog/read-stdout
FAIL tests/userprog/read-bad-fd
FAIL tests/userprog/write-normal
FAIL tests/userprog/write-bad-ptr
FAIL tests/userprog/write-boundary
FAIL tests/userprog/write-zero
FAIL tests/userprog/write-stdin
FAIL tests/userprog/write-bad-fd
FAIL tests/userprog/exec-once
FAIL tests/userprog/exec-arg
FAIL tests/userprog/exec-multiple
FAIL tests/userprog/exec-missing
FAIL tests/userprog/exec-bad-ptr
FAIL tests/userprog/wait-simple
FAIL tests/userprog/wait-twice
FAIL tests/userprog/wait-killed
FAIL tests/userprog/wait-bad-pid
FAIL tests/userprog/multi-recurse
FAIL tests/userprog/multi-child-fd
FAIL tests/userprog/rox-simple
FAIL tests/userprog/rox-child
FAIL tests/userprog/rox-multichild
FAIL tests/userprog/bad-read
FAIL tests/userprog/bad-write
FAIL tests/userprog/bad-read2
FAIL tests/userprog/bad-write2
FAIL tests/userprog/bad-jump
FAIL tests/userprog/bad-jump2
FAIL tests/userprog/no-vm/multi-oom
FAIL tests/filesys/base/lg-create
FAIL tests/filesys/base/lg-full
FAIL tests/filesys/base/lg-random
FAIL tests/filesys/base/lg-seq-block
FAIL tests/filesys/base/lg-seq-random
FAIL tests/filesys/base/sm-create
FAIL tests/filesys/base/sm-full
FAIL tests/filesys/base/sm-random
FAIL tests/filesys/base/sm-seq-block
FAIL tests/filesys/base/sm-seq-random
FAIL tests/filesys/base/syn-read
FAIL tests/filesys/base/syn-remove
FAIL tests/filesys/base/syn-write
Posted 2021-03-09