Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rand #48

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Rand #48

Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c69319b
semaphore 1.0
Rand312 May 4, 2022
193e5ea
Initial commit
Rand312 May 4, 2022
0dec94e
删除文件 README.en.md
Rand312 May 4, 2022
6076643
删除文件 README.md
Rand312 May 4, 2022
225699d
Merge branch 'master' of https://gitee.com/rand_cs/xv6-rust
Rand312 May 4, 2022
ad93b38
fifo, need debug
Rand312 May 12, 2022
74f7c78
thread_not_modify_pagetable tmp
Rand312 May 13, 2022
e617bc7
thread faild, next reconstruct process
Rand312 May 14, 2022
85b250e
thread 5.17
Rand312 May 17, 2022
a20fc56
fifo 5.17
Rand312 May 17, 2022
fd2f7c3
debug fifo 5.17.1
Rand312 May 17, 2022
13ca1ea
fifo debug size
Rand312 May 17, 2022
1182019
try detatch lock and pipe
Rand312 May 17, 2022
a2a06b4
pipe,find bug,try kill
Rand312 May 18, 2022
899be9f
pipe success
Rand312 May 18, 2022
5231107
pipe fifo bingo
Rand312 May 18, 2022
829d294
kernel_thread bingo
Rand312 May 19, 2022
ba7f08c
user thread bingo
Rand312 May 21, 2022
f745d8b
Lazy Allocation, bug : is addr valid check
Rand312 May 22, 2022
171e274
COW 1.0 bug: some remap
Rand312 May 22, 2022
1dc0da7
add xv6-user
Rand312 May 23, 2022
374a718
xv6-user
Rand312 May 23, 2022
594cb05
add xv6-user submodule
Rand312 May 23, 2022
0b272c3
add xv6-user
Rand312 May 23, 2022
2adf466
add asm file
Rand312 May 23, 2022
cf4d33f
add xv6-user
Rand312 May 23, 2022
3f9cc0b
Initial commit
May 27, 2022
058eca6
msg bingo
Rand312 May 28, 2022
0264f1f
share memory bingo
Rand312 May 28, 2022
bf74304
push to gitlab
Rand312 Jun 4, 2022
53f724a
modify README.md
Rand312 Jun 4, 2022
a87b268
modify huanjingdajian.pdf
Rand312 Jun 4, 2022
eb06351
modify README design doc
Rand312 Jun 5, 2022
217f310
fix picture
Rand312 Jun 16, 2022
84f7d0b
fix conflict 2
Rand312 Jun 16, 2022
c605d68
decider
Rand312 Aug 15, 2022
8fee816
delete useless files
Aug 30, 2022
d3d4838
delete useless files
Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix picture
Rand312 committed Jun 16, 2022
commit 217f310b4adcc1689130f117b316df3aa8b0ca40
2 changes: 1 addition & 1 deletion .vscode/configurationCache.log

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .vscode/dryrun.log
Original file line number Diff line number Diff line change
@@ -2,6 +2,5 @@ make --dry-run --keep-going --print-directory
make: Entering directory '/home/rand/xv6-rust'

make -C kernel run

make: Leaving directory '/home/rand/xv6-rust'

44 changes: 25 additions & 19 deletions .vscode/targets.log
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ make: *** No rule to make target 'all'. Stop.
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.

# Make data base, printed on Sat May 28 20:46:15 2022
# Make data base, printed on Mon Jun 6 11:38:43 2022

# Variables

@@ -131,7 +131,7 @@ XDG_SESSION_DESKTOP = ubuntu
# environment
SSH_AUTH_SOCK = /run/user/1000/keyring/ssh
# environment
GIO_LAUNCHED_DESKTOP_FILE_PID = 2601
GIO_LAUNCHED_DESKTOP_FILE_PID = 71603
# automatic
%F = $(notdir $%)
# environment
@@ -199,7 +199,7 @@ CC = riscv64-unknown-elf-gcc
# environment
GNOME_SHELL_SESSION_MODE = ubuntu
# environment
VSCODE_IPC_HOOK_EXTHOST = /run/user/1000/vscode-ipc-decc2bba-912c-42f1-9ef1-4bec104c8303.sock
VSCODE_IPC_HOOK_EXTHOST = /run/user/1000/vscode-ipc-0ad2b37c-bce8-4ccf-8d31-e20adf2c6c74.sock
# default
MAKE_VERSION := 4.2.1
# makefile (from 'Makefile', line 2)
@@ -228,7 +228,6 @@ MAKE_COMMAND := make
LANGUAGE = zh_CN:zh
# environment
VSCODE_IPC_HOOK = /run/user/1000/vscode-f2998c1d-1.67.2-main.sock

