Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
dca5b5ca
提交
dca5b5ca
8月 10, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid assignments in declarations
上级
6861140a
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
42 行增加
和
34 行删除
+42
-34
main.c
main.c
+2
-2
printf.c
printf.c
+11
-6
string.c
string.c
+6
-4
sysfile.c
sysfile.c
+1
-1
trap.c
trap.c
+5
-6
ulib.c
ulib.c
+6
-5
umalloc.c
umalloc.c
+1
-1
usertests.c
usertests.c
+10
-9
没有找到文件。
main.c
浏览文件 @
dca5b5ca
...
@@ -118,13 +118,13 @@ mpmain(void)
...
@@ -118,13 +118,13 @@ mpmain(void)
void
void
process0
(
void
)
process0
(
void
)
{
{
struct
proc
*
p0
=
&
proc
[
0
];
struct
proc
*
p1
;
extern
struct
spinlock
proc_table_lock
;
extern
struct
spinlock
proc_table_lock
;
struct
proc
*
p0
,
*
p1
;
struct
trapframe
tf
;
struct
trapframe
tf
;
release
(
&
proc_table_lock
);
release
(
&
proc_table_lock
);
p0
=
&
proc
[
0
];
p0
->
cwd
=
iget
(
rootdev
,
1
);
p0
->
cwd
=
iget
(
rootdev
,
1
);
iunlock
(
p0
->
cwd
);
iunlock
(
p0
->
cwd
);
...
...
printf.c
浏览文件 @
dca5b5ca
...
@@ -11,18 +11,20 @@ putc(int fd, char c)
...
@@ -11,18 +11,20 @@ putc(int fd, char c)
static
void
static
void
printint
(
int
fd
,
int
xx
,
int
base
,
int
sgn
)
printint
(
int
fd
,
int
xx
,
int
base
,
int
sgn
)
{
{
static
char
digits
[]
=
"0123456789ABCDEF"
;
char
buf
[
16
];
char
buf
[
16
];
char
digits
[]
=
"0123456789ABCDEF"
;
int
i
,
neg
;
int
i
=
0
,
neg
=
0
;
uint
x
;
uint
x
;
neg
=
0
;
if
(
sgn
&&
xx
<
0
){
if
(
sgn
&&
xx
<
0
){
neg
=
1
;
neg
=
1
;
x
=
0
-
xx
;
x
=
-
xx
;
}
else
{
}
else
{
x
=
xx
;
x
=
xx
;
}
}
i
=
0
;
do
{
do
{
buf
[
i
++
]
=
digits
[
x
%
base
];
buf
[
i
++
]
=
digits
[
x
%
base
];
}
while
((
x
/=
base
)
!=
0
);
}
while
((
x
/=
base
)
!=
0
);
...
@@ -37,9 +39,12 @@ printint(int fd, int xx, int base, int sgn)
...
@@ -37,9 +39,12 @@ printint(int fd, int xx, int base, int sgn)
void
void
printf
(
int
fd
,
char
*
fmt
,
...)
printf
(
int
fd
,
char
*
fmt
,
...)
{
{
int
i
,
state
=
0
,
c
;
char
*
s
;
uint
*
ap
=
(
uint
*
)(
void
*
)
&
fmt
+
1
;
int
c
,
i
,
state
;
uint
*
ap
;
state
=
0
;
ap
=
(
uint
*
)(
void
*
)
&
fmt
+
1
;
for
(
i
=
0
;
fmt
[
i
];
i
++
){
for
(
i
=
0
;
fmt
[
i
];
i
++
){
c
=
fmt
[
i
]
&
0xff
;
c
=
fmt
[
i
]
&
0xff
;
if
(
state
==
0
){
if
(
state
==
0
){
...
@@ -56,7 +61,7 @@ printf(int fd, char *fmt, ...)
...
@@ -56,7 +61,7 @@ printf(int fd, char *fmt, ...)
printint
(
fd
,
*
ap
,
16
,
0
);
printint
(
fd
,
*
ap
,
16
,
0
);
ap
++
;
ap
++
;
}
else
if
(
c
==
's'
){
}
else
if
(
c
==
's'
){
char
*
s
=
(
char
*
)
*
ap
;
s
=
(
char
*
)
*
ap
;
ap
++
;
ap
++
;
while
(
*
s
!=
0
){
while
(
*
s
!=
0
){
putc
(
fd
,
*
s
);
putc
(
fd
,
*
s
);
...
...
string.c
浏览文件 @
dca5b5ca
...
@@ -4,8 +4,9 @@
...
@@ -4,8 +4,9 @@
void
*
void
*
memset
(
void
*
dst
,
int
c
,
uint
n
)
memset
(
void
*
dst
,
int
c
,
uint
n
)
{
{
char
*
d
=
(
char
*
)
dst
;
char
*
d
;
d
=
(
char
*
)
dst
;
while
(
n
--
>
0
)
while
(
n
--
>
0
)
*
d
++
=
c
;
*
d
++
=
c
;
...
@@ -15,12 +16,13 @@ memset(void *dst, int c, uint n)
...
@@ -15,12 +16,13 @@ memset(void *dst, int c, uint n)
int
int
memcmp
(
const
void
*
v1
,
const
void
*
v2
,
uint
n
)
memcmp
(
const
void
*
v1
,
const
void
*
v2
,
uint
n
)
{
{
const
uchar
*
s1
=
(
const
uchar
*
)
v1
;
const
uchar
*
s1
,
*
s2
;
const
uchar
*
s2
=
(
const
uchar
*
)
v2
;
s1
=
v1
;
s2
=
v2
;
while
(
n
--
>
0
)
{
while
(
n
--
>
0
)
{
if
(
*
s1
!=
*
s2
)
if
(
*
s1
!=
*
s2
)
return
(
int
)
*
s1
-
(
int
)
*
s2
;
return
*
s1
-
*
s2
;
s1
++
,
s2
++
;
s1
++
,
s2
++
;
}
}
...
...
sysfile.c
浏览文件 @
dca5b5ca
...
@@ -54,7 +54,7 @@ int
...
@@ -54,7 +54,7 @@ int
sys_pipe
(
void
)
sys_pipe
(
void
)
{
{
int
*
fd
;
int
*
fd
;
struct
file
*
rf
=
0
,
*
wf
=
0
;
struct
file
*
rf
,
*
wf
;
int
fd0
,
fd1
;
int
fd0
,
fd1
;
if
(
argptr
(
0
,
(
void
*
)
&
fd
,
2
*
sizeof
fd
[
0
])
<
0
)
if
(
argptr
(
0
,
(
void
*
)
&
fd
,
2
*
sizeof
fd
[
0
])
<
0
)
...
...
trap.c
浏览文件 @
dca5b5ca
...
@@ -30,9 +30,7 @@ idtinit(void)
...
@@ -30,9 +30,7 @@ idtinit(void)
void
void
trap
(
struct
trapframe
*
tf
)
trap
(
struct
trapframe
*
tf
)
{
{
int
v
=
tf
->
trapno
;
if
(
tf
->
trapno
==
T_SYSCALL
){
if
(
v
==
T_SYSCALL
){
if
(
cp
->
killed
)
if
(
cp
->
killed
)
proc_exit
();
proc_exit
();
cp
->
tf
=
tf
;
cp
->
tf
=
tf
;
...
@@ -47,7 +45,7 @@ trap(struct trapframe *tf)
...
@@ -47,7 +45,7 @@ trap(struct trapframe *tf)
// during interrupt handler. Decrement before returning.
// during interrupt handler. Decrement before returning.
cpus
[
cpu
()].
nlock
++
;
cpus
[
cpu
()].
nlock
++
;
switch
(
v
){
switch
(
tf
->
trapno
){
case
IRQ_OFFSET
+
IRQ_TIMER
:
case
IRQ_OFFSET
+
IRQ_TIMER
:
lapic_timerintr
();
lapic_timerintr
();
cpus
[
cpu
()].
nlock
--
;
cpus
[
cpu
()].
nlock
--
;
...
@@ -82,12 +80,13 @@ trap(struct trapframe *tf)
...
@@ -82,12 +80,13 @@ trap(struct trapframe *tf)
if
(
cp
)
{
if
(
cp
)
{
// Assume process divided by zero or dereferenced null, etc.
// Assume process divided by zero or dereferenced null, etc.
cprintf
(
"pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc
\n
"
,
cprintf
(
"pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc
\n
"
,
cp
->
pid
,
cp
->
name
,
v
,
cpu
(),
tf
->
eip
);
cp
->
pid
,
cp
->
name
,
tf
->
trapno
,
cpu
(),
tf
->
eip
);
proc_exit
();
proc_exit
();
}
}
// Otherwise it's our mistake.
// Otherwise it's our mistake.
cprintf
(
"unexpected trap %d from cpu %d eip %x
\n
"
,
v
,
cpu
(),
tf
->
eip
);
cprintf
(
"unexpected trap %d from cpu %d eip %x
\n
"
,
tf
->
trapno
,
cpu
(),
tf
->
eip
);
panic
(
"trap"
);
panic
(
"trap"
);
}
}
...
...
ulib.c
浏览文件 @
dca5b5ca
...
@@ -31,7 +31,8 @@ strcmp(const char *p, const char *q)
...
@@ -31,7 +31,8 @@ strcmp(const char *p, const char *q)
uint
uint
strlen
(
char
*
s
)
strlen
(
char
*
s
)
{
{
int
n
=
0
;
int
n
;
for
(
n
=
0
;
s
[
n
];
n
++
)
for
(
n
=
0
;
s
[
n
];
n
++
)
;
;
return
n
;
return
n
;
...
@@ -40,11 +41,11 @@ strlen(char *s)
...
@@ -40,11 +41,11 @@ strlen(char *s)
void
*
void
*
memset
(
void
*
dst
,
int
c
,
uint
n
)
memset
(
void
*
dst
,
int
c
,
uint
n
)
{
{
char
*
d
=
(
char
*
)
dst
;
char
*
d
;
d
=
dst
;
while
(
n
--
>
0
)
while
(
n
--
>
0
)
*
d
++
=
c
;
*
d
++
=
c
;
return
dst
;
return
dst
;
}
}
...
@@ -60,10 +61,10 @@ strchr(const char *s, char c)
...
@@ -60,10 +61,10 @@ strchr(const char *s, char c)
char
*
char
*
gets
(
char
*
buf
,
int
max
)
gets
(
char
*
buf
,
int
max
)
{
{
int
i
=
0
,
cc
;
int
i
,
cc
;
char
c
;
char
c
;
while
(
i
+
1
<
max
){
for
(
i
=
0
;
i
+
1
<
max
;
){
cc
=
read
(
0
,
&
c
,
1
);
cc
=
read
(
0
,
&
c
,
1
);
if
(
cc
<
1
)
if
(
cc
<
1
)
break
;
break
;
...
...
umalloc.c
浏览文件 @
dca5b5ca
...
@@ -19,7 +19,7 @@ union header {
...
@@ -19,7 +19,7 @@ union header {
typedef
union
header
Header
;
typedef
union
header
Header
;
static
Header
base
;
static
Header
base
;
static
Header
*
freep
=
0
;
static
Header
*
freep
;
void
void
free
(
void
*
ap
)
free
(
void
*
ap
)
...
...
usertests.c
浏览文件 @
dca5b5ca
...
@@ -203,13 +203,14 @@ void
...
@@ -203,13 +203,14 @@ void
pipe1
(
void
)
pipe1
(
void
)
{
{
int
fds
[
2
],
pid
;
int
fds
[
2
],
pid
;
int
seq
=
0
,
i
,
n
,
cc
,
total
;
int
seq
,
i
,
n
,
cc
,
total
;
if
(
pipe
(
fds
)
!=
0
){
if
(
pipe
(
fds
)
!=
0
){
printf
(
1
,
"pipe() failed
\n
"
);
printf
(
1
,
"pipe() failed
\n
"
);
exit
();
exit
();
}
}
pid
=
fork
();
pid
=
fork
();
seq
=
0
;
if
(
pid
==
0
){
if
(
pid
==
0
){
close
(
fds
[
0
]);
close
(
fds
[
0
]);
for
(
n
=
0
;
n
<
5
;
n
++
){
for
(
n
=
0
;
n
<
5
;
n
++
){
...
@@ -464,8 +465,8 @@ twofiles(void)
...
@@ -464,8 +465,8 @@ twofiles(void)
void
void
createdelete
(
void
)
createdelete
(
void
)
{
{
enum
{
N
=
20
};
int
pid
,
i
,
fd
;
int
pid
,
i
,
fd
;
int
n
=
20
;
char
name
[
32
];
char
name
[
32
];
printf
(
1
,
"createdelete test
\n
"
);
printf
(
1
,
"createdelete test
\n
"
);
...
@@ -477,7 +478,7 @@ createdelete(void)
...
@@ -477,7 +478,7 @@ createdelete(void)
name
[
0
]
=
pid
?
'p'
:
'c'
;
name
[
0
]
=
pid
?
'p'
:
'c'
;
name
[
2
]
=
'\0'
;
name
[
2
]
=
'\0'
;
for
(
i
=
0
;
i
<
n
;
i
++
){
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
1
]
=
'0'
+
i
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
O_CREATE
|
O_RDWR
);
fd
=
open
(
name
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
if
(
fd
<
0
){
...
@@ -499,14 +500,14 @@ createdelete(void)
...
@@ -499,14 +500,14 @@ createdelete(void)
// else
// else
//exit();
//exit();
for
(
i
=
0
;
i
<
n
;
i
++
){
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
0
]
=
'p'
;
name
[
0
]
=
'p'
;
name
[
1
]
=
'0'
+
i
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
n
/
2
)
&&
fd
<
0
){
if
((
i
==
0
||
i
>=
N
/
2
)
&&
fd
<
0
){
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
exit
();
exit
();
}
else
if
((
i
>=
1
&&
i
<
n
/
2
)
&&
fd
>=
0
){
}
else
if
((
i
>=
1
&&
i
<
N
/
2
)
&&
fd
>=
0
){
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
exit
();
exit
();
}
}
...
@@ -516,10 +517,10 @@ createdelete(void)
...
@@ -516,10 +517,10 @@ createdelete(void)
name
[
0
]
=
'c'
;
name
[
0
]
=
'c'
;
name
[
1
]
=
'0'
+
i
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
n
/
2
)
&&
fd
<
0
){
if
((
i
==
0
||
i
>=
N
/
2
)
&&
fd
<
0
){
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
exit
();
exit
();
}
else
if
((
i
>=
1
&&
i
<
n
/
2
)
&&
fd
>=
0
){
}
else
if
((
i
>=
1
&&
i
<
N
/
2
)
&&
fd
>=
0
){
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
exit
();
exit
();
}
}
...
@@ -527,7 +528,7 @@ createdelete(void)
...
@@ -527,7 +528,7 @@ createdelete(void)
close
(
fd
);
close
(
fd
);
}
}
for
(
i
=
0
;
i
<
n
;
i
++
){
for
(
i
=
0
;
i
<
N
;
i
++
){
name
[
0
]
=
'p'
;
name
[
0
]
=
'p'
;
name
[
1
]
=
'0'
+
i
;
name
[
1
]
=
'0'
+
i
;
unlink
(
name
);
unlink
(
name
);
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论