-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: os_concepts system_call.md add
- Loading branch information
yshyeonn
committed
Nov 30, 2024
1 parent
ec4c698
commit ac27217
Showing
2 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
# π [System Call] | ||
|
||
## 1. **κ°λ μμ½** | ||
|
||
System Callμ΄λ μ¬μ©μκ° μ»€λμμμμ νμν μνμ νκΈ° μν΄ μ μ μμμμ μ¬μ©νλ νλ‘κ·Έλλ° μΈν°νμ΄μ€μ΄λ€. | ||
|
||
--- | ||
|
||
## 2. **μΈλΆ μ€λͺ ** | ||
|
||
System Call | ||
- μ¬μ©μκ° μ§μ μ¬μ©νμ§ λͺ»νλ 컀λ κΈ°λ₯λ€μ μ¬μ©ν μ μλ€. | ||
- System Callμ νΈμΆνλ κ³³μ User Space, μνλλ κ³³μ Kernel Space μ΄λ€. | ||
- νΈμΆνλ κ³³κ³Ό μνλλ κ³³μ μμμ΄ λ€λ₯΄κΈ° λλ¬Έμ, μ κ·Όν μ μλ μ£Όμμ μμ λν μ νλμ΄ μλ€. | ||
a. System Callμ νΈμΆνλ κ³³ -> User Space Memory | ||
b. System Callμ΄ μνλλ κ³³ -> User, Kernel Space Memory | ||
|
||
|
||
System callμ΄ μ€μ 리λ μ€μμ μνλλ κ³Όμ μ λ€μκ³Ό κ°λ€. | ||
|
||
1. User taskμμμ System Call ν¨μ νΈμΆ | ||
2. IDT(Interrupt Descriptor Table)μ 0x80 offsetμ system call κ΄λ ¨ Interrupt λ°μ (Trap Instruction) | ||
3. Trapμ μ²λ¦¬νκΈ° μν΄ handlerλ μννκ³ μ νλ system call λ²νΈλ₯Ό sys_call_tableμμ μ°Ύμ λ€ Kernel μμμ ν¨μλ₯Ό νΈμΆνλ€. | ||
4. ν¨μ κ²°κ³Όκ°μ User Processλ‘ return νλ€. | ||
|
||
--- | ||
|
||
## 3. **κ΄λ ¨ μ½λ** | ||
|
||
[μ΄ κ°λ κ³Ό κ΄λ ¨λ μ½λ μμΉλ ꡬν λ°©λ²μ μ€λͺ ν©λλ€.] | ||
|
||
- νμΌ μμΉ: `src/threads/[νμΌλͺ ]` | ||
- μ£Όμ ν¨μ: | ||
- `function_name()`: [ν¨μμ μν λ° κ°λ¨ν μ€λͺ ] | ||
- `function_name_2()`: [ν¨μμ μν λ° κ°λ¨ν μ€λͺ ] | ||
|
||
- νμΌ μμΉ: `src/lib/syscall_nr.h` | ||
- system call number λ₯Ό μ μν κ³³ | ||
|
||
- νμΌ μμΉ: `src/lib/user/syscall.c` | ||
- `define syscall#(NUMBER, ...)`: μ΄μ λΈλ¦¬μ CμΈμ΄λ‘ μμ± λ system callμ μννλ 맀ν¬λ‘ | ||
- `void halt(void){syscall0(...)}, void exit(int status){syscall1(...)}`: μΈμ κ°μμ μ©λμ λ§κ² 맀ν¬λ‘ syscall#μ νμ©νμ¬ system callμ μννλλ‘ μ μν΄λμ ν¨μ | ||
|
||
- νμΌ μμΉ: `src/userprog/syscall.c` | ||
- μ£Όμ ν¨μ: | ||
- `syscall_init` | ||
|
||
|
||
μ: | ||
|
||
```c | ||
/* threads/thread.c */ | ||
/* μ€λ λλ₯Ό μ΄κΈ°ννλ ν¨μ */ | ||
void initialize_thread(struct thread *t, const char *name, int priority) { | ||
ASSERT(t != NULL); | ||
ASSERT(name != NULL); | ||
t->priority = priority; | ||
/* Additional initialization code here */ | ||
} | ||
``` | ||
--- | ||
## 4. **Pintosμμμ μν ** | ||
[ν΄λΉ κ°λ μ΄ Pintosμμ μ΄λ»κ² μ¬μ©λκ³ , ꡬν μ μ΄λ€ λΆλΆμμ μ€μν μν μ νλμ§ μμ±ν©λλ€.] | ||
μ: | ||
- **μ€λ λ κ΄λ¦¬**: | ||
- μ€λ λλ Pintosμμ κΈ°λ³Έ μ€ν λ¨μλ‘, CPU μ€μΌμ€λ§ λ° λκΈ°νμ μ£Όμ λμμ λλ€. | ||
- μ€λ λμ μν(ready, running, blocked)λ CPU μ€μΌμ€λ§μ μν₯μ μ€λλ€. | ||
--- | ||
## 5. **μ΄ν΄λ₯Ό λλ μμ ** | ||
[κ°λ μ μ΄ν΄νλ λ° λμμ΄ λλ κ°λ¨ν μ½λ μμ λ μλ리μ€λ₯Ό μμ±ν©λλ€.] | ||
μ: | ||
```c | ||
/* μ€λ λ μμ±κ³Ό μ€ν */ | ||
struct thread *t = thread_create("worker", PRI_DEFAULT, worker_function, NULL); | ||
/* μμ±λ μ€λ λ μ€ν */ | ||
thread_unblock(t); | ||
``` | ||
|
||
--- | ||
|
||
## 6. **μ£Όμ ꡬν λ¨κ³** | ||
|
||
[μ΄ κ°λ μ ꡬννκΈ° μν΄ νμν λ¨κ³ λ° μ κ·Ό λ°©μμ λμ΄ν©λλ€.] | ||
|
||
1. [λ¨κ³ 1: μ€λͺ ] | ||
2. [λ¨κ³ 2: μ€λͺ ] | ||
3. [λ¨κ³ 3: μ€λͺ ] | ||
|
||
--- | ||
|
||
## 7. **κ΄λ ¨ κ°λ ** | ||
|
||
[μ΄ κ°λ κ³Ό κ΄λ ¨λ λ€λ₯Έ κ°λ μ΄λ ꡬν μμλ₯Ό λ§ν¬νκ±°λ κ°λ¨ν μ€λͺ ν©λλ€.] | ||
|
||
- [κ΄λ ¨ κ°λ 1] | ||
- [κ΄λ ¨ κ°λ 2] | ||
|
||
μ: | ||
|
||
- **μ€μΌμ€λ§(Scheduling)**: μ€λ λμ μ€ν μμλ₯Ό κ²°μ νλ μκ³ λ¦¬μ¦. κΈ°λ³Έ μκ³ λ¦¬μ¦μ `priority scheduling`μ λλ€. | ||
|
||
--- | ||
|
||
## 8. **μ°Έκ³ μλ£** | ||
|
||
λ³΄κ³ μ μ°Έκ³ μλ£ | ||
- [νν μ€_νμλ.pdf] | ||
- [Trap] (https://autumnrain.tistory.com/entry/Kernel-Trap-%ED%8A%B8%EB%9E%A9) | ||
|
||
|
||
[νμλ€μ΄ λ κΉμ΄ μ΄ν΄ν μ μλλ‘ μ°Έκ³ ν μλ£(λ¬Έμ, λ§ν¬ λ±)λ₯Ό μ 곡νμΈμ.] | ||
|
||
- [Pintos 곡μ λ¬Έμ](http://web.stanford.edu/class/cs140/projects/pintos/pintos_1.html) | ||
- [Operating Systems: Three Easy Pieces](https://pages.cs.wisc.edu/~remzi/OSTEP/) | ||
|
||
--- |