# environment
BAMF_DESKTOP_FILE_HINT = /var/lib/snapd/desktop/applications/code_code.desktop
# makefile
@@ -268,7 +267,7 @@ OBJCOPY = riscv64-unknown-elf-objcopy
# default
SUFFIXES :=
# makefile (from 'Makefile', line 108)
UPROGS = $(USER)/_init $(USER)/_sh $(USER)/_echo $(USER)/_ls $(USER)/_mkdir $(USER)/_touch $(USER)/_cat $(USER)/_rm $(USER)/_forktest $(USER)/_stressfs $(USER)/_sem_test1 $(USER)/_sem_test2 $(USER)/_thread_test $(USER)/_malloc_test $(USER)/_fork_test $(USER)/_fifo_test1 $(USER)/_fifo_test2 $(USER)/_pipe_test $(USER)/_uthreadtest $(USER)/_msgtest1 $(USER)/_msgtest2 $(USER)/_shmtest1 $(USER)/_shmtest2
UPROGS = $(USER)/_init $(USER)/_sh $(USER)/_echo $(USER)/_ls $(USER)/_mkdir $(USER)/_touch $(USER)/_cat $(USER)/_rm $(USER)/_wc $(USER)/_forktest $(USER)/_stressfs $(USER)/_sem_test1 $(USER)/_sem_test2 $(USER)/_thread_test $(USER)/_malloc_test $(USER)/_fork_test $(USER)/_fifo_test1 $(USER)/_fifo_test2 $(USER)/_pipe_test $(USER)/_uthreadtest $(USER)/_msgtest1 $(USER)/_msgtest2 $(USER)/_shmtest1 $(USER)/_shmtest2
# environment
SNAP_REEXEC =
# environment
@@ -279,23 +278,24 @@ WINDOWPATH = 2
.INCLUDE_DIRS = /usr/include /usr/local/include /usr/include
# environment
GJS_DEBUG_OUTPUT = stderr

# default
.RECIPEPREFIX :=
# environment
LANG = C
# environment
VSCODE_PID = 2645
VSCODE_PID = 71647
# variable set hash-table stats:
# Load=136/1024=13%, Rehash=0, Collisions=24/254=9%
# Load=136/1024=13%, Rehash=0, Collisions=24/255=9%

# Pattern-specific Variable Values

# No pattern-specific variable values.

# Directories

# user (device 2053, inode 955528): 9 files, no impossibilities.
# . (device 2053, inode 677081): 23 files, no impossibilities.
# user (device 2053, inode 303738): 9 files, no impossibilities.
# . (device 2053, inode 303342): 23 files, no impossibilities.

# 32 files, no impossibilities in 2 directories.

@@ -317,6 +317,12 @@ xv6-user/_malloc_test:
# Modification time never checked.
# File has not been updated.

# Not a target:
xv6-user/_wc:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.

# Not a target:
xv6-user/_shmtest2:
# Implicit rule search has not been done.
@@ -432,7 +438,7 @@ kernel/target/riscv64gc-unknown-none-elf/debug/kernel:
# Not a target:
Makefile:
# Implicit rule search has been done.
# Last modified 2022-05-28 20:45:43.935035161
# Last modified 2022-06-06 11:38:03.195113361
# File has been updated.
# Successfully updated.

@@ -504,12 +510,11 @@ xv6-user/uthread/setcontext.S:
# Modification time never checked.
# File has not been updated.

