Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
528c4f91
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
528c4f91
编写于
12月 19, 2021
作者:
A
Amanieu d'Antras
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add PanicInfo::can_unwind which indicates whether a panic handler is
allowed to trigger unwinding.
上级
bd3cb525
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
10 deletion
+31
-10
library/core/src/panic/panic_info.rs
library/core/src/panic/panic_info.rs
+15
-1
library/core/src/panicking.rs
library/core/src/panicking.rs
+1
-1
library/std/src/lib.rs
library/std/src/lib.rs
+1
-0
library/std/src/panicking.rs
library/std/src/panicking.rs
+14
-8
未找到文件。
library/core/src/panic/panic_info.rs
浏览文件 @
528c4f91
...
...
@@ -31,6 +31,7 @@ pub struct PanicInfo<'a> {
payload
:
&
'a
(
dyn
Any
+
Send
),
message
:
Option
<&
'a
fmt
::
Arguments
<
'a
>>
,
location
:
&
'a
Location
<
'a
>
,
can_unwind
:
bool
,
}
impl
<
'a
>
PanicInfo
<
'a
>
{
...
...
@@ -44,9 +45,10 @@ impl<'a> PanicInfo<'a> {
pub
fn
internal_constructor
(
message
:
Option
<&
'a
fmt
::
Arguments
<
'a
>>
,
location
:
&
'a
Location
<
'a
>
,
can_unwind
:
bool
,
)
->
Self
{
struct
NoPayload
;
PanicInfo
{
location
,
message
,
payload
:
&
NoPayload
}
PanicInfo
{
location
,
message
,
payload
:
&
NoPayload
,
can_unwind
}
}
#[unstable(
...
...
@@ -127,6 +129,18 @@ pub fn location(&self) -> Option<&Location<'_>> {
// deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
Some
(
&
self
.location
)
}
/// Returns whether the panic handler is allowed to unwind the stack from
/// the point where the panic occurred.
///
/// This is true for most kinds of panics with the exception of panics
/// caused by trying to unwind out of a `Drop` implementation or a function
/// whose ABI does not support unwinding.
#[must_use]
#[unstable(feature
=
"panic_can_unwind"
,
issue
=
"92988"
)]
pub
fn
can_unwind
(
&
self
)
->
bool
{
self
.can_unwind
}
}
#[stable(feature
=
"panic_hook_display"
,
since
=
"1.26.0"
)]
...
...
library/core/src/panicking.rs
浏览文件 @
528c4f91
...
...
@@ -104,7 +104,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
fn
panic_impl
(
pi
:
&
PanicInfo
<
'_
>
)
->
!
;
}
let
pi
=
PanicInfo
::
internal_constructor
(
Some
(
&
fmt
),
Location
::
caller
());
let
pi
=
PanicInfo
::
internal_constructor
(
Some
(
&
fmt
),
Location
::
caller
()
,
true
);
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
unsafe
{
panic_impl
(
&
pi
)
}
...
...
library/std/src/lib.rs
浏览文件 @
528c4f91
...
...
@@ -312,6 +312,7 @@
#![feature(once_cell)]
#![feature(panic_info_message)]
#![feature(panic_internals)]
#![feature(panic_can_unwind)]
#![feature(panic_unwind)]
#![feature(pin_static_ref)]
#![feature(portable_simd)]
...
...
library/std/src/panicking.rs
浏览文件 @
528c4f91
...
...
@@ -576,9 +576,14 @@ fn get(&mut self) -> &(dyn Any + Send) {
let
msg
=
info
.message
()
.unwrap
();
// The current implementation always returns Some
crate
::
sys_common
::
backtrace
::
__
rust_end_short_backtrace
(
move
||
{
if
let
Some
(
msg
)
=
msg
.as_str
()
{
rust_panic_with_hook
(
&
mut
StrPanicPayload
(
msg
),
info
.message
(),
loc
);
rust_panic_with_hook
(
&
mut
StrPanicPayload
(
msg
),
info
.message
(),
loc
,
info
.can_unwind
()
);
}
else
{
rust_panic_with_hook
(
&
mut
PanicPayload
::
new
(
msg
),
info
.message
(),
loc
);
rust_panic_with_hook
(
&
mut
PanicPayload
::
new
(
msg
),
info
.message
(),
loc
,
info
.can_unwind
(),
);
}
})
}
...
...
@@ -602,7 +607,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
let
loc
=
Location
::
caller
();
return
crate
::
sys_common
::
backtrace
::
__
rust_end_short_backtrace
(
move
||
{
rust_panic_with_hook
(
&
mut
PanicPayload
::
new
(
msg
),
None
,
loc
)
rust_panic_with_hook
(
&
mut
PanicPayload
::
new
(
msg
),
None
,
loc
,
true
)
});
struct
PanicPayload
<
A
>
{
...
...
@@ -647,6 +652,7 @@ fn rust_panic_with_hook(
payload
:
&
mut
dyn
BoxMeUp
,
message
:
Option
<&
fmt
::
Arguments
<
'_
>>
,
location
:
&
Location
<
'_
>
,
can_unwind
:
bool
,
)
->
!
{
let
(
must_abort
,
panics
)
=
panic_count
::
increase
();
...
...
@@ -663,14 +669,14 @@ fn rust_panic_with_hook(
}
else
{
// Unfortunately, this does not print a backtrace, because creating
// a `Backtrace` will allocate, which we must to avoid here.
let
panicinfo
=
PanicInfo
::
internal_constructor
(
message
,
location
);
let
panicinfo
=
PanicInfo
::
internal_constructor
(
message
,
location
,
can_unwind
);
rtprintpanic!
(
"{}
\n
panicked after panic::always_abort(), aborting.
\n
"
,
panicinfo
);
}
intrinsics
::
abort
()
crate
::
sys
::
abort_internal
();
}
unsafe
{
let
mut
info
=
PanicInfo
::
internal_constructor
(
message
,
location
);
let
mut
info
=
PanicInfo
::
internal_constructor
(
message
,
location
,
can_unwind
);
let
_
guard
=
HOOK_LOCK
.read
();
match
HOOK
{
// Some platforms (like wasm) know that printing to stderr won't ever actually
...
...
@@ -691,13 +697,13 @@ fn rust_panic_with_hook(
};
}
if
panics
>
1
{
if
panics
>
1
||
!
can_unwind
{
// If a thread panics while it's already unwinding then we
// have limited options. Currently our preference is to
// just abort. In the future we may consider resuming
// unwinding or otherwise exiting the thread cleanly.
rtprintpanic!
(
"thread panicked while panicking. aborting.
\n
"
);
intrinsics
::
abort
()
crate
::
sys
::
abort_internal
();
}
rust_panic
(
payload
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录