Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
39024ea6
提交
39024ea6
2月 16, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
c++ for lwip
上级
abfb55e2
隐藏空白字符变更
内嵌
并排
正在显示
30 个修改的文件
包含
112 行增加
和
72 行删除
+112
-72
Makefile
Makefile
+1
-0
bio.cc
bio.cc
+1
-2
condvar.cc
condvar.cc
+1
-1
condvar.h
condvar.h
+2
-0
console.cc
console.cc
+14
-1
crange.cc
crange.cc
+1
-1
exec.cc
exec.cc
+1
-1
file.cc
file.cc
+1
-1
fs.cc
fs.cc
+1
-1
gc.cc
gc.cc
+1
-1
hwvm.cc
hwvm.cc
+1
-1
kernel.hh
kernel.hh
+6
-3
kernlet.cc
kernlet.cc
+1
-1
memide.cc
memide.cc
+1
-1
net.cc
net.cc
+1
-5
cc.h
net/arch/cc.h
+4
-5
if.cc
net/if.cc
+8
-5
sys_arch.cc
net/sys_arch.cc
+30
-6
pipe.cc
pipe.cc
+1
-1
proc.cc
proc.cc
+4
-4
prof.cc
prof.cc
+1
-1
sampler.cc
sampler.cc
+1
-1
sched.cc
sched.cc
+1
-1
spinlock.cc
spinlock.cc
+1
-1
syscall.cc
syscall.cc
+1
-1
sysfile.cc
sysfile.cc
+1
-1
sysproc.cc
sysproc.cc
+1
-1
trap.cc
trap.cc
+1
-1
vm.cc
vm.cc
+21
-21
vm.hh
vm.hh
+2
-2
没有找到文件。
Makefile
浏览文件 @
39024ea6
...
@@ -126,6 +126,7 @@ $(O)/kernel: $(O) $(O)/boot.o $(OBJS)
...
@@ -126,6 +126,7 @@ $(O)/kernel: $(O) $(O)/boot.o $(OBJS)
$(O)
:
$(O)
:
$(Q)
mkdir
$(O)
$(Q)
mkdir
$(O)
$(Q)
mkdir
$(O)
/net
$(O)/%.o
:
%.c
$(O)/%.o
:
%.c
@
echo
" CC
$@
"
@
echo
" CC
$@
"
...
...
bio.cc
浏览文件 @
39024ea6
...
@@ -24,8 +24,7 @@
...
@@ -24,8 +24,7 @@
#include "types.h"
#include "types.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.hh"
#include "condvar.h"
#include "buf.hh"
#include "buf.hh"
#include "cpputil.hh"
#include "cpputil.hh"
#include "ns.hh"
#include "ns.hh"
...
...
condvar.cc
浏览文件 @
39024ea6
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "amd64.h"
#include "amd64.h"
#include "mmu.h"
#include "mmu.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "kernel.hh"
#include "kernel.hh"
...
...
condvar.h
h
→
condvar.h
浏览文件 @
39024ea6
#pragma once
#include "queue.h"
#include "queue.h"
struct
condvar
{
struct
condvar
{
...
...
console.cc
浏览文件 @
39024ea6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "fs.h"
#include "fs.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "file.hh"
#include "file.hh"
#include "amd64.h"
#include "amd64.h"
#include "queue.h"
#include "queue.h"
...
@@ -122,6 +122,19 @@ cprintf(const char *fmt, ...)
...
@@ -122,6 +122,19 @@ cprintf(const char *fmt, ...)
}
}
void
void
vcprintf
(
const
char
*
fmt
,
va_list
ap
)
{
int
locking
=
cons
.
locking
;
if
(
locking
)
acquire
(
&
cons
.
lock
);
vprintfmt
(
writecons
,
0
,
fmt
,
ap
);
if
(
locking
)
release
(
&
cons
.
lock
);
}
void
puts
(
const
char
*
s
)
puts
(
const
char
*
s
)
{
{
u8
*
p
,
*
ep
;
u8
*
p
,
*
ep
;
...
...
crange.cc
浏览文件 @
39024ea6
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "kernel.hh"
#include "kernel.hh"
#include "mmu.h"
#include "mmu.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "cpu.hh"
#include "cpu.hh"
...
...
exec.cc
浏览文件 @
39024ea6
#include "types.h"
#include "types.h"
#include "mmu.h"
#include "mmu.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "kernel.hh"
#include "kernel.hh"
...
...
file.cc
浏览文件 @
39024ea6
#include "types.h"
#include "types.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "kernel.hh"
#include "kernel.hh"
#include "fs.h"
#include "fs.h"
#include "file.hh"
#include "file.hh"
...
...
fs.cc
浏览文件 @
39024ea6
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "mmu.h"
#include "mmu.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "fs.h"
#include "fs.h"
...
...
gc.cc
浏览文件 @
39024ea6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "mmu.h"
#include "mmu.h"
#include "amd64.h"
#include "amd64.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "cpu.hh"
#include "cpu.hh"
...
...
hwvm.cc
浏览文件 @
39024ea6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "spinlock.h"
#include "spinlock.h"
#include "kalloc.h"
#include "kalloc.h"
#include "queue.h"
#include "queue.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "proc.hh"
#include "proc.hh"
#include "vm.hh"
#include "vm.hh"
#include <stddef.h>
#include <stddef.h>
...
...
kernel.hh
浏览文件 @
39024ea6
...
@@ -2,6 +2,8 @@ extern "C" {
...
@@ -2,6 +2,8 @@ extern "C" {
#include "kern_c.h"
#include "kern_c.h"
}
}
#include <stdarg.h>
#define KBASE 0xFFFFFF0000000000ull
#define KBASE 0xFFFFFF0000000000ull
#define KSHARED 0xFFFFF00000000000ull
#define KSHARED 0xFFFFF00000000000ull
#define USERTOP 0x0000800000000000ull
#define USERTOP 0x0000800000000000ull
...
@@ -48,6 +50,7 @@ void cv_tick(void);
...
@@ -48,6 +50,7 @@ void cv_tick(void);
// console.c
// console.c
void
cprintf
(
const
char
*
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
void
cprintf
(
const
char
*
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
void
vcprintf
(
const
char
*
fmt
,
va_list
ap
);
void
panic
(
const
char
*
,
...)
void
panic
(
const
char
*
,
...)
__noret__
__attribute__
((
format
(
printf
,
1
,
2
)));
__noret__
__attribute__
((
format
(
printf
,
1
,
2
)));
void
kerneltrap
(
struct
trapframe
*
tf
)
__noret__
;
void
kerneltrap
(
struct
trapframe
*
tf
)
__noret__
;
...
@@ -221,10 +224,10 @@ void syscall(void);
...
@@ -221,10 +224,10 @@ void syscall(void);
// string.c
// string.c
int
memcmp
(
const
void
*
,
const
void
*
,
u32
);
int
memcmp
(
const
void
*
,
const
void
*
,
u32
);
void
*
memmove
(
void
*
,
const
void
*
,
u32
);
void
*
memmove
(
void
*
,
const
void
*
,
u32
);
void
*
memset
(
void
*
,
int
,
u32
);
extern
"C"
void
*
memset
(
void
*
,
int
,
u32
);
void
*
memcpy
(
void
*
,
const
void
*
,
u32
);
extern
"C"
void
*
memcpy
(
void
*
,
const
void
*
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
u32
);
extern
"C"
unsigned
int
strlen
(
const
char
*
);
extern
"C"
unsigned
int
strlen
(
const
char
*
);
int
strncmp
(
const
char
*
,
const
char
*
,
u32
);
int
strncmp
(
const
char
*
,
const
char
*
,
u32
);
char
*
strncpy
(
char
*
,
const
char
*
,
u32
);
char
*
strncpy
(
char
*
,
const
char
*
,
u32
);
int
strcmp
(
const
char
*
p
,
const
char
*
q
);
int
strcmp
(
const
char
*
p
,
const
char
*
q
);
...
...
kernlet.cc
浏览文件 @
39024ea6
#include "types.h"
#include "types.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "cpu.hh"
#include "cpu.hh"
#include "proc.hh"
#include "proc.hh"
#include "fs.h"
#include "fs.h"
...
...
memide.cc
浏览文件 @
39024ea6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "queue.h"
#include "queue.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "proc.hh"
#include "proc.hh"
#include "amd64.h"
#include "amd64.h"
#include "traps.h"
#include "traps.h"
...
...
net.cc
浏览文件 @
39024ea6
...
@@ -13,20 +13,16 @@ extern "C" {
...
@@ -13,20 +13,16 @@ extern "C" {
#include "types.h"
#include "types.h"
#include "kernel.hh"
#include "kernel.hh"
#include "queue.h"
#include "queue.h"
#ifndef LWIP
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.hh"
#include "condvar.h"
#endif
#include "proc.hh"
#include "proc.hh"
#include "fs.h"
#include "fs.h"
#include "file.hh"
#include "file.hh"
#include "net.hh"
#include "net.hh"
#ifdef LWIP
#ifdef LWIP
extern
"C"
{
err_t
if_init
(
struct
netif
*
netif
);
err_t
if_init
(
struct
netif
*
netif
);
void
if_input
(
struct
netif
*
netif
,
void
*
buf
,
u16
len
);
void
if_input
(
struct
netif
*
netif
,
void
*
buf
,
u16
len
);
}
#endif
#endif
void
void
...
...
net/arch/cc.h
浏览文件 @
39024ea6
...
@@ -3,9 +3,8 @@
...
@@ -3,9 +3,8 @@
#include <types.h>
#include <types.h>
void
cprintf
(
const
char
*
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
void
lwip_cprintf
(
const
char
*
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
void
panic
(
const
char
*
,
...)
void
lwip_panic
(
const
char
*
,
...)
__noret__
__attribute__
((
format
(
printf
,
1
,
2
)));
__noret__
__attribute__
((
format
(
printf
,
1
,
2
)));
typedef
u32
u32_t
;
typedef
u32
u32_t
;
typedef
s32
s32_t
;
typedef
s32
s32_t
;
...
@@ -34,8 +33,8 @@ typedef uptr mem_ptr_t;
...
@@ -34,8 +33,8 @@ typedef uptr mem_ptr_t;
#define U32_F "u"
#define U32_F "u"
#define X32_F "x"
#define X32_F "x"
#define LWIP_PLATFORM_DIAG(x) cprintf x
#define LWIP_PLATFORM_DIAG(x)
lwip_
cprintf x
#define LWIP_PLATFORM_ASSERT(x) panic(x)
#define LWIP_PLATFORM_ASSERT(x)
lwip_
panic(x)
#ifndef BYTE_ORDER
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#define BYTE_ORDER LITTLE_ENDIAN
...
...
net/if.c
→
net/if.c
c
浏览文件 @
39024ea6
extern
"C"
{
#include "lwip/stats.h"
#include "lwip/stats.h"
#include "netif/etharp.h"
#include "netif/etharp.h"
#include "kernel.h"
}
#include "kernel.hh"
/**
/**
* In this function, the hardware should be initialized.
* In this function, the hardware should be initialized.
...
@@ -52,7 +55,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
...
@@ -52,7 +55,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
u8
*
buf
;
u8
*
buf
;
size
=
0
;
size
=
0
;
buf
=
netalloc
();
buf
=
(
u8
*
)
netalloc
();
if
(
buf
==
NULL
)
{
if
(
buf
==
NULL
)
{
cprintf
(
"low_level_output: netalloc failed
\n
"
);
cprintf
(
"low_level_output: netalloc failed
\n
"
);
return
ERR_MEM
;
return
ERR_MEM
;
...
@@ -122,7 +125,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len)
...
@@ -122,7 +125,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len)
int
bytes
=
q
->
len
;
int
bytes
=
q
->
len
;
if
(
bytes
>
(
len
-
copied
))
if
(
bytes
>
(
len
-
copied
))
bytes
=
len
-
copied
;
bytes
=
len
-
copied
;
memmove
(
q
->
payload
,
buf
+
copied
,
bytes
);
memmove
(
q
->
payload
,
(
char
*
)
buf
+
copied
,
bytes
);
copied
+=
bytes
;
copied
+=
bytes
;
}
}
...
@@ -160,7 +163,7 @@ if_input(struct netif *netif, void *buf, u16 len)
...
@@ -160,7 +163,7 @@ if_input(struct netif *netif, void *buf, u16 len)
/* no packet could be read, silently ignore this */
/* no packet could be read, silently ignore this */
if
(
p
==
NULL
)
return
;
if
(
p
==
NULL
)
return
;
/* points to packet payload, which starts with an Ethernet header */
/* points to packet payload, which starts with an Ethernet header */
ethhdr
=
p
->
payload
;
ethhdr
=
(
eth_hdr
*
)
p
->
payload
;
switch
(
htons
(
ethhdr
->
type
))
{
switch
(
htons
(
ethhdr
->
type
))
{
/* IP or ARP packet? */
/* IP or ARP packet? */
...
@@ -175,7 +178,7 @@ if_input(struct netif *netif, void *buf, u16 len)
...
@@ -175,7 +178,7 @@ if_input(struct netif *netif, void *buf, u16 len)
if
(
VERBOSE
)
if
(
VERBOSE
)
cprintf
(
"if_input: unknown type %04x
\n
"
,
htons
(
ethhdr
->
type
));
cprintf
(
"if_input: unknown type %04x
\n
"
,
htons
(
ethhdr
->
type
));
pbuf_free
(
p
);
pbuf_free
(
p
);
p
=
NULL
;
p
=
0
;
break
;
break
;
}
}
}
}
...
...
net/sys_arch.c
→
net/sys_arch.c
c
浏览文件 @
39024ea6
extern
"C"
{
#include "lwip/sys.h"
#include "lwip/sys.h"
#include "arch/sys_arch.h"
#include "arch/sys_arch.h"
}
#include "queue.h"
#include "queue.h"
#include "kernel.h"
#include "kernel.h
h
"
#include "proc.h"
#include "proc.h
h
"
#include "cpu.h"
#include "cpu.h
h
"
#define DIE panic(__func__)
#define DIE panic(__func__)
...
@@ -192,7 +194,7 @@ struct lwip_thread {
...
@@ -192,7 +194,7 @@ struct lwip_thread {
static
void
static
void
lwip_thread
(
void
*
x
)
lwip_thread
(
void
*
x
)
{
{
struct
lwip_thread
*
lt
=
x
;
struct
lwip_thread
*
lt
=
(
struct
lwip_thread
*
)
x
;
lwip_core_lock
();
lwip_core_lock
();
lt
->
thread
(
lt
->
arg
);
lt
->
thread
(
lt
->
arg
);
lwip_core_unlock
();
lwip_core_unlock
();
...
@@ -206,9 +208,9 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
...
@@ -206,9 +208,9 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
struct
lwip_thread
*
lt
;
struct
lwip_thread
*
lt
;
struct
proc
*
p
;
struct
proc
*
p
;
lt
=
kmalloc
(
sizeof
(
*
lt
));
lt
=
(
struct
lwip_thread
*
)
kmalloc
(
sizeof
(
*
lt
));
if
(
lt
==
NULL
)
if
(
lt
==
NULL
)
return
NULL
;
return
0
;
lt
->
thread
=
thread
;
lt
->
thread
=
thread
;
lt
->
arg
=
arg
;
lt
->
arg
=
arg
;
...
@@ -259,3 +261,25 @@ lwip_core_init(void)
...
@@ -259,3 +261,25 @@ lwip_core_init(void)
{
{
initlock
(
&
lwprot
.
lk
,
"lwIP lwprot"
,
1
);
initlock
(
&
lwprot
.
lk
,
"lwIP lwprot"
,
1
);
}
}
void
lwip_panic
(
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vcprintf
(
fmt
,
ap
);
va_end
(
ap
);
panic
(
"LWIP panic"
);
}
void
lwip_cprintf
(
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vcprintf
(
fmt
,
ap
);
va_end
(
ap
);
}
pipe.cc
浏览文件 @
39024ea6
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "mmu.h"
#include "mmu.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "fs.h"
#include "fs.h"
...
...
proc.cc
浏览文件 @
39024ea6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "mmu.h"
#include "mmu.h"
#include "amd64.h"
#include "amd64.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "cpu.hh"
#include "cpu.hh"
...
@@ -427,13 +427,13 @@ growproc(int n)
...
@@ -427,13 +427,13 @@ growproc(int n)
vma
*
e
=
m
->
lookup
(
newstart
,
1
);
vma
*
e
=
m
->
lookup
(
newstart
,
1
);
if
(
e
==
0
)
if
(
e
==
0
)
break
;
break
;
if
(
e
->
va_end
>=
newstart
+
newn
){
if
(
e
->
v
m
a_end
>=
newstart
+
newn
){
newstart
+=
newn
;
newstart
+=
newn
;
newn
=
0
;
newn
=
0
;
break
;
break
;
}
}
newn
-=
e
->
va_end
-
newstart
;
newn
-=
e
->
v
m
a_end
-
newstart
;
newstart
=
e
->
va_end
;
newstart
=
e
->
v
m
a_end
;
}
}
gc_end_epoch
();
gc_end_epoch
();
...
...
prof.cc
浏览文件 @
39024ea6
#include "types.h"
#include "types.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "fs.h"
#include "fs.h"
#include "file.hh"
#include "file.hh"
#include "prof.hh"
#include "prof.hh"
...
...
sampler.cc
浏览文件 @
39024ea6
#include "types.h"
#include "types.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "fs.h"
#include "fs.h"
#include "kernel.hh"
#include "kernel.hh"
#include "stat.h"
#include "stat.h"
...
...
sched.cc
浏览文件 @
39024ea6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "mmu.h"
#include "mmu.h"
#include "amd64.h"
#include "amd64.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "cpu.hh"
#include "cpu.hh"
...
...
spinlock.cc
浏览文件 @
39024ea6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "bits.hh"
#include "bits.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "mtrace.h"
#include "mtrace.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "fs.h"
#include "fs.h"
#include "file.hh"
#include "file.hh"
...
...
syscall.cc
浏览文件 @
39024ea6
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "mmu.h"
#include "mmu.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "amd64.h"
#include "amd64.h"
...
...
sysfile.cc
浏览文件 @
39024ea6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "mmu.h"
#include "mmu.h"
#include "kernel.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "fs.h"
#include "fs.h"
...
...
sysproc.cc
浏览文件 @
39024ea6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "kernel.hh"
#include "kernel.hh"
#include "mmu.h"
#include "mmu.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.hh"
#include "proc.hh"
#include "cpu.hh"
#include "cpu.hh"
...
...
trap.cc
浏览文件 @
39024ea6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include "traps.h"
#include "traps.h"
#include "queue.h"
#include "queue.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "proc.hh"
#include "proc.hh"
#include "kmtrace.hh"
#include "kmtrace.hh"
#include "bits.hh"
#include "bits.hh"
...
...
vm.cc
浏览文件 @
39024ea6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "spinlock.h"
#include "spinlock.h"
#include "kalloc.h"
#include "kalloc.h"
#include "queue.h"
#include "queue.h"
#include "condvar.h
h
"
#include "condvar.h"
#include "proc.hh"
#include "proc.hh"
#include "vm.hh"
#include "vm.hh"
#include "gc.hh"
#include "gc.hh"
...
@@ -120,7 +120,7 @@ vmnode::load(inode *iparg, u64 offarg, u64 szarg)
...
@@ -120,7 +120,7 @@ vmnode::load(inode *iparg, u64 offarg, u64 szarg)
*/
*/
vma
::
vma
()
vma
::
vma
()
:
rcu_freed
(
"vma"
),
v
a_start
(
0
),
v
a_end
(
0
),
va_type
(
PRIVATE
),
n
(
0
)
:
rcu_freed
(
"vma"
),
v
ma_start
(
0
),
vm
a_end
(
0
),
va_type
(
PRIVATE
),
n
(
0
)
{
{
snprintf
(
lockname
,
sizeof
(
lockname
),
"vma:%p"
,
this
);
snprintf
(
lockname
,
sizeof
(
lockname
),
"vma:%p"
,
this
);
initlock
(
&
lock
,
lockname
,
LOCKSTAT_VM
);
initlock
(
&
lock
,
lockname
,
LOCKSTAT_VM
);
...
@@ -210,15 +210,15 @@ vmap::copy(int share)
...
@@ -210,15 +210,15 @@ vmap::copy(int share)
if
(
ne
==
0
)
if
(
ne
==
0
)
goto
err
;
goto
err
;
ne
->
v
a_start
=
e
->
v
a_start
;
ne
->
v
ma_start
=
e
->
vm
a_start
;
ne
->
v
a_end
=
e
->
v
a_end
;
ne
->
v
ma_end
=
e
->
vm
a_end
;
if
(
share
)
{
if
(
share
)
{
ne
->
n
=
e
->
n
;
ne
->
n
=
e
->
n
;
ne
->
va_type
=
COW
;
ne
->
va_type
=
COW
;
scoped_acquire
sae
(
&
e
->
lock
);
scoped_acquire
sae
(
&
e
->
lock
);
e
->
va_type
=
COW
;
e
->
va_type
=
COW
;
updatepages
(
pml4
,
(
void
*
)
(
e
->
v
a_start
),
(
void
*
)
(
e
->
v
a_end
),
PTE_COW
);
updatepages
(
pml4
,
(
void
*
)
(
e
->
v
ma_start
),
(
void
*
)
(
e
->
vm
a_end
),
PTE_COW
);
}
else
{
}
else
{
ne
->
n
=
e
->
n
->
copy
();
ne
->
n
=
e
->
n
->
copy
();
ne
->
va_type
=
e
->
va_type
;
ne
->
va_type
=
e
->
va_type
;
...
@@ -228,7 +228,7 @@ vmap::copy(int share)
...
@@ -228,7 +228,7 @@ vmap::copy(int share)
goto
err
;
goto
err
;
ne
->
n
->
ref
++
;
ne
->
n
->
ref
++
;
nm
->
cr
.
add
(
ne
->
v
a_start
,
ne
->
va_end
-
ne
->
v
a_start
,
(
void
*
)
ne
);
nm
->
cr
.
add
(
ne
->
v
ma_start
,
ne
->
vma_end
-
ne
->
vm
a_start
,
(
void
*
)
ne
);
}
}
if
(
share
)
if
(
share
)
...
@@ -256,9 +256,9 @@ vmap::lookup(uptr start, uptr len)
...
@@ -256,9 +256,9 @@ vmap::lookup(uptr start, uptr len)
range
*
r
=
cr
.
search
(
start
,
len
);
range
*
r
=
cr
.
search
(
start
,
len
);
if
(
r
!=
0
)
{
if
(
r
!=
0
)
{
vma
*
e
=
(
struct
vma
*
)
(
r
->
value
);
vma
*
e
=
(
struct
vma
*
)
(
r
->
value
);
if
(
e
->
v
a_end
<=
e
->
v
a_start
)
if
(
e
->
v
ma_end
<=
e
->
vm
a_start
)
panic
(
"malformed va"
);
panic
(
"malformed va"
);
if
(
e
->
v
a_start
<
start
+
len
&&
e
->
v
a_end
>
start
)
if
(
e
->
v
ma_start
<
start
+
len
&&
e
->
vm
a_end
>
start
)
return
e
;
return
e
;
}
}
...
@@ -266,12 +266,12 @@ vmap::lookup(uptr start, uptr len)
...
@@ -266,12 +266,12 @@ vmap::lookup(uptr start, uptr len)
}
}
int
int
vmap
::
insert
(
vmnode
*
n
,
uptr
va_start
)
vmap
::
insert
(
vmnode
*
n
,
uptr
v
m
a_start
)
{
{
scoped_acquire
sa
(
&
lock
);
scoped_acquire
sa
(
&
lock
);
u64
len
=
n
->
npages
*
PGSIZE
;
u64
len
=
n
->
npages
*
PGSIZE
;
if
(
lookup
(
va_start
,
len
))
{
if
(
lookup
(
v
m
a_start
,
len
))
{
cprintf
(
"vmap_insert: overlap
\n
"
);
cprintf
(
"vmap_insert: overlap
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -280,28 +280,28 @@ vmap::insert(vmnode *n, uptr va_start)
...
@@ -280,28 +280,28 @@ vmap::insert(vmnode *n, uptr va_start)
if
(
e
==
0
)
if
(
e
==
0
)
return
-
1
;
return
-
1
;
e
->
v
a_start
=
v
a_start
;
e
->
v
ma_start
=
vm
a_start
;
e
->
v
a_end
=
v
a_start
+
len
;
e
->
v
ma_end
=
vm
a_start
+
len
;
e
->
n
=
n
;
e
->
n
=
n
;
n
->
ref
++
;
n
->
ref
++
;
cr
.
add
(
e
->
va_start
,
len
,
(
void
*
)
e
);
cr
.
add
(
e
->
v
m
a_start
,
len
,
(
void
*
)
e
);
return
0
;
return
0
;
}
}
int
int
vmap
::
remove
(
uptr
va_start
,
uptr
len
)
vmap
::
remove
(
uptr
v
m
a_start
,
uptr
len
)
{
{
scoped_acquire
sa
(
&
lock
);
scoped_acquire
sa
(
&
lock
);
uptr
v
a_end
=
v
a_start
+
len
;
uptr
v
ma_end
=
vm
a_start
+
len
;
struct
range
*
r
=
cr
.
search
(
va_start
,
len
);
struct
range
*
r
=
cr
.
search
(
v
m
a_start
,
len
);
if
(
r
==
0
)
if
(
r
==
0
)
panic
(
"no vma?"
);
panic
(
"no vma?"
);
struct
vma
*
e
=
(
struct
vma
*
)
r
->
value
;
struct
vma
*
e
=
(
struct
vma
*
)
r
->
value
;
if
(
e
->
v
a_start
!=
va_start
||
e
->
va_end
!=
v
a_end
)
{
if
(
e
->
v
ma_start
!=
vma_start
||
e
->
vma_end
!=
vm
a_end
)
{
cprintf
(
"vmap_remove: partial unmap unsupported
\n
"
);
cprintf
(
"vmap_remove: partial unmap unsupported
\n
"
);
return
-
1
;
return
-
1
;
}
}
cr
.
del
(
va_start
,
len
);
cr
.
del
(
v
m
a_start
,
len
);
gc_delayed
(
e
);
gc_delayed
(
e
);
return
0
;
return
0
;
}
}
...
@@ -341,7 +341,7 @@ vmap::pagefault_wcow(uptr va, pme_t *pte, vma *m, u64 npg)
...
@@ -341,7 +341,7 @@ vmap::pagefault_wcow(uptr va, pme_t *pte, vma *m, u64 npg)
m
->
va_type
=
PRIVATE
;
m
->
va_type
=
PRIVATE
;
m
->
n
=
c
;
m
->
n
=
c
;
// Update the hardware page tables to reflect the change to the vma
// Update the hardware page tables to reflect the change to the vma
updatepages
(
pml4
,
(
void
*
)
m
->
v
a_start
,
(
void
*
)
m
->
v
a_end
,
0
);
updatepages
(
pml4
,
(
void
*
)
m
->
v
ma_start
,
(
void
*
)
m
->
vm
a_end
,
0
);
pte
=
walkpgdir
(
pml4
,
(
const
void
*
)
va
,
0
);
pte
=
walkpgdir
(
pml4
,
(
const
void
*
)
va
,
0
);
*
pte
=
v2p
(
m
->
n
->
page
[
npg
])
|
PTE_P
|
PTE_U
|
PTE_W
;
*
pte
=
v2p
(
m
->
n
->
page
[
npg
])
|
PTE_P
|
PTE_U
|
PTE_W
;
// drop my ref to vmnode
// drop my ref to vmnode
...
@@ -364,7 +364,7 @@ vmap::pagefault(uptr va, u32 err)
...
@@ -364,7 +364,7 @@ vmap::pagefault(uptr va, u32 err)
return
-
1
;
return
-
1
;
acquire
(
&
m
->
lock
);
acquire
(
&
m
->
lock
);
u64
npg
=
(
PGROUNDDOWN
(
va
)
-
m
->
va_start
)
/
PGSIZE
;
u64
npg
=
(
PGROUNDDOWN
(
va
)
-
m
->
v
m
a_start
)
/
PGSIZE
;
if
(
m
->
n
&&
m
->
n
->
type
==
ONDEMAND
&&
m
->
n
->
page
[
npg
]
==
0
)
if
(
m
->
n
&&
m
->
n
->
type
==
ONDEMAND
&&
m
->
n
->
page
[
npg
]
==
0
)
m
=
pagefault_ondemand
(
va
,
err
,
m
);
m
=
pagefault_ondemand
(
va
,
err
,
m
);
...
@@ -412,7 +412,7 @@ vmap::copyout(uptr va, void *p, u64 len)
...
@@ -412,7 +412,7 @@ vmap::copyout(uptr va, void *p, u64 len)
return
-
1
;
return
-
1
;
acquire
(
&
vma
->
lock
);
acquire
(
&
vma
->
lock
);
uptr
pn
=
(
va0
-
vma
->
va_start
)
/
PGSIZE
;
uptr
pn
=
(
va0
-
vma
->
v
m
a_start
)
/
PGSIZE
;
char
*
p0
=
vma
->
n
->
page
[
pn
];
char
*
p0
=
vma
->
n
->
page
[
pn
];
if
(
p0
==
0
)
if
(
p0
==
0
)
panic
(
"copyout: missing page"
);
panic
(
"copyout: missing page"
);
...
...
vm.hh
浏览文件 @
39024ea6
...
@@ -31,8 +31,8 @@ struct vmnode {
...
@@ -31,8 +31,8 @@ struct vmnode {
enum
vmatype
{
PRIVATE
,
COW
};
enum
vmatype
{
PRIVATE
,
COW
};
struct
vma
:
public
rcu_freed
{
struct
vma
:
public
rcu_freed
{
uptr
v
a_start
;
// start of mapping
uptr
v
ma_start
;
// start of mapping
uptr
v
a_end
;
// one past the last byte
uptr
v
ma_end
;
// one past the last byte
enum
vmatype
va_type
;
enum
vmatype
va_type
;
struct
vmnode
*
n
;
struct
vmnode
*
n
;
struct
spinlock
lock
;
// serialize fault/unmap
struct
spinlock
lock
;
// serialize fault/unmap
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论