Skip to content

Commit

Permalink
Merge pull request #20 from Arceos-monolithic/zlm_1_6
Browse files Browse the repository at this point in the history
Zlm 第一阶段任务六(杨金全)
  • Loading branch information
scPointer authored Feb 29, 2024
2 parents 9ab4610 + ad8df99 commit 6fea32e
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ make run
```shell
# 构建镜像
./build_img.sh sdcard

# 运行 Unikernel 架构内核
make run

Expand Down
8 changes: 5 additions & 3 deletions modules/axprocess/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn exit_current_task(exit_code: i32) -> ! {

let curr_id = current_task.id().as_u64();

info!("exit task id {} with code {}", curr_id, exit_code);
info!("exit task id {} with code _{}_", curr_id, exit_code);
clear_wait(
if current_task.is_leader() {
process.pid()
Expand Down Expand Up @@ -231,11 +231,12 @@ pub unsafe fn wait_pid(pid: isize, exit_code_ptr: *mut i32) -> Result<u64, WaitS
answer_status = WaitStatus::Running;
if let Some(exit_code) = child.get_code_if_exit() {
answer_status = WaitStatus::Exited;
info!("wait pid _{}_ with code _{}_", child.pid(), exit_code);
exit_task_id = index;
if !exit_code_ptr.is_null() {
unsafe {
// 因为没有切换页表,所以可以直接填写
*exit_code_ptr = exit_code;
*exit_code_ptr = exit_code << 8;
}
}
answer_id = child.pid();
Expand All @@ -245,10 +246,11 @@ pub unsafe fn wait_pid(pid: isize, exit_code_ptr: *mut i32) -> Result<u64, WaitS
// 找到了对应的进程
if let Some(exit_code) = child.get_code_if_exit() {
answer_status = WaitStatus::Exited;
info!("wait pid _{}_ with code _{:?}_", child.pid(), exit_code);
exit_task_id = index;
if !exit_code_ptr.is_null() {
unsafe {
*exit_code_ptr = exit_code;
*exit_code_ptr = exit_code << 8;
// 用于WEXITSTATUS设置编码
}
}
Expand Down
Binary file added testcases/testsuits-x86_64-linux-musl/wait
Binary file not shown.
55 changes: 55 additions & 0 deletions testcases/testsuits-x86_64-linux-musl/wait.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

// // #define WEXITSTATUS(s) (((s)&0xff00) >> 8)
// // #define WIFEXITED(s) (!WTERMSIG(s))
// #define WIFEXITED(s) ((s)&0x7f)

int main(void)
{
pid_t pid, wpid;
int status;
int i = 0;
pid = fork();
// printf(" %d \n", pid);
if (pid == -1) {
// fork失败
perror("fork failed");
exit(EXIT_FAILURE);
} else if (pid == 0) { //子进程
printf("Child --- My Parent is %d\n", getppid());
sleep(5);
// 子进程的任务完成,现在退出
printf("Child Process is exiting\n");
exit(9); // 退出子进程
} else if(pid > 0) { //父进程
wpid = wait(&status); //等待回收子进程

printf("Status %d\n", status);

if(wpid == -1) {
perror("wait error:");
exit(1);
}

while(i < 3) {
printf("Parent Pid = %d, SonPid = %d\n", getpid(), pid);
sleep(1);
i++;
}

printf("Parent: Status %d WIFEXITED(status) == %d\n", status, WIFEXITED(status));

//WEXITSTATUS get the return code
printf("Parent: Status %d The return code WEXITSTATUS(status) == %d\n", status, WEXITSTATUS(status));
} else {
perror("for error");
exit(1);
}

return 0;
}
Binary file added testcases/testsuits-x86_64-linux-musl/wait1
Binary file not shown.
55 changes: 55 additions & 0 deletions testcases/testsuits-x86_64-linux-musl/wait1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

// // #define WEXITSTATUS(s) (((s)&0xff00) >> 8)
// // #define WIFEXITED(s) (!WTERMSIG(s))
// #define WIFEXITED(s) ((s)&0x7f)

int main(void)
{
pid_t pid, wpid;
int status;
int i = 0;
pid = fork();
// printf(" %d \n", pid);
if (pid == -1) {
// fork失败
perror("fork failed");
exit(EXIT_FAILURE);
} else if (pid == 0) { //子进程
printf("Child --- My Parent is %d\n", getppid());
sleep(5);
// 子进程的任务完成,现在退出
printf("Child Process is exiting\n");
exit(0); // 退出子进程
} else if(pid > 0) { //父进程
wpid = wait(&status); //等待回收子进程

printf("Status %d\n", status);

if(wpid == -1) {
perror("wait error:");
exit(1);
}

while(i < 3) {
printf("Parent Pid = %d, SonPid = %d\n", getpid(), pid);
sleep(1);
i++;
}

printf("Parent: Status %d WIFEXITED(status) == %d\n", status, WIFEXITED(status));

//WEXITSTATUS get the return code
printf("Parent: Status %d The return code WEXITSTATUS(status) == %d\n", status, WEXITSTATUS(status));
} else {
perror("for error");
exit(1);
}

return 0;
}
2 changes: 2 additions & 0 deletions ulib/axstarry/syscall_entry/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ pub const OSTRAIN_TESTCASES: &[&str] = &[
pub const SDCARD_TESTCASES: &[&str] = &[
// "busybox sh",
"./MediaServer -h",
// "./wait",
//"./wait1"
// "./arch_prctl",
// "busybox sh ./test_all.sh",
// "./riscv64-linux-musl-native/bin/riscv64-linux-musl-gcc ./hello.c -static",
Expand Down
1 change: 1 addition & 0 deletions ulib/axstarry/syscall_task/src/imp/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub fn syscall_vfork() -> SyscallResult {

/// 等待子进程完成任务,若子进程没有完成,则自身yield
/// 当前仅支持WNOHANG选项,即若未完成时则不予等待,直接返回0
/// WIFEXITED(s) WEXITSTATUS(s)
pub fn syscall_wait4(pid: isize, exit_code_ptr: *mut i32, option: WaitFlags) -> SyscallResult {
loop {
let answer = unsafe { wait_pid(pid, exit_code_ptr) };
Expand Down
6 changes: 3 additions & 3 deletions ulib/axstarry/syscall_utils/src/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ impl UtsName {
/// 默认的 UtsName,并没有统一标准
pub fn default() -> Self {
Self {
sysname: Self::from_str("YoimiyaOS"),
nodename: Self::from_str("YoimiyaOS - machine[0]"),
release: Self::from_str("114"),
sysname: Self::from_str("Starry"),
nodename: Self::from_str("Starry - machine[0]"),
release: Self::from_str("100"),
version: Self::from_str("1.0"),
machine: Self::from_str("RISC-V 64 on SIFIVE FU740"),
domainname: Self::from_str("https://github.com/Azure-stars/arceos"),
Expand Down

0 comments on commit 6fea32e

Please sign in to comment.