Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
60205a16
提交
60205a16
2月 10, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some more c++, using gnu extensions
上级
2a47dd2b
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
33 行增加
和
30 行删除
+33
-30
fs.c
fs.c
+5
-5
kernel.h
kernel.h
+6
-4
ns.cc
ns.cc
+4
-2
proc.cc
proc.cc
+18
-19
没有找到文件。
fs.c
浏览文件 @
60205a16
...
...
@@ -684,10 +684,10 @@ dirlink(struct inode *dp, char *name, u32 inum)
// skipelem("", name) = skipelem("////", name) = 0
//
static
int
skipelem
(
char
**
rpath
,
char
*
name
)
skipelem
(
c
onst
c
har
**
rpath
,
char
*
name
)
{
char
*
path
=
*
rpath
;
char
*
s
;
c
onst
c
har
*
path
=
*
rpath
;
c
onst
c
har
*
s
;
int
len
;
while
(
*
path
==
'/'
)
...
...
@@ -714,7 +714,7 @@ skipelem(char **rpath, char *name)
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
static
struct
inode
*
namex
(
char
*
path
,
int
nameiparent
,
char
*
name
)
namex
(
c
onst
c
har
*
path
,
int
nameiparent
,
char
*
name
)
{
struct
inode
*
ip
,
*
next
;
int
r
;
...
...
@@ -759,7 +759,7 @@ namex(char *path, int nameiparent, char *name)
}
struct
inode
*
namei
(
char
*
path
)
namei
(
c
onst
c
har
*
path
)
{
char
name
[
DIRSIZ
];
struct
inode
*
r
=
namex
(
path
,
0
,
name
);
...
...
kernel.h
浏览文件 @
60205a16
...
...
@@ -100,7 +100,7 @@ int filewrite(struct file*, char*, int n);
int
namecmp
(
const
char
*
,
const
char
*
);
struct
inode
*
dirlookup
(
struct
inode
*
,
char
*
);
struct
inode
*
ialloc
(
u32
,
short
);
struct
inode
*
namei
(
char
*
);
struct
inode
*
namei
(
c
onst
c
har
*
);
void
iput
(
struct
inode
*
);
struct
inode
*
iget
(
u32
dev
,
u32
inum
);
void
ilock
(
struct
inode
*
,
int
writer
);
...
...
@@ -208,7 +208,7 @@ struct nskey {
}
u
;
};
#define KI(v) (struct nskey){
.type=nskey_int,.u.i=v
}
#define KI(v) (struct nskey){
type: nskey_int, u: { i: v }
}
#define KII(x,y) (struct nskey){.type=nskey_ii,.u.ii.a=x,.u.ii.b=y}
#define KS(v) (struct nskey){.type=nskey_str,.u.s=v}
#define KD(v) (struct nskey){.type=nskey_dirname,.u.dirname=v}
...
...
@@ -412,8 +412,10 @@ long sys_bind(int, void*, int);
long
sys_listen
(
int
,
int
);
long
sys_accept
(
int
,
void
*
,
void
*
);
// other exported functions
// other exported
/imported
functions
void
cmain
(
u64
mbmagic
,
u64
mbaddr
);
void
mpboot
(
void
);
void
trapret
(
void
);
void
threadstub
(
void
);
void
threadhelper
(
void
(
*
fn
)(
void
*
),
void
*
arg
);
ns.c
→
ns.c
c
浏览文件 @
60205a16
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "spinlock.h"
#include "fs.h"
#include <stddef.h>
}
// name spaces
// XXX maybe use open hash table, no chain, better cache locality
...
...
@@ -54,7 +56,7 @@ nsalloc(int allowdup)
{
struct
ns
*
ns
=
0
;
ns
=
kmalloc
(
sizeof
(
struct
ns
));
ns
=
(
struct
ns
*
)
kmalloc
(
sizeof
(
struct
ns
));
if
(
ns
==
0
)
panic
(
"nsalloc"
);
memset
(
ns
,
0
,
sizeof
(
struct
ns
));
...
...
@@ -102,7 +104,7 @@ elemalloc(struct nskey *k)
panic
(
"key type"
);
}
e
=
kmalloc
(
sz
);
e
=
(
elem
*
)
kmalloc
(
sz
);
if
(
e
==
0
)
return
0
;
memset
(
e
,
0
,
sz
);
...
...
proc.c
→
proc.c
c
浏览文件 @
60205a16
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include "mmu.h"
...
...
@@ -11,8 +12,7 @@
#include "kmtrace.h"
#include "vm.h"
#include "sched.h"
extern
void
threadstub
(
void
);
}
int
__mpalign__
idle
[
NCPU
];
struct
ns
*
nspid
__mpalign__
;
...
...
@@ -139,7 +139,7 @@ exit(void)
// Kernel threads might not have a cwd
if
(
myproc
()
->
cwd
!=
NULL
)
{
iput
(
myproc
()
->
cwd
);
myproc
()
->
cwd
=
NULL
;
myproc
()
->
cwd
=
0
;
}
// Pass abandoned children to init.
...
...
@@ -185,11 +185,10 @@ freeproc(struct proc *p)
static
struct
proc
*
allocproc
(
void
)
{
extern
void
trapret
(
void
);
struct
proc
*
p
;
char
*
sp
;
p
=
kmalloc
(
sizeof
(
struct
proc
));
p
=
(
proc
*
)
kmalloc
(
sizeof
(
struct
proc
));
if
(
p
==
0
)
return
0
;
memset
(
p
,
0
,
sizeof
(
*
p
));
...
...
@@ -212,7 +211,7 @@ allocproc(void)
panic
(
"allocproc: ns_insert"
);
// Allocate kernel stack if possible.
if
((
p
->
kstack
=
ksalloc
(
slab_stack
))
==
0
){
if
((
p
->
kstack
=
(
char
*
)
ksalloc
(
slab_stack
))
==
0
){
if
(
ns_remove
(
nspid
,
KI
(
p
->
pid
),
p
)
==
0
)
panic
(
"allocproc: ns_remove"
);
freeproc
(
p
);
...
...
@@ -271,7 +270,7 @@ inituser(void)
p
->
tf
->
rip
=
0x0
;
// beginning of initcode.S
safestrcpy
(
p
->
name
,
"initcode"
,
sizeof
(
p
->
name
));
p
->
cwd
=
NULL
;
// forkret will fix in the process's context
p
->
cwd
=
0
;
// forkret will fix in the process's context
acquire
(
&
p
->
lock
);
addrun
(
p
);
release
(
&
p
->
lock
);
...
...
@@ -495,13 +494,13 @@ kill(int pid)
void
*
procdump
(
void
*
vk
,
void
*
v
,
void
*
arg
)
{
static
char
*
states
[]
=
{
[
UNUSED
]
=
"unused"
,
[
EMBRYO
]
=
"embryo"
,
[
SLEEPING
]
=
"sleep "
,
[
RUNNABLE
]
=
"runble"
,
[
RUNNING
]
=
"run "
,
[
ZOMBIE
]
=
"zombie"
static
c
onst
c
har
*
states
[]
=
{
/* [UNUSED] = */
"unused"
,
/* [EMBRYO] = */
"embryo"
,
/* [SLEEPING] = */
"sleep "
,
/* [RUNNABLE] = */
"runble"
,
/* [RUNNING] = */
"run "
,
/* [ZOMBIE] = */
"zombie"
};
struct
proc
*
p
=
(
struct
proc
*
)
v
;
const
char
*
name
=
"(no name)"
;
...
...
@@ -555,7 +554,7 @@ fork(int flags)
// Copy process state from p.
if
((
np
->
vmap
=
vmap_copy
(
myproc
()
->
vmap
,
cow
))
==
0
){
ksfree
(
slab_stack
,
np
->
kstack
);
np
->
kstack
=
NULL
;
np
->
kstack
=
0
;
np
->
state
=
UNUSED
;
if
(
ns_remove
(
nspid
,
KI
(
np
->
pid
),
np
)
==
0
)
panic
(
"fork: ns_remove"
);
...
...
@@ -616,7 +615,7 @@ wait(void)
SLIST_REMOVE
(
&
myproc
()
->
childq
,
p
,
proc
,
child_next
);
release
(
&
myproc
()
->
lock
);
ksfree
(
slab_stack
,
p
->
kstack
);
p
->
kstack
=
NULL
;
p
->
kstack
=
0
;
vmap_decref
(
p
->
vmap
);
p
->
state
=
UNUSED
;
if
(
ns_remove
(
nspid
,
KI
(
p
->
pid
),
p
)
==
0
)
...
...
@@ -660,18 +659,18 @@ threadalloc(void (*fn)(void *), void *arg)
p
=
allocproc
();
if
(
p
==
NULL
)
return
NULL
;
return
0
;
p
->
vmap
=
vmap_alloc
();
if
(
p
->
vmap
==
NULL
)
{
freeproc
(
p
);
return
NULL
;
return
0
;
}
p
->
context
->
rip
=
(
u64
)
threadstub
;
p
->
context
->
r12
=
(
u64
)
fn
;
p
->
context
->
r13
=
(
u64
)
arg
;
p
->
parent
=
myproc
();
p
->
cwd
=
NULL
;
p
->
cwd
=
0
;
return
p
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论