Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
ad28f5f6
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,发现更多精彩内容 >>
提交
ad28f5f6
编写于
4月 26, 2022
作者:
chyyuu1972
2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update signal impl and apps
上级
a6b278fe
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
129 addition
and
19 deletion
+129
-19
os/src/syscall/mod.rs
os/src/syscall/mod.rs
+2
-2
os/src/syscall/process.rs
os/src/syscall/process.rs
+5
-5
user/src/bin/sig_simple.rs
user/src/bin/sig_simple.rs
+32
-0
user/src/bin/sig_simple2.rs
user/src/bin/sig_simple2.rs
+44
-0
user/src/bin/sig_tests.rs
user/src/bin/sig_tests.rs
+10
-9
user/src/lib.rs
user/src/lib.rs
+34
-1
user/src/syscall.rs
user/src/syscall.rs
+2
-2
未找到文件。
os/src/syscall/mod.rs
浏览文件 @
ad28f5f6
...
...
@@ -34,8 +34,8 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
SYSCALL_WRITE
=>
sys_write
(
args
[
0
],
args
[
1
]
as
*
const
u8
,
args
[
2
]),
SYSCALL_EXIT
=>
sys_exit
(
args
[
0
]
as
i32
),
SYSCALL_YIELD
=>
sys_yield
(),
SYSCALL_KILL
=>
sys_kill
(
args
[
0
],
args
[
1
]
as
u
32
),
SYSCALL_SIGACTION
=>
sys_sigaction
(
args
[
0
],
args
[
1
]
as
*
const
SignalAction
,
args
[
2
]
as
*
mut
SignalAction
),
SYSCALL_KILL
=>
sys_kill
(
args
[
0
],
args
[
1
]
as
i
32
),
SYSCALL_SIGACTION
=>
sys_sigaction
(
args
[
0
]
as
i32
,
args
[
1
]
as
*
const
SignalAction
,
args
[
2
]
as
*
mut
SignalAction
),
SYSCALL_SIGPROCMASK
=>
sys_sigprocmask
(
args
[
0
]
as
u32
),
SYSCALL_SIGRETURN
=>
sys_sigretrun
(),
SYSCALL_GET_TIME
=>
sys_get_time
(),
...
...
os/src/syscall/process.rs
浏览文件 @
ad28f5f6
...
...
@@ -104,9 +104,9 @@ pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize {
// ---- release current PCB automatically
}
pub
fn
sys_kill
(
pid
:
usize
,
sign
al
:
u
32
)
->
isize
{
pub
fn
sys_kill
(
pid
:
usize
,
sign
um
:
i
32
)
->
isize
{
if
let
Some
(
task
)
=
pid2task
(
pid
)
{
if
let
Some
(
flag
)
=
SignalFlags
::
from_bits
(
signal
)
{
if
let
Some
(
flag
)
=
SignalFlags
::
from_bits
(
1
<<
signum
)
{
// insert the signal if legal
let
mut
task_ref
=
task
.inner_exclusive_access
();
if
task_ref
.signals
.contains
(
flag
)
{
...
...
@@ -159,7 +159,7 @@ fn check_sigaction_error(signal: SignalFlags, action: usize, old_action: usize)
}
}
pub
fn
sys_sigaction
(
signum
:
usize
,
action
:
*
const
SignalAction
,
old_action
:
*
mut
SignalAction
)
->
isize
{
pub
fn
sys_sigaction
(
signum
:
i32
,
action
:
*
const
SignalAction
,
old_action
:
*
mut
SignalAction
)
->
isize
{
let
token
=
current_user_token
();
if
let
Some
(
task
)
=
current_task
()
{
let
mut
inner
=
task
.inner_exclusive_access
();
...
...
@@ -170,7 +170,7 @@ pub fn sys_sigaction(signum: usize, action: *const SignalAction, old_action: *mu
if
check_sigaction_error
(
flag
,
action
as
usize
,
old_action
as
usize
)
{
return
-
1
;
}
let
old_kernel_action
=
inner
.signal_actions.table
[
signum
];
let
old_kernel_action
=
inner
.signal_actions.table
[
signum
as
usize
];
if
old_kernel_action
.mask
!=
SignalFlags
::
from_bits
(
40
)
.unwrap
()
{
*
translated_refmut
(
token
,
old_action
)
=
old_kernel_action
;
}
else
{
...
...
@@ -178,7 +178,7 @@ pub fn sys_sigaction(signum: usize, action: *const SignalAction, old_action: *mu
ref_old_action
.handler
=
old_kernel_action
.handler
;
}
let
ref_action
=
translated_ref
(
token
,
action
);
inner
.signal_actions.table
[
signum
]
=
*
ref_action
;
inner
.signal_actions.table
[
signum
as
usize
]
=
*
ref_action
;
return
0
;
}
}
...
...
user/src/bin/sig_simple.rs
0 → 100644
浏览文件 @
ad28f5f6
#![no_std]
#![no_main]
#[macro_use]
extern
crate
user_lib
;
// use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn};
use
user_lib
::
*
;
fn
func
()
{
println!
(
"user_sig_test succsess"
);
sigreturn
();
}
#[no_mangle]
pub
fn
main
()
->
i32
{
let
mut
new
=
SignalAction
::
default
();
let
old
=
SignalAction
::
default
();
new
.handler
=
func
as
usize
;
println!
(
"signal_simple: sigaction"
);
if
sigaction
(
SIGUSR1
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
println!
(
"signal_simple: kill"
);
if
kill
(
getpid
()
as
usize
,
SIGUSR1
)
<
0
{
println!
(
"Kill failed!"
);
exit
(
1
);
}
println!
(
"signal_simple: Done"
);
0
}
user/src/bin/sig_simple2.rs
0 → 100644
浏览文件 @
ad28f5f6
#![no_std]
#![no_main]
#[macro_use]
extern
crate
user_lib
;
use
user_lib
::{
sigaction
,
sigprocmask
,
SignalAction
,
SignalFlags
,
fork
,
exit
,
waitpid
,
kill
,
getpid
,
sleep
,
sigreturn
};
fn
func
()
{
println!
(
"user_sig_test succsess"
);
sigreturn
();
}
#[no_mangle]
pub
fn
main
()
->
i32
{
let
pid
=
fork
();
if
pid
==
0
{
let
mut
new
=
SignalAction
::
default
();
let
old
=
SignalAction
::
default
();
new
.handler
=
func
as
usize
;
println!
(
"signal_simple2: child sigaction"
);
if
sigaction
(
10
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
sleep
(
1000
);
println!
(
"signal_simple2: child done"
);
exit
(
0
);
}
else
if
pid
>
0
{
println!
(
"signal_simple2: parent kill child"
);
sleep
(
500
);
if
kill
(
pid
as
usize
,
1
<<
10
)
<
0
{
println!
(
"Kill failed!"
);
exit
(
1
);
}
println!
(
"signal_simple2: parent wait child"
);
let
mut
exit_code
=
0
;
waitpid
(
pid
as
usize
,
&
mut
exit_code
);
println!
(
"signal_simple2: parent Done"
);
exit
(
0
);
}
0
}
user/src/bin/sig_tests.rs
浏览文件 @
ad28f5f6
...
...
@@ -4,7 +4,8 @@
#[macro_use]
extern
crate
user_lib
;
use
user_lib
::{
sigaction
,
sigprocmask
,
SignalAction
,
SignalFlags
,
fork
,
exit
,
wait
,
kill
,
getpid
,
sleep
,
sigreturn
};
// use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn};
use
user_lib
::
*
;
fn
func
()
{
println!
(
"user_sig_test succsess"
);
...
...
@@ -36,10 +37,10 @@ fn user_sig_test_kill() {
let
old
=
SignalAction
::
default
();
new
.handler
=
func
as
usize
;
if
sigaction
(
10
,
&
new
,
&
old
)
<
0
{
if
sigaction
(
SIGUSR1
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
if
kill
(
getpid
()
as
usize
,
1
<<
10
)
<
0
{
if
kill
(
getpid
()
as
usize
,
SIGUSR1
)
<
0
{
println!
(
"Kill failed!"
);
exit
(
1
);
}
...
...
@@ -51,11 +52,11 @@ fn user_sig_test_multiprocsignals() {
let
mut
new
=
SignalAction
::
default
();
let
old
=
SignalAction
::
default
();
new
.handler
=
func
as
usize
;
if
sigaction
(
10
,
&
new
,
&
old
)
<
0
{
if
sigaction
(
SIGUSR1
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
}
else
{
if
kill
(
pid
as
usize
,
1
<<
10
)
<
0
{
if
kill
(
pid
as
usize
,
SIGUSR1
)
<
0
{
println!
(
"Kill failed!"
);
exit
(
1
);
}
...
...
@@ -70,11 +71,11 @@ fn user_sig_test_restore() {
let
old2
=
SignalAction
::
default
();
new
.handler
=
func
as
usize
;
if
sigaction
(
10
,
&
new
,
&
old
)
<
0
{
if
sigaction
(
SIGUSR1
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
if
sigaction
(
10
,
&
old
,
&
old2
)
<
0
{
if
sigaction
(
SIGUSR1
,
&
old
,
&
old2
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
...
...
@@ -135,13 +136,13 @@ fn final_sig_test() {
let
pid
=
fork
();
if
pid
==
0
{
if
sigaction
(
10
,
&
new
,
&
old
)
<
0
{
if
sigaction
(
SIGUSR1
,
&
new
,
&
old
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
if
sigaction
(
14
,
&
new2
,
&
old2
)
<
0
{
panic!
(
"Sigaction failed!"
);
}
if
kill
(
getpid
()
as
usize
,
1
<<
10
)
<
0
{
if
kill
(
getpid
()
as
usize
,
SIGUSR1
)
<
0
{
println!
(
"Kill failed!"
);
exit
(
-
1
);
}
...
...
user/src/lib.rs
浏览文件 @
ad28f5f6
...
...
@@ -156,6 +156,39 @@ impl Default for SignalAction {
}
}
pub
const
SIGDEF
:
i32
=
1
;
// Default signal handling
pub
const
SIGHUP
:
i32
=
1
;
pub
const
SIGINT
:
i32
=
2
;
pub
const
SIGQUIT
:
i32
=
3
;
pub
const
SIGILL
:
i32
=
4
;
pub
const
SIGTRAP
:
i32
=
5
;
pub
const
SIGABRT
:
i32
=
6
;
pub
const
SIGBUS
:
i32
=
7
;
pub
const
SIGFPE
:
i32
=
8
;
pub
const
SIGKILL
:
i32
=
9
;
pub
const
SIGUSR1
:
i32
=
10
;
pub
const
SIGSEGV
:
i32
=
11
;
pub
const
SIGUSR2
:
i32
=
12
;
pub
const
SIGPIPE
:
i32
=
13
;
pub
const
SIGALRM
:
i32
=
14
;
pub
const
SIGTERM
:
i32
=
15
;
pub
const
SIGSTKFLT
:
i32
=
16
;
pub
const
SIGCHLD
:
i32
=
17
;
pub
const
SIGCONT
:
i32
=
18
;
pub
const
SIGSTOP
:
i32
=
19
;
pub
const
SIGTSTP
:
i32
=
20
;
pub
const
SIGTTIN
:
i32
=
21
;
pub
const
SIGTTOU
:
i32
=
22
;
pub
const
SIGURG
:
i32
=
23
;
pub
const
SIGXCPU
:
i32
=
24
;
pub
const
SIGXFSZ
:
i32
=
25
;
pub
const
SIGVTALRM
:
i32
=
26
;
pub
const
SIGPROF
:
i32
=
27
;
pub
const
SIGWINCH
:
i32
=
28
;
pub
const
SIGIO
:
i32
=
29
;
pub
const
SIGPWR
:
i32
=
30
;
pub
const
SIGSYS
:
i32
=
31
;
bitflags!
{
pub
struct
SignalFlags
:
i32
{
const
SIGDEF
=
1
;
// Default signal handling
...
...
@@ -197,7 +230,7 @@ pub fn kill(pid: usize, signal: i32) -> isize {
sys_kill
(
pid
,
signal
)
}
pub
fn
sigaction
(
signum
:
usize
,
action
:
*
const
SignalAction
,
old_action
:
*
const
SignalAction
)
->
isize
{
pub
fn
sigaction
(
signum
:
i32
,
action
:
*
const
SignalAction
,
old_action
:
*
const
SignalAction
)
->
isize
{
sys_sigaction
(
signum
,
action
,
old_action
)
}
...
...
user/src/syscall.rs
浏览文件 @
ad28f5f6
...
...
@@ -97,8 +97,8 @@ pub fn sys_waitpid(pid: isize, exit_code: *mut i32) -> isize {
syscall
(
SYSCALL_WAITPID
,
[
pid
as
usize
,
exit_code
as
usize
,
0
])
}
pub
fn
sys_sigaction
(
signum
:
usize
,
action
:
*
const
SignalAction
,
old_action
:
*
const
SignalAction
)
->
isize
{
syscall
(
SYSCALL_SIGACTION
,
[
signum
,
action
as
usize
,
old_action
as
usize
])
pub
fn
sys_sigaction
(
signum
:
i32
,
action
:
*
const
SignalAction
,
old_action
:
*
const
SignalAction
)
->
isize
{
syscall
(
SYSCALL_SIGACTION
,
[
signum
as
usize
,
action
as
usize
,
old_action
as
usize
])
}
pub
fn
sys_sigprocmask
(
mask
:
u32
)
->
isize
{
...
...
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
9293a71b
·
4月 27, 2022
mentioned in commit
9293a71b
mentioned in commit 9293a71bb30c0601496b1275df78506ba721b873
开关提交列表
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
7892e5e2
·
4月 27, 2022
mentioned in commit
7892e5e2
mentioned in commit 7892e5e2dadaedddd3497eb71ed717a7e093fbf7
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录