fs.img: xv6-mkfs/mkfs README.md xv6-user/_init xv6-user/_sh xv6-user/_echo xv6-user/_ls xv6-user/_mkdir xv6-user/_touch xv6-user/_cat xv6-user/_rm xv6-user/_forktest xv6-user/_stressfs xv6-user/_sem_test1 xv6-user/_sem_test2 xv6-user/_thread_test xv6-user/_malloc_test xv6-user/_fork_test xv6-user/_fifo_test1 xv6-user/_fifo_test2 xv6-user/_pipe_test xv6-user/_uthreadtest xv6-user/_msgtest1 xv6-user/_msgtest2 xv6-user/_shmtest1 xv6-user/_shmtest2
fs.img: xv6-mkfs/mkfs README.md xv6-user/_init xv6-user/_sh xv6-user/_echo xv6-user/_ls xv6-user/_mkdir xv6-user/_touch xv6-user/_cat xv6-user/_rm xv6-user/_wc xv6-user/_forktest xv6-user/_stressfs xv6-user/_sem_test1 xv6-user/_sem_test2 xv6-user/_thread_test xv6-user/_malloc_test xv6-user/_fork_test xv6-user/_fifo_test1 xv6-user/_fifo_test2 xv6-user/_pipe_test xv6-user/_uthreadtest xv6-user/_msgtest1 xv6-user/_msgtest2 xv6-user/_shmtest1 xv6-user/_shmtest2
# Implicit rule search has not been done.

# Modification time never checked.
# File has not been updated.
# recipe to execute (from 'Makefile', line 135):
# recipe to execute (from 'Makefile', line 136):
xv6-mkfs/mkfs fs.img README.md $(UPROGS)

# Not a target:
@@ -554,6 +559,7 @@ xv6-user/_forktest: xv6-user/forktest.o xv6-user/ulib.o xv6-user/usys.o xv6-user
# File has not been updated.

# Not a target:

xv6-user/uthread/uthread.c:
# Implicit rule search has not been done.
# Modification time never checked.
@@ -709,19 +715,19 @@ xv6-mkfs/mkfs: xv6-mkfs/mkfs.c xv6-user/include/fs.h xv6-user/include/param.h
gcc -Werror -Wall -I./xv6-user -o xv6-mkfs/mkfs xv6-mkfs/mkfs.c

# files hash-table stats:
# Load=62/1024=6%, Rehash=0, Collisions=6/122=5%
# Load=63/1024=6%, Rehash=0, Collisions=6/124=5%
# VPATH Search Paths

# No 'vpath' search paths.

# No general ('VPATH' variable) search path.

# strcache buffers: 1 (0) / strings = 90 / storage = 1345 B / avg = 14 B
# current buf: size = 8162 B / used = 1345 B / count = 90 / avg = 14 B
# strcache buffers: 1 (0) / strings = 91 / storage = 1358 B / avg = 14 B
# current buf: size = 8162 B / used = 1358 B / count = 91 / avg = 14 B

# strcache performance: lookups = 139 / hit rate = 35%
# strcache performance: lookups = 140 / hit rate = 35%
# hash-table stats:
# Load=90/8192=1%, Rehash=0, Collisions=4/139=3%
# Finished Make data base on Sat May 28 20:46:15 2022
# Load=91/8192=1%, Rehash=0, Collisions=4/140=3%
# Finished Make data base on Mon Jun 6 11:38:43 2022


3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ UPROGS=\
$(USER)/_touch \
$(USER)/_cat \
$(USER)/_rm \
$(USER)/_wc \
$(USER)/_forktest \
$(USER)/_stressfs \
$(USER)/_sem_test1 \
@@ -128,7 +129,7 @@ UPROGS=\
$(USER)/_msgtest1 \
$(USER)/_msgtest2 \
$(USER)/_shmtest1 \
$(USER)/_shmtest2
$(USER)/_shmtest2


fs.img: xv6-mkfs/mkfs README.md $(UPROGS)
183 changes: 26 additions & 157 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,168 +1,37 @@
# xv6-rust
## Introduction
## 项目简介

![](run.png)
本项目是在去年比赛实现的 xv6-rust 基础之上进行二次开发,主要有两个方面:一是增加新的功能,二是修改完善现有代码的一些 bug,具体如下所示:

This is a try to implement xv6 OS in pure Rust.
- 实现进程间的通信功能:
- 信号量
- 消息队列
- 共享内存
- 管道

What's more, we are desired to add something new features into our OS, like network and GUI.
- 实现线程协程:
- 内核级线程
- 用户级线程(协程)

The further goal of this project is to support multiple architecture and multiple boards, finally making our OS running in our own CPU.
- 简单封装运行库
- 功能改进:
- 页面延迟分配
- 优先级调度

