Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
224f6598
提交
224f6598
9月 07, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor syscall code
上级
31085bb4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
193 行增加
和
243 行删除
+193
-243
defs.h
defs.h
+5
-6
file.c
file.c
+1
-13
syscall.c
syscall.c
+39
-32
syscall.h
syscall.h
+1
-0
sysfile.c
sysfile.c
+142
-186
sysproc.c
sysproc.c
+5
-6
没有找到文件。
defs.h
浏览文件 @
224f6598
...
...
@@ -16,7 +16,7 @@ struct jmpbuf;
void
setupsegs
(
struct
proc
*
);
struct
proc
*
copyproc
(
struct
proc
*
);
struct
spinlock
;
u
int
growproc
(
int
);
int
growproc
(
int
);
void
sleep
(
void
*
,
struct
spinlock
*
);
void
wakeup
(
void
*
);
void
scheduler
(
void
);
...
...
@@ -43,10 +43,10 @@ int strncmp(const char*, const char*, uint);
// syscall.c
void
syscall
(
void
);
int
fetchint
(
struct
proc
*
,
uint
,
int
*
);
int
fetch
byte
(
struct
proc
*
,
uint
,
char
*
);
int
fetcharg
(
int
,
void
*
);
int
checkstring
(
u
int
);
int
putint
(
struct
proc
*
,
uint
,
int
);
int
fetch
str
(
struct
proc
*
,
uint
,
char
*
*
);
int
argint
(
int
,
int
*
);
int
argptr
(
int
,
char
**
,
int
);
int
argstr
(
int
,
char
**
);
// picirq.c
extern
ushort
irq_mask_8259A
;
...
...
@@ -99,7 +99,6 @@ int pipe_read(struct pipe*, char*, int);
// file.c
struct
stat
;
void
fileinit
(
void
);
int
fdalloc
(
void
);
struct
file
*
filealloc
(
void
);
void
fileclose
(
struct
file
*
);
int
fileread
(
struct
file
*
,
char
*
,
int
n
);
...
...
file.c
浏览文件 @
224f6598
...
...
@@ -22,19 +22,7 @@ fileinit(void)
initlock
(
&
fd_table_lock
,
"fd_table"
);
}
// Allocate a file descriptor number for curproc.
int
fdalloc
(
void
)
{
int
fd
;
struct
proc
*
p
=
curproc
[
cpu
()];
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
if
(
p
->
ofile
[
fd
]
==
0
)
return
fd
;
return
-
1
;
}
// Allocate a file descriptor structure
// Allocate a file structure
struct
file
*
filealloc
(
void
)
{
...
...
syscall.c
浏览文件 @
224f6598
...
...
@@ -21,64 +21,71 @@
// library system call function. The saved user %esp points
// to a saved program counter, and then the first argument.
// Fetch 32 bits from a user-supplied pointer.
// Returns 0 if addr was OK, -1 if illegal.
// Fetch the int at addr from process p.
int
fetchint
(
struct
proc
*
p
,
uint
addr
,
int
*
ip
)
{
*
ip
=
0
;
if
(
addr
>
p
->
sz
-
4
)
if
(
addr
>=
p
->
sz
||
addr
+
4
>
p
->
sz
)
return
-
1
;
*
ip
=
*
(
int
*
)(
p
->
mem
+
addr
);
return
0
;
}
// Fetch byte from a user-supplied pointer.
// Returns 0 on success, -1 if pointer is illegal.
// Fetch the nul-terminated string at addr from process p.
// Doesn't actually copy the string - just sets *pp to point at it.
// Returns length of string, not including nul.
int
fetch
byte
(
struct
proc
*
p
,
uint
addr
,
char
*
c
)
fetch
str
(
struct
proc
*
p
,
uint
addr
,
char
**
pp
)
{
char
*
cp
,
*
ep
;
if
(
addr
>=
p
->
sz
)
return
-
1
;
*
c
=
*
(
p
->
mem
+
addr
);
return
0
;
*
pp
=
p
->
mem
+
addr
;
ep
=
p
->
mem
+
p
->
sz
;
for
(
cp
=
*
pp
;
cp
<
ep
;
cp
++
)
if
(
*
cp
==
0
)
return
cp
-
*
pp
;
return
-
1
;
}
// Fetch the argno'th word-sized system call argument as an integer.
int
fetcharg
(
int
argno
,
void
*
ip
)
argint
(
int
argno
,
int
*
ip
)
{
uint
esp
;
struct
proc
*
p
=
curproc
[
cpu
()]
;
esp
=
(
uint
)
curproc
[
cpu
()]
->
tf
->
esp
;
return
fetchint
(
curproc
[
cpu
()],
esp
+
4
+
4
*
argno
,
ip
);
return
fetchint
(
p
,
p
->
tf
->
esp
+
4
+
4
*
argno
,
ip
);
}
// Check that an entire string is valid in user space.
// Returns the length, not including null, or -1.
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes. Check that the pointer
// lies within the process address space.
int
checkstring
(
uint
s
)
argptr
(
int
argno
,
char
**
pp
,
int
size
)
{
char
c
;
int
len
=
0
;
for
(;;){
if
(
fetchbyte
(
curproc
[
cpu
()],
s
,
&
c
)
<
0
)
return
-
1
;
if
(
c
==
'\0'
)
return
len
;
len
++
;
s
++
;
}
int
i
;
struct
proc
*
p
=
curproc
[
cpu
()];
if
(
argint
(
argno
,
&
i
)
<
0
)
return
-
1
;
if
((
uint
)
i
>=
p
->
sz
||
(
uint
)
i
+
size
>=
p
->
sz
)
return
-
1
;
*
pp
=
p
->
mem
+
i
;
return
0
;
}
// Fetch the nth word-sized system call argument as a string pointer.
// Check that the pointer is valid and the string is nul-terminated.
// (There is no shared writable memory, so the string can't change
// between this check and being used by the kernel.)
int
putint
(
struct
proc
*
p
,
uint
addr
,
int
x
)
argstr
(
int
argno
,
char
**
pp
)
{
if
(
addr
>
p
->
sz
-
4
)
int
addr
;
if
(
argint
(
argno
,
&
addr
)
<
0
)
return
-
1
;
memmove
(
p
->
mem
+
addr
,
&
x
,
4
);
return
0
;
return
fetchstr
(
curproc
[
cpu
()],
addr
,
pp
);
}
extern
int
sys_chdir
(
void
);
...
...
syscall.h
浏览文件 @
224f6598
// System call numbers
#define SYS_fork 1
#define SYS_exit 2
#define SYS_wait 3
...
...
sysfile.c
浏览文件 @
224f6598
差异被折叠。
点击展开。
sysproc.c
浏览文件 @
224f6598
...
...
@@ -44,7 +44,7 @@ sys_kill(void)
{
int
pid
;
if
(
fetcharg
(
0
,
&
pid
)
<
0
)
if
(
argint
(
0
,
&
pid
)
<
0
)
return
-
1
;
return
proc_kill
(
pid
);
}
...
...
@@ -52,20 +52,19 @@ sys_kill(void)
int
sys_getpid
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
return
cp
->
pid
;
return
curproc
[
cpu
()]
->
pid
;
}
int
sys_sbrk
(
void
)
{
u
int
addr
;
int
addr
;
int
n
;
struct
proc
*
cp
=
curproc
[
cpu
()];
if
(
fetcharg
(
0
,
&
n
)
<
0
)
if
(
argint
(
0
,
&
n
)
<
0
)
return
-
1
;
if
((
addr
=
growproc
(
n
))
==
0xffffffff
)
if
((
addr
=
growproc
(
n
))
<
0
)
return
-
1
;
setupsegs
(
cp
);
return
addr
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论