Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
1493ec94
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1493ec94
编写于
9月 30, 2021
作者:
Y
Yifan Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stage1 clear! All applications work but now they are based on threads.
上级
c599a31d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
21 addition
and
22 deletion
+21
-22
os/src/console.rs
os/src/console.rs
+2
-2
os/src/task/id.rs
os/src/task/id.rs
+11
-6
os/src/task/manager.rs
os/src/task/manager.rs
+1
-1
os/src/task/mod.rs
os/src/task/mod.rs
+3
-3
os/src/task/process.rs
os/src/task/process.rs
+2
-4
os/src/task/task.rs
os/src/task/task.rs
+1
-1
os/src/trap/mod.rs
os/src/trap/mod.rs
+0
-4
user/src/lib.rs
user/src/lib.rs
+1
-1
未找到文件。
os/src/console.rs
浏览文件 @
1493ec94
...
...
@@ -19,14 +19,14 @@ pub fn print(args: fmt::Arguments) {
#[macro_export]
macro_rules!
print
{
(
$fmt
:
literal
$
(,
$
(
$arg
:
tt
)
+
)
?
)
=>
{
$crate
::
console
::
print
(
format_args!
(
$fmt
$
(,
$
(
$arg
)
+
)
?
))
;
$crate
::
console
::
print
(
format_args!
(
$fmt
$
(,
$
(
$arg
)
+
)
?
))
}
}
#[macro_export]
macro_rules!
println
{
(
$fmt
:
literal
$
(,
$
(
$arg
:
tt
)
+
)
?
)
=>
{
$crate
::
console
::
print
(
format_args!
(
concat!
(
$fmt
,
"
\n
"
)
$
(,
$
(
$arg
)
+
)
?
))
;
$crate
::
console
::
print
(
format_args!
(
concat!
(
$fmt
,
"
\n
"
)
$
(,
$
(
$arg
)
+
)
?
))
}
}
...
...
os/src/task/id.rs
浏览文件 @
1493ec94
...
...
@@ -163,15 +163,9 @@ impl TaskUserRes {
);
}
pub
fn
dealloc_tid
(
&
self
)
{
let
mut
process
=
self
.process
.inner_exclusive_access
();
process
.dealloc_tid
(
self
.tid
);
}
fn
dealloc_user_res
(
&
self
)
{
// dealloc tid
let
mut
process
=
self
.process
.inner_exclusive_access
();
process
.dealloc_tid
(
self
.tid
);
// dealloc ustack manually
let
ustack_bottom_va
:
VirtAddr
=
ustack_bottom_from_tid
(
self
.ustack_base
,
self
.tid
)
.into
();
process
.memory_set
.remove_area_with_start_vpn
(
ustack_bottom_va
.into
());
...
...
@@ -180,6 +174,16 @@ impl TaskUserRes {
process
.memory_set
.remove_area_with_start_vpn
(
trap_cx_bottom_va
.into
());
}
#[allow(unused)]
pub
fn
alloc_tid
(
&
mut
self
)
{
self
.tid
=
self
.process
.inner_exclusive_access
()
.alloc_tid
();
}
pub
fn
dealloc_tid
(
&
self
)
{
let
mut
process
=
self
.process
.inner_exclusive_access
();
process
.dealloc_tid
(
self
.tid
);
}
pub
fn
trap_cx_user_va
(
&
self
)
->
usize
{
trap_cx_bottom_from_tid
(
self
.tid
)
}
...
...
@@ -202,6 +206,7 @@ impl TaskUserRes {
impl
Drop
for
TaskUserRes
{
fn
drop
(
&
mut
self
)
{
self
.dealloc_tid
();
self
.dealloc_user_res
();
// kstack can also be deallocated automatically
}
...
...
os/src/task/manager.rs
浏览文件 @
1493ec94
...
...
@@ -33,4 +33,4 @@ pub fn add_task(task: Arc<TaskControlBlock>) {
pub
fn
fetch_task
()
->
Option
<
Arc
<
TaskControlBlock
>>
{
TASK_MANAGER
.exclusive_access
()
.fetch
()
}
\ No newline at end of file
}
os/src/task/mod.rs
浏览文件 @
1493ec94
...
...
@@ -55,7 +55,7 @@ pub fn suspend_current_and_run_next() {
pub
fn
exit_current_and_run_next
(
exit_code
:
i32
)
{
// take from Processor
let
task
=
take_current_task
()
.unwrap
();
let
task_exit_code
=
task
.inner_exclusive_access
()
.
exit_code
;
task
.inner_exclusive_access
()
.exit_code
=
exit_code
;
let
tid
=
task
.inner_exclusive_access
()
.res.tid
;
// remove thread
let
process
=
task
.process
.upgrade
()
.unwrap
();
...
...
@@ -66,7 +66,7 @@ pub fn exit_current_and_run_next(exit_code: i32) {
// mark this process as a zombie process
process_inner
.is_zombie
=
true
;
// record exit code of main process
process_inner
.exit_code
=
task_
exit_code
;
process_inner
.exit_code
=
exit_code
;
{
// move all child processes under init process
...
...
@@ -99,5 +99,5 @@ lazy_static! {
}
pub
fn
add_initproc
()
{
let
initproc
=
INITPROC
.clone
();
let
_
initproc
=
INITPROC
.clone
();
}
os/src/task/process.rs
浏览文件 @
1493ec94
...
...
@@ -3,8 +3,6 @@ use crate::mm::{
KERNEL_SPACE
,
translated_refmut
,
};
use
crate
::
task
::
TaskContext
;
use
crate
::
task
::
id
::
TaskUserRes
;
use
crate
::
trap
::{
TrapContext
,
trap_handler
};
use
crate
::
sync
::
UPSafeCell
;
use
core
::
cell
::
RefMut
;
...
...
@@ -37,6 +35,7 @@ pub struct ProcessControlBlockInner {
}
impl
ProcessControlBlockInner
{
#[allow(unused)]
pub
fn
get_user_token
(
&
self
)
->
usize
{
self
.memory_set
.token
()
}
...
...
@@ -138,9 +137,9 @@ impl ProcessControlBlock {
// since memory_set has been changed
let
task
=
self
.inner_exclusive_access
()
.get_task
(
0
);
let
mut
task_inner
=
task
.inner_exclusive_access
();
task_inner
.res
.dealloc_tid
();
task_inner
.res.ustack_base
=
ustack_base
;
task_inner
.res
.alloc_user_res
();
task_inner
.trap_cx_ppn
=
task_inner
.res
.trap_cx_ppn
();
// push arguments on user stack
let
mut
user_sp
=
task_inner
.res
.ustack_top
();
user_sp
-=
(
args
.len
()
+
1
)
*
core
::
mem
::
size_of
::
<
usize
>
();
...
...
@@ -177,7 +176,6 @@ impl ProcessControlBlock {
trap_cx
.x
[
10
]
=
args
.len
();
trap_cx
.x
[
11
]
=
argv_base
;
*
task_inner
.get_trap_cx
()
=
trap_cx
;
task_inner
.task_cx
=
TaskContext
::
goto_trap_return
(
task_inner
.res
.kstack_top
());
}
/// Only support processes with a single thread.
...
...
os/src/task/task.rs
浏览文件 @
1493ec94
...
...
@@ -41,7 +41,7 @@ impl TaskControlBlockInner {
self
.trap_cx_ppn
.get_mut
()
}
#[allow(unused)]
fn
get_status
(
&
self
)
->
TaskStatus
{
self
.task_status
}
...
...
os/src/trap/mod.rs
浏览文件 @
1493ec94
...
...
@@ -47,7 +47,6 @@ pub fn enable_timer_interrupt() {
#[no_mangle]
pub
fn
trap_handler
()
->
!
{
println!
(
"into trap!"
);
set_kernel_trap_entry
();
let
scause
=
scause
::
read
();
let
stval
=
stval
::
read
();
...
...
@@ -55,7 +54,6 @@ pub fn trap_handler() -> ! {
Trap
::
Exception
(
Exception
::
UserEnvCall
)
=>
{
// jump to next instruction anyway
let
mut
cx
=
current_trap_cx
();
println!
(
"syscall #{}"
,
cx
.x
[
17
]);
cx
.sepc
+=
4
;
// get system call return value
let
result
=
syscall
(
cx
.x
[
17
],
[
cx
.x
[
10
],
cx
.x
[
11
],
cx
.x
[
12
]]);
...
...
@@ -96,11 +94,9 @@ pub fn trap_handler() -> ! {
#[no_mangle]
pub
fn
trap_return
()
->
!
{
println!
(
"into trap_return!"
);
set_user_trap_entry
();
let
trap_cx_user_va
=
current_trap_cx_user_va
();
let
user_satp
=
current_user_token
();
println!
(
"trap_cx = {:#x}, user_satp = {:#x}"
,
trap_cx_user_va
,
user_satp
);
extern
"C"
{
fn
__
alltraps
();
fn
__
restore
();
...
...
user/src/lib.rs
浏览文件 @
1493ec94
...
...
@@ -105,4 +105,4 @@ pub fn sleep(period_ms: usize) {
while
sys_get_time
()
<
start
+
period_ms
as
isize
{
sys_yield
();
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录