For the purpose of supporting the feature of Rust language, I also intend to use `async/await` feature to implement kernel thread scheduler renewedly.
- 修改重构:
- 重写进程结构体及其锁的形式,改用大粒度锁
- 修改原有管道的 bug
- 修改内存管理的 bug

Due to the complexity of the project and the busy course-work, I think it's hard to complete above work independently, so I'm sincerely hope others can interest on this project and join our teams.
以上便是初赛阶段已完成的一些内容,还有一些目前正在做待完成

## Start
### QEMU
**Linux**:
```
wget https://download.qemu.org/qemu-5.0.0.tar.x
tar xvJf qemu-5.0.0.tar.xz
cd qemu-5.0.0
./configure --target-list=riscv32-softmmu,riscv64-softmmu
make -j$(nproc)
sudo make install
```
If you find some errors when building, you can slove by following hints:
- `ERROR: pkg-config binary 'pkg-config' not found` : `sudo apt-get install pkg-config`
- `ERROR: glib-2.48 gthread-2.0 is required to compile QEMU`: `sudo apt-get install libglib2.0-dev`
- `ERROR: pixman >= 0.21.8 not present`: `sudo apt-get install libpixman-1-dev`
- 模拟中断实现信号机制
- 重新组织进程结构体,采用红黑树并实现 CFS 调度算法
- 写时复制、mmap 等系统调用。

### Rust
You need download rust to start our environment. We suggest you to use official shell:
```
curl https://sh.rustup.rs -sSf | sh
```
If you fail because of slow network speed. You can try this to speed up:
```
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
curl https://sh.rustup.rs -sSf | sh
```
## 环境搭建

If you have finished these, you can test your environment by following commands:
```
source $HOME/.cargo/env
rustc --version
```
In addition, we'd better change the package mirror address crates.io used by the package manager cargo to the mirror server of the University of Science and Technology of China to speed up the download of the tripartite library. We open (create a new file if it doesn't exist) ~/.cargo/config and modify the content to:
```
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
```
Besides, you also update some tools in rust:
[环境搭建](docs/环境搭建.pdf)

```
rustup target add riscv64gc-unknown-none-elf
cargo install cargo-binutils
rustup component add llvm-tools-preview
```
## 设计文档

Finally, you run this OS on your machine by excuteing following commands:

```
git clone https://github.com/Ko-oK-OS/xv6-rust.git
cd xv6-rust
git submodule update --init --recursive
make run
```

## GDB Usage
To use gdb to debug, we need to download `riscv64-unkonown-elf-gdb` and `tmux`.

### GDB Download
- [Ubuntu](https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-linux-ubuntu14.tar.gz)
- [CentOS](https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-linux-centos6.tar.gz)
- [macOS](https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-apple-darwin.tar.gz)
- [Windows](https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-w64-mingw32.zip)

We support gdb in OS kernel, you can exectue this command in `xv6-rust/kernel` directory:
```shell
make debug
```
And then you can debug this programe step by step.

## Schedule

- Virtual Memory and Management
- [x] Virtulal Memory Map
- [x] Kernel Allocator(Buddy System Allocator)
- [x] Load ELF Files From Memory
- Traps,Interrupts, and drivers
- [x] Kernel Trap
- [x] Users Trap
- [x] UART Drivers
- [x] Machine-Mode Timer Interrupt
- [x] Virtio Disk Drivers
- [x] PCI and E1000 Drivers
- Locking
- [x] Spinlock
- [x] Sleeplock
- Process and Scheduing
- [x] Process
- [x] Scheduing
- [x] Muti-Core Support
- [x] Syscall
- File System
- [x] Mkfs
- [x] Buffer Layer
- [x] Log Layer
- [x] SuperBlock Layer
- [x] Inode Layer
- [x] Bitmap Layer
- [x] File Descriptor Layer
- [x] File Path
- [x] Pipe
- [x] Syscall
- NetWork
- [x] PCI and E1000 Initialize
- [x] Protocol Headers
- [ ] Network Card Driver
- [ ] Syscall
- Device Driver
- [x] Virtio Disk
- [x] Uart/Console
- [x] PCI

## Differences
### Fs
- [x] Remove `FILE_TABLE`
- [x] Use `Arc` instead of `refs`, `Arc::clone()` will plat the same role of `refs++`
- [ ] User `enum FileInner` to separate files of various file types

