-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[closes #354, #258] myproc()의 사용을 줄이고, usertrap()에서 syscall 함수로 proc전달 #385
Conversation
d959e9f
to
10319cf
Compare
60a9ac5
to
e477acf
Compare
kernel-rs/src/proc.rs
Outdated
} | ||
|
||
impl DerefMut for CurrentProc { | ||
fn deref_mut(&mut self) -> &mut Self::Target { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래는 아까 오프라인 미팅에서 말씀드린 내용입니다.
Lines 946 to 953 in f06956c
for p in &kernel().procs.process_pool { | |
let mut guard = p.lock(); | |
if guard.deref_info().state == Procstate::RUNNABLE { | |
// Switch to chosen process. It is the process's job | |
// to release its lock and then reacquire it | |
// before jumping back to us. | |
guard.deref_mut_info().state = Procstate::RUNNING; | |
unsafe { (*c).proc = p as *const _ as *mut _ }; |
Cpu
의 proc
이 *mut Proc
인데, schedule
에서 &Proc
을 *mut Proc
으로 변환하여 proc
에 저장하고 있습니다. &T
를 *mut T
로 변환한 다음, 값을 쓰거나 &mut T
로 변환하면 UB이기 때문에 현재 구현에 다소 문제가 있어 보입니다. Cpu
의 proc
을 *const Proc
으로 바꾸고 Proc
은 항상 &mut Proc
대신 &Proc
으로만 사용되게 해야 할 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*const Proc
으로 사용하기 위해 다음과 같은 변경사항을 적용했습니다.
Cpu.proc
,ProcessSystem.initial_proc
,Proc.parent
에서*mut Proc
대신*const Proc
사용CurrentProc
에서*const Proc
사용 (NonNull
은 *mut T를 받기 때문에 사용하지 않았습니다.)CurrentProc
,Proc
의DerefMut
대신Proc
에deref_mut_data()
구현Proc.name
을ProcData
의 field로 이동 (exec에서 디버깅을 위해&mut p.name
을 사용하는데, 이때Proc
이 mutable 하게 참조되기 때문입니다. )
Lines 188 to 193 in 551a6b1
let p_name = &mut p.name; let len = cmp::min(p_name.len(), name.len()); p_name[..len].copy_from_slice(&name[..len]); if len < p_name.len() { p_name[len] = 0; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 반영했습니다 :)
CurrentProc
,Proc
에Deref
구현 추가CurentProc
에 lifetime 추가myproc()
대신CurrentProc
이Option
리턴Cpu.proc
,ProcessSystem.initial_proc
,Proc.parent
에서*mut Proc
대신*const Proc
사용 (관련해서 구체적인 내용은 아래 코멘트에 있습니다.)
kernel-rs/src/proc.rs
Outdated
} | ||
|
||
impl DerefMut for CurrentProc { | ||
fn deref_mut(&mut self) -> &mut Self::Target { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*const Proc
으로 사용하기 위해 다음과 같은 변경사항을 적용했습니다.
Cpu.proc
,ProcessSystem.initial_proc
,Proc.parent
에서*mut Proc
대신*const Proc
사용CurrentProc
에서*const Proc
사용 (NonNull
은 *mut T를 받기 때문에 사용하지 않았습니다.)CurrentProc
,Proc
의DerefMut
대신Proc
에deref_mut_data()
구현Proc.name
을ProcData
의 field로 이동 (exec에서 디버깅을 위해&mut p.name
을 사용하는데, 이때Proc
이 mutable 하게 참조되기 때문입니다. )
Lines 188 to 193 in 551a6b1
let p_name = &mut p.name; let len = cmp::min(p_name.len(), name.len()); p_name[..len].copy_from_slice(&name[..len]); if len < p_name.len() { p_name[len] = 0; }
kernel-rs/src/proc.rs
Outdated
pub fn current_proc(&self) -> Option<CurrentProc<'_>> { | ||
unsafe { push_off() }; | ||
let c = self.mycpu(); | ||
let p = unsafe { (*c).proc }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CurrentProc
의 lifetime에 대한 invariant를 보장할 수 있도록 (*c).proc
이 nonnull이면 &self
의 lifetime 동안 살아있다는 설명이 추가되어야 할 것 같습니다. 이를 위해서는 Kernel
의 invariant로 cpus
안에 있는 proc
들의 lifetime에 대한 조건이 기술되어야 할 것으로 보입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8cc4aab
반영했습니다. 제가 맞게 이해한 것인지 궁금합니다. @Medowhill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코멘트 반영을 완료했습니다. (commit이 많은 것 같아서 코멘트에 해당하는 commit을 기록했습니다.)
주요 변경점입니다.
- syscall관련 함수들은 모두
CurrentProc
을 input으로 받아서 사용합니다. CurrentProc
과 관련된 safety invarient를 추가했습니다.&mut Proc
대신&Proc
을 사용하도록 수정했습니다.- 추가적으로
Proc
과ProcGuard
에서Deref
를 사용할 수 있는 일부 코드를 수정했습니다.
kernel-rs/src/proc.rs
Outdated
pub fn current_proc(&self) -> Option<CurrentProc<'_>> { | ||
unsafe { push_off() }; | ||
let c = self.mycpu(); | ||
let p = unsafe { (*c).proc }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8cc4aab
반영했습니다. 제가 맞게 이해한 것인지 궁금합니다. @Medowhill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굉장히 잘 해주셨습니다. 감사합니다.
마이너한 코멘트 몇개 더 남깁니다.
@@ -453,12 +499,6 @@ impl Deref for ProcGuard { | |||
} | |||
} | |||
|
|||
impl DerefMut for ProcGuard { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 지워진 까닭은?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DerefMut
이 &mut Proc
을 리턴하기 때문에 지웠습니다.
관련된 재민님의 코멘트입니다.
#385 (comment)
#385 (comment)
kernel-rs/src/proc.rs
Outdated
/// `inner` is current Cpu's proc, this means it's state is `RUNNING`. | ||
/// `Proc` lives during lifetime `'p`. | ||
pub struct CurrentProc<'p> { | ||
inner: *const Proc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위의 invariant가 의미하는 것이 결국 inner
가 'p
동안 유효한 Proc
을 가리킨다는 것이니, 지금처럼 inner: *const Proc
으로 raw pointer를 사용하기보다는 그냥 inner: &'p Proc
으로 해도 되지 않을까 싶습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 반영했습니다 :)
주요 변경점입니다.
CurrentProc
이*const Proc
대신&'p Proc
을inner
로 가집니다.- 코멘트주신 내용을 반영하여 invariant 관련 주석을 수정했습니다.
CurrentProc
이Proc
의 포인터를 가지지 않기 때문에non-null pointer
와 관련된 주석은 삭제했습니다.
@@ -453,12 +499,6 @@ impl Deref for ProcGuard { | |||
} | |||
} | |||
|
|||
impl DerefMut for ProcGuard { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DerefMut
이 &mut Proc
을 리턴하기 때문에 지웠습니다.
관련된 재민님의 코멘트입니다.
#385 (comment)
#385 (comment)
kernel-rs/src/proc.rs
Outdated
/// `inner` is current Cpu's proc, this means it's state is `RUNNING`. | ||
/// `Proc` lives during lifetime `'p`. | ||
pub struct CurrentProc<'p> { | ||
inner: *const Proc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2a0cd19
to
78e8a8e
Compare
bors retry |
bors r+ |
Build succeeded: |
주요 변경사항입니다.
myproc()
을Kernel
의 메소드로 이동struct ExecutingProc
추가:*mut Proc
을 감싸는 structkernel().myexproc()
추가:myproc()
에서Proc
이 존재함을 확인하고ExecutingProc
을 리턴usertrap()
에서 sys_* 함수들에ExecutingProc
을 전달myproc()
의 사용을 모두myexproc()
으로 수정했습니다.