Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9ea4afe5
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,发现更多精彩内容 >>
提交
9ea4afe5
编写于
8月 17, 2012
作者:
E
Elliott Slaughter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gc: Avoid double free when pointer appears on stack multiple times.
上级
3f0d207b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
14 deletion
+23
-14
src/libcore/gc.rs
src/libcore/gc.rs
+23
-14
未找到文件。
src/libcore/gc.rs
浏览文件 @
9ea4afe5
import
stackwalk
::
Word
;
import
libc
::
size_t
;
import
send_map
::
linear
::
LinearMap
;
extern
mod
rustrt
{
fn
rust_annihilate_box
(
ptr
:
*
Word
);
...
...
@@ -37,7 +38,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
return
None
;
}
type
Visitor
=
fn
(
root
:
**
Word
,
tydesc
:
*
Word
);
type
Visitor
=
fn
(
root
:
**
Word
,
tydesc
:
*
Word
)
->
bool
;
unsafe
fn
walk_safe_point
(
fp
:
*
Word
,
sp
:
SafePoint
,
visitor
:
Visitor
)
{
let
fp_bytes
:
*
u8
=
unsafe
::
reinterpret_cast
(
&
fp
);
...
...
@@ -69,7 +70,7 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
}
else
{
ptr
::
null
()
};
visitor
(
root
,
tydesc
);
if
!
visitor
(
root
,
tydesc
)
{
return
;
}
}
sri
+=
1
;
}
...
...
@@ -94,25 +95,25 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
unsafe
fn
walk_gc_roots
(
mem
:
Memory
,
visitor
:
Visitor
)
{
let
mut
last_ret
:
*
Word
=
ptr
::
null
();
do
stackwalk
::
walk_stack
|
frame
|
{
for
stackwalk
::
walk_stack
|
frame
|
{
unsafe
{
if
ptr
::
is_not_null
(
last_ret
)
{
let
sp
=
is_safe_point
(
last_ret
);
match
sp
{
Some
(
sp_info
)
=>
{
do
walk_safe_point
(
frame
.fp
,
sp_info
)
|
root
,
tydesc
|
{
for
walk_safe_point
(
frame
.fp
,
sp_info
)
|
root
,
tydesc
|
{
if
ptr
::
is_null
(
tydesc
)
{
// Root is a generic box.
let
refcount
=
**
root
;
if
mem
|
task_local_heap
!=
0
&&
refcount
!=
-
1
{
visitor
(
root
,
tydesc
);
if
!
visitor
(
root
,
tydesc
)
{
return
;
}
}
else
if
mem
|
exchange_heap
!=
0
{
visitor
(
root
,
tydesc
);
if
!
visitor
(
root
,
tydesc
)
{
return
;
}
}
}
else
{
// Root is a non-immediate.
if
mem
|
stack
!=
0
{
visitor
(
root
,
tydesc
);
if
!
visitor
(
root
,
tydesc
)
{
return
;
}
}
}
}
...
...
@@ -122,34 +123,42 @@ unsafe fn walk_gc_roots(mem: Memory, visitor: Visitor) {
}
last_ret
=
*
ptr
::
offset
(
frame
.fp
,
1
)
as
*
Word
;
}
true
}
}
fn
gc
()
{
unsafe
{
let
mut
i
=
0
;
do
walk_gc_roots
(
task_local_heap
)
|
_
root
,
_
tydesc
|
{
for
walk_gc_roots
(
task_local_heap
)
|
_
root
,
_
tydesc
|
{
// FIXME(#2997): Walk roots and mark them.
io
::
stdout
()
.write
([
46
]);
// .
i
+=
1
;
}
}
}
type
RootSet
=
LinearMap
<*
Word
,()
>
;
fn
RootSet
()
->
RootSet
{
LinearMap
()
}
// This should only be called from fail, as it will drop the roots
// which are *live* on the stack, rather than dropping those that are
// dead.
fn
cleanup_stack_for_failure
()
{
unsafe
{
let
mut
i
=
0
;
do
walk_gc_roots
(
need_cleanup
)
|
root
,
tydesc
|
{
let
mut
roots
=
~
RootSet
();
for
walk_gc_roots
(
need_cleanup
)
|
root
,
tydesc
|
{
// Track roots to avoid double frees.
if
option
::
is_some
(
roots
.find
(
&*
root
))
{
again
;
}
roots
.insert
(
*
root
,
());
if
ptr
::
is_null
(
tydesc
)
{
rustrt
::
rust_annihilate_box
(
*
root
);
}
else
{
rustrt
::
rust_call_tydesc_glue
(
*
root
,
tydesc
,
3
as
size_t
);
}
i
+=
1
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录