### Scheduler
- [ ] Use `VecDeque` instead of raw array.

### Process
- [ ] Use `BTreeMap` to maintain open files in `Process`
- [ ] Add `Thread` in Kernel Process

## Expected Future
- [ ] More Clear Memory Model
- [ ] Better Scheduler
- [ ] SD Card Driver Support
- [ ] Network Support(Use `smoltcp` to simplify design)
- [ ] Async IO Support

## Docs

[项目设计文档](docs/项目设计文档.pdf)

## References

- [Building a stupid Mutex in the Rust](https://medium.com/@Mnwa/building-a-stupid-mutex-in-the-rust-d55886538889)
- [Rust源码分析:std::sync::Mutex](https://zhuanlan.zhihu.com/p/50006335)
- [buddy_system_allocator](https://github.com/rcore-os/buddy_system_allocator)
- [Write a OS in Rust](https://os.phil-opp.com)
- [rCore-Tutorial-v3](https://rcore-os.github.io/rCore-Tutorial-Book-v3/index.html)
- [rCore-Tutorial](https://rcore-os.github.io/rCore-Tutorial-deploy/)
- [xv6-riscv](https://github.com/mit-pdos/xv6-riscv)
- [xv6-riscv-rust](https://github.com/Jaic1/xv6-riscv-rust)
- [rCore](https://github.com/rcore-os/rCore)

## License
MIT License
[项目设计文档](docs/设计文档.pdf)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
102 changes: 102 additions & 0 deletions docs/环境搭建.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 环境搭建

## 1、ubuntu20.04 及相关环境

```bash
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
sudo apt-get install riscv64-unknown-elf-gcc
#不能定位的话尝试 gcc-riscv64-unknown-elf
```

其他工具比如说 vim,vmtools 工具之类的

## 2、qemu

```bash
wget https://download.qemu.org/qemu-5.0.0.tar.xz
tar xvJf qemu-5.0.0.tar.xz
cd qemu-5.0.0
./configure --target-list=riscv32-softmmu,riscv64-softmmu
make -j$(nproc)
sudo make install
```

If you find some errors when building, you can slove by following hints:

- `ERROR: pkg-config binary 'pkg-config' not found` : `sudo apt-get install pkg-config`
- `ERROR: glib-2.48 gthread-2.0 is required to compile QEMU`: `sudo apt-get install libglib2.0-dev`
- `ERROR: pixman >= 0.21.8 not present`: `sudo apt-get install libpixman-1-dev`

## 3、clone

```bash
git clone https://github.com/Ko-oK-OS/xv6-rust.git
```

其中有三个子仓库 clone 不下来,自己克隆或者下载然后移动进去,因为权限的原因没法直接使用

```bash
git submodule update --init --recursive
```

或者是去修改 .gitmodule 文件 URL 前缀为 https

![image-20220502221208991](C:/Users/Rand/AppData/Roaming/Typora/typora-user-images/image-20220502221208991.png)

## 4、RUST相关环境

You need download rust to start our environment. We suggest you to use official shell:

```bash
curl https://sh.rustup.rs -sSf | sh
```

If you fail because of slow network speed. You can try this to speed up:

```bash
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
curl https://sh.rustup.rs -sSf | sh
```

If you have finished these, you can test your environment by following commands:

```bash
source $HOME/.cargo/env
rustc --version
```

In addition, we'd better change the package mirror address crates.io used by the package manager cargo to the mirror server of the University of Science and Technology of China to speed up the download of the tripartite library. We open (create a new file if it doesn't exist) ~/.cargo/config and modify the content to:

```
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
```

Besides, you also update some tools in rust:

```bash
rustup target add riscv64gc-unknown-none-elf
cargo install cargo-binutils
rustup component add llvm-tools-preview
```

!!!!!!!!!!! 最后这一步的这两个命令

```bash
rustup target add riscv64gc-unknown-none-elf
rustup component add llvm-tools-preview
```

需要在 xv6-rust 目录下执行一次,还需要在 xv6-rust/kernel 目录下执行一次

## 5、搭建完成

```
make run
```

Binary file added docs/环境搭建.pdf
Binary file not shown.
Binary file added docs/设计文档.assets/UserSpace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/设计文档.assets/pipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/设计文档.assets/redir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,283 changes: 1,283 additions & 0 deletions docs/设计文档.md

Large diffs are not rendered by default.

Binary file added docs/设计文档.pdf
Binary file not shown.
20 changes: 8 additions & 12 deletions kernel/src/fs/pipe.rs
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ impl Pipe {
// pipe: PipeData::alloc(),
// pipe_lock: Spinlock::new((), "pipe")
// };

let pipe = &mut *pipe_ptr;
pipe.read_open = true;
pipe.write_open = true;
@@ -113,6 +114,8 @@ impl Pipe {
// // pipe_guard.read_number += 1;

// }


let mut i = 0;
while i < len {
if self.nread == self.nwrite {
@@ -143,19 +146,13 @@ impl Pipe {
let mut guard = self.pipe_lock.acquire();
// let pipe = unsafe { &mut *self.pipe };
let mut i = 0;

// pipe.write_open;

// println!("$$$");

// println!("@{} {}", pipe.write_number, pipe.read_number);

while i < len {
// println!("#{}", i);
// if !pipe.read_open || my_proc.killed() {
// drop(guard);
// return Err("pipe write: pipe read close or current process has been killed")
// }
if !self.read_open || my_proc.killed() {
drop(guard);
return Err("pipe write: pipe read close or current process has been killed")
}
// println!("HEHE");

if self.nwrite == self.nread + PIPE_SIZE {
@@ -167,15 +164,14 @@ impl Pipe {
my_proc.sleep(&self.nwrite as *const _ as usize, guard);
guard = self.pipe_lock.acquire();
} else {
// println!("HAHA");

let mut char: u8 = 0;
let pgt = unsafe { &mut *my_proc.pagetable };
if pgt.copy_in(&mut char as *mut u8, addr + i, 1).is_err() {
break;
}
let write_cursor = self.nwrite % PIPE_SIZE;
self.data[write_cursor] = char;
// println!("+{}", char);

self.nwrite += 1;
i += 1;
2 changes: 0 additions & 2 deletions kernel/src/ipc/bitmap.rs
Original file line number Diff line number Diff line change
@@ -10,12 +10,10 @@ use array_macro::array;
pub const SHARE_MEM_AREA_SIZE: usize = 4*1024*1024;



pub const SHARE_MEM_MAP_PAGES: usize = SHARE_MEM_AREA_SIZE/(PGSIZE);
pub const SHARE_MEM_BIT_MAP_SIZE: usize = SHARE_MEM_MAP_PAGES/8+1;



pub struct BitMap{
bitmap: [u8; SHARE_MEM_BIT_MAP_SIZE]
}
21 changes: 4 additions & 17 deletions xv6-user/pipe_test.c
Original file line number Diff line number Diff line change
@@ -4,45 +4,32 @@

int main(){
int p[2];

pipe(p);
const char* str = "hello";

printf("%x %x\n", p[0], p[1]);



if(fork() == 0){

printf("***** %d \n", (long)str);

// printf("***** %d \n", (long)str);

close(1);
dup(p[1]);

close(p[0]);
close(p[1]);



write(1, str, 6);



printf("child exit\n");

return 1;
}else{
wait(0);

char buf[6];
close(0);
dup(p[0]);



close(p[0]);
close(p[1]);

read(0, buf, 6);
read(0, buf, 12);

printf("$$$$$ %s \n", buf);

55 changes: 55 additions & 0 deletions xv6-user/wc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "include/types.h"
#include "include/stat.h"
#include "include/param.h"
#include "user.h"

char buf[512];

void
wc(int fd, char *name)
{
int i, n;
int l, w, c, inword;

l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
c++;
if(buf[i] == '\n')
l++;
if(strchr(" \r\t\n\v", buf[i]))
inword = 0;
else if(!inword){
w++;
inword = 1;
}
}
}
if(n < 0){
printf("wc: read error\n");
exit(1);
}
printf("%d %d %d %s\n", l, w, c, name);
}

int
main(int argc, char *argv[])
{
int fd, i;

if(argc <= 1){
wc(0, "");
exit(0);
}

for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf("wc: cannot open %s\n", argv[i]);
exit(1);
}
wc(fd, argv[i]);
close(fd);
}
exit(0);
}