Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
2b285c52
提交
2b285c52
4月 02, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some more out-of-memory handling
上级
ba71a527
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
30 行增加
和
16 行删除
+30
-16
cpputil.hh
include/cpputil.hh
+23
-0
filetable.hh
include/filetable.hh
+0
-2
proc.cc
kernel/proc.cc
+7
-14
没有找到文件。
include/cpputil.hh
浏览文件 @
2b285c52
...
...
@@ -152,3 +152,26 @@ extern void *__dso_handle;
kmfree(p, sizeof(classname)); \
}
template
<
class
T
>
class
scoped_cleanup_obj
{
private
:
T
handler_
;
bool
active_
;
public
:
scoped_cleanup_obj
(
const
T
&
h
)
:
handler_
(
h
),
active_
(
true
)
{};
~
scoped_cleanup_obj
()
{
if
(
active_
)
handler_
();
}
void
dismiss
()
{
active_
=
false
;
}
void
operator
=
(
const
scoped_cleanup_obj
&
)
=
delete
;
scoped_cleanup_obj
(
const
scoped_cleanup_obj
&
)
=
delete
;
scoped_cleanup_obj
(
scoped_cleanup_obj
&&
other
)
:
handler_
(
other
.
handler_
),
active_
(
other
.
active_
)
{
other
.
dismiss
();
}
};
template
<
class
T
>
scoped_cleanup_obj
<
T
>
scoped_cleanup
(
const
T
&
h
)
{
return
scoped_cleanup_obj
<
T
>
(
h
);
}
include/filetable.hh
浏览文件 @
2b285c52
...
...
@@ -8,8 +8,6 @@ public:
filetable
*
copy
()
{
filetable
*
t
=
alloc
();
if
(
t
==
nullptr
)
return
nullptr
;
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
{
sref
<
file
>
f
;
...
...
kernel/proc.cc
浏览文件 @
2b285c52
...
...
@@ -354,19 +354,18 @@ fork(int flags)
if
((
np
=
proc
::
alloc
())
==
0
)
throw
std
::
bad_alloc
();
// XXX use a scoped cleanup handler to do xnspid->remove & freeproc
auto
proc_cleanup
=
scoped_cleanup
([
&
np
]()
{
if
(
!
xnspid
->
remove
(
np
->
pid
,
&
np
))
panic
(
"fork: ns_remove"
);
freeproc
(
np
);
});
if
(
flags
&
FORK_SHARE_VMAP
)
{
np
->
vmap
=
myproc
()
->
vmap
;
np
->
vmap
->
ref
++
;
}
else
{
// Copy process state from p.
if
((
np
->
vmap
=
myproc
()
->
vmap
->
copy
(
cow
))
==
0
){
if
(
!
xnspid
->
remove
(
np
->
pid
,
&
np
))
panic
(
"fork: ns_remove"
);
freeproc
(
np
);
throw
std
::
bad_alloc
();
}
np
->
vmap
=
myproc
()
->
vmap
->
copy
(
cow
);
}
np
->
parent
=
myproc
();
...
...
@@ -383,11 +382,6 @@ fork(int flags)
np
->
ftable
=
myproc
()
->
ftable
;
}
else
{
np
->
ftable
=
myproc
()
->
ftable
->
copy
();
if
(
np
->
ftable
==
nullptr
)
{
// XXX(sbw) leaking?
freeproc
(
np
);
throw
std
::
bad_alloc
();
}
}
np
->
cwd
=
idup
(
myproc
()
->
cwd
);
...
...
@@ -402,6 +396,7 @@ fork(int flags)
addrun
(
np
);
release
(
&
np
->
lock
);
proc_cleanup
.
dismiss
();
return
pid
;
}
...
...
@@ -412,8 +407,6 @@ finishproc(struct proc *p)
p
->
vmap
->
decref
();
if
(
p
->
uwq
!=
nullptr
)
p
->
uwq
->
dec
();
ksfree
(
slab_stack
,
p
->
kstack
);
p
->
kstack
=
0
;
p
->
pid
=
0
;
p
->
parent
=
0
;
p
->
name
[
0
]
=
0
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论