diff --git a/kernel/object/clone_proc.c b/kernel/object/clone_proc.c index e04d532a6fb70e47db1ef9c856acb95c9ece0b71..03d86e2f921bccc8dda93dae0aebc860ce4580e8 100644 --- a/kernel/object/clone_proc.c +++ b/kernel/object/clone_proc.c @@ -48,13 +48,12 @@ static int clone_thread_vmr(struct cap_group* parent_cap_group, struct cap_group } } - // kinfo("vmr_tmp start: %lx\n", vmr_tmp->start); - // kinfo("vmr_tmp->size: %lx\n", vmr_tmp->size); + if (rights == -1) { pmo_tmp = vmr_tmp->pmo; rights = VMR_READ; } - // kinfo("pmo type %d\n", pmo_tmp->type); + /* To simplify implementation, we don't register file to fs and just copy pmo directly */ if (pmo_tmp->type == PMO_DATA) { ret = create_pmo(pmo_tmp->size, pmo_tmp->type, new_cap_group, @@ -308,7 +307,6 @@ int set_server_conn_config(struct thread* parent_thread, struct thread* new_thre if(ret < 0){ kinfo("vmspace map failed, ret: %d\n", ret); } - kinfo("server shm successfully\n"); break; } } @@ -454,7 +452,6 @@ cap_t sys_handle_clone(int input_argc, char** input_argv, if (conn->server_handler_thread->cap_group->badge != parent_cap_group->badge) continue; if (prev_conn && conn == prev_conn) continue; prev_conn = conn; - kinfo("slot id: %d pipe connection is ok for clone \n", slot_id); conn = obj_alloc(TYPE_CONNECTION, sizeof(*conn)); BUG_ON(!conn); write_lock(&slot_table->table_guard); diff --git a/user/apps/samples/CMakeLists.txt b/user/apps/samples/CMakeLists.txt index 2a007b4109e945ad580f2e02302b7e6d6e95d781..564b2aa0f98929b14fc5732f9b3235ebba231491 100644 --- a/user/apps/samples/CMakeLists.txt +++ b/user/apps/samples/CMakeLists.txt @@ -13,6 +13,7 @@ add_compile_options(-g) add_executable(client.bin client.c) add_executable(server.bin server.c) add_executable(sdtest.bin sdtest.c) +add_executable(pipe_test.bin pipe_test.c) add_executable(hello_world.bin hello_world.c) diff --git a/user/apps/samples/load_testcase_elf.c b/user/apps/samples/load_testcase_elf.c index a5c7cf9cef408c86dfe4448479edfc86dd0f8547..fb503929f1304e8df5746dc598b65cddec5e280b 100644 --- a/user/apps/samples/load_testcase_elf.c +++ b/user/apps/samples/load_testcase_elf.c @@ -251,21 +251,9 @@ extern int __syscall1(long n, long a); extern int __syscall5(long n, long a, long b, long c, long d, long e); -extern int chcore_pipe2(int *pipefd, int flags); -extern ssize_t chcore_pipe_read(int fd, void *buf, size_t count); -ssize_t chcore_pipe_write(int fd, void *buf, size_t count); extern int chcore_mount(const char *special, const char *dir, const char *fstype, unsigned long flags, const void *data); -static int pipefd_0 = -1; -static int pipefd_1 = -1; -// static struct yield_info_t { -// int yield_use; -// int yield_cnt; -// } yield_clone_info; - -// static int brk_out = 27; - void execute_binary(char *filename) { uint64_t syscall_num, tmp; @@ -355,8 +343,6 @@ void execute_binary(char *filename) PREPARE_RET_ADDR((uintptr_t)(mem + header.e_entry), 0x10160); PREPARE_CASE_REGISTERS(); - // yield_clone_info.yield_use = 0; - // yield_clone_info.yield_cnt = 0; while(1){ // save and restore registers @@ -443,16 +429,8 @@ void execute_binary(char *filename) break; } case SYS_write: { - if (a0 != pipefd_1) { - // printf("write to stdout %s\n", (char*)a1); - tmp = write(a0, (void*)a1, a2); - STORE_TO_REGISTER(a0, tmp); - } else { - // printf("write to chcore_pipe_write\n"); - tmp = chcore_pipe_write(a0, (void*)a1, a2); - STORE_TO_REGISTER(a0, tmp); - } - + tmp = write(a0, (void*)a1, a2); + STORE_TO_REGISTER(a0, tmp); break; } case SYS_mount: { @@ -482,21 +460,11 @@ void execute_binary(char *filename) } case SYS_clone: { /* To map the yield function vmr, we need to map yield vmr */ - // sched_yield(); - // if(a1 == 0){ - // tmp = __syscall5(SYS_clone, 0, 0, 0, 0, 0); - // }else{ - // tmp = __syscall5(SYS_clone, (long)a0, (long)a1, (long)a2, (long)a3, (long)a4); - // } - - - if ( pipefd_0 != -1 ) { - // pipe use this branch - tmp = 2; - } - else { - // yield , wait use this branch - tmp = 0; + sched_yield(); + if(a1 == 0){ + tmp = __syscall5(SYS_clone, 0, 0, 0, 0, 0); + }else{ + tmp = __syscall5(SYS_clone, (long)a0, (long)a1, (long)a2, (long)a3, (long)a4); } STORE_TO_REGISTER(a0, tmp); break; @@ -514,8 +482,8 @@ void execute_binary(char *filename) break; } case SYS_brk: { - // /* because of 'sext.w a0, a0', retval should in 32 bits */ long res; + /* because of 'sext.w a0, a0', retval should in 32 bits */ if(a0 != 0){ a0 = ((a0 & 0xFFFF0000) << 16) + (a0 & 0xFFFF); res = __syscall1(SYS_brk, a0); @@ -541,19 +509,6 @@ void execute_binary(char *filename) break; } case SYS_sched_yield: { - // yield_clone_info.yield_use = 1; - // if (yield_clone_info.yield_use && yield_clone_info.yield_cnt ==0) { - // // inner loop execut only once - // printf(" CCCCCCCCCC [1/5]\n"); - // printf(" BBBBBBBBBB [2/5]\n"); - // printf(" BBBBBBBBBB [3/5]\n"); - // printf(" BBBBBBBBBB [4/5]\n"); - // printf(" BBBBBBBBBB [4/5]\n"); - // } - // printf("========== End test_yield\n"); - // yield_clone_info.yield_cnt++; - // yield_clone_info.yield_use=1; - // tmp = 0; tmp = sched_yield(); STORE_TO_REGISTER(a0, tmp); break; @@ -565,8 +520,6 @@ void execute_binary(char *filename) } case SYS_gettimeofday: { tmp = gettimeofday((void *)a0, (void *)a1); - // printf("{tms_utime:100, tms_stime:200, tms_cutime:150, tms_cstime:175}\n"); - // tmp = 0; STORE_TO_REGISTER(a0, tmp); break; } @@ -574,48 +527,21 @@ void execute_binary(char *filename) case SYS_pipe2: { int* pipefd = (int*)a0; int flags = (int)a1; - int res = chcore_pipe2(pipefd, flags); - pipefd_0 = pipefd[0]; - pipefd_1 = pipefd[1]; - printf("cpid: 0\n"); - fflush(stdout); + int res = pipe2(pipefd, flags); STORE_TO_REGISTER(a0, (int64_t)res); break; } case SYS_getdents64: { - printf("========== END test_getdentg�\n"); - printf("========== START test_getdents\n"); int fd = (int)a0; struct dirent* dirp = (struct dirent*)a1; size_t count = (size_t)a2; int res = getdents(fd, dirp, count); STORE_TO_REGISTER(a0, (int64_t)res); - printf("open fd:222\n"); - printf("getdents fd:666\n"); - printf("getdents success.\n"); - printf("dummy\n"); - printf("\n"); - - printf("========== END test_getdents\n"); - printf("========== START test_getdentg�\n"); - fflush(stdout); break; } case SYS_read: { - if (a0 != pipefd_0) { - printf("Hi, this is a text file.\n"); - printf("syscalls testing success!\n"); - fflush(stdout); - // ssize_t tmp = read(a0, (void*)a1, a2); - tmp = 1; - STORE_TO_REGISTER(a0, tmp); - } else { - ssize_t tmp = chcore_pipe_read(a0, (void*)a1, a2); - // printf("chcore_pipe_read call ret %ld\n", tmp); - // printf("read from pipe %s\n", (char*)a1); - fflush(stdout); - STORE_TO_REGISTER(a0, tmp); - } + ssize_t tmp = read(a0, (void*)a1, a2); + STORE_TO_REGISTER(a0, tmp); break; } case SYS_mkdirat: { @@ -644,8 +570,8 @@ void execute_binary(char *filename) char *case_name = (char*)malloc(sizeof(char) * 30); char *input_argv[2]; input_argv[0] = "/load.bin"; - memcpy(case_name, case_dir, 11); - memcpy(case_name + 11, (char*)a0, strlen((char*)a0)+1); + memcpy(case_name, case_dir, 10); + memcpy(case_name + 10, (char*)a0, strlen((char*)a0)+1); input_argv[1] = case_name; pid_t pid = chcore_new_process(2, input_argv); int status; diff --git a/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c b/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c index 4df1e71047e01a7cd1c87afb344d236ef4a44740..202325820d244a8f144187e7ae78efb1a4edd371 100644 --- a/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c +++ b/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c @@ -154,11 +154,11 @@ int chcore_pipe2(int pipefd[2], int flags) write_fd_desc->fd_op = &pipe_op; *pf = (struct pipe_file){.read_idx = 0, - .write_idx = 30, // for testcases + .write_idx = 0, .pipe_lock = 0, .read_fd = read_fd, .write_fd = write_fd}; - strcpy(pf->buf, " Write to pipe successfully.\n"); + pipefd[0] = read_fd; pipefd[1] = write_fd; diff --git a/user/system-services/system-servers/procmgr/procmgr.c b/user/system-services/system-servers/procmgr/procmgr.c index 4acae7772c8bd8437acee0d70eda3c7b742f59da..3efb7899bf6b7219ac7482de1c3e4483017227c8 100644 --- a/user/system-services/system-servers/procmgr/procmgr.c +++ b/user/system-services/system-servers/procmgr/procmgr.c @@ -753,9 +753,6 @@ void boot_testcases(void) struct dirent *entry; char case_dir[11] = "/testcases/"; char case_name[30]; - // int yield_first = 1; - // char* skip_list[] = {".", "..", "clone", "exit", "fork", "getppid", "times", "wait", "waitpid", "yield", NULL}; - char* skip_list[] = {".", "..", NULL}; sleep(1); @@ -764,46 +761,18 @@ void boot_testcases(void) if (ret != 0) { BUG("procmgr boot testcase mount failed\n"); } - //printf("mount sdcard success\n"); - // sleep(2); dir = opendir("/testcases"); if (dir == NULL) { BUG("procmgr boot testcase opendir failed\n"); } - // if (yield_first) { - - // printf("========== START test_yield ==========\n"); - // for (int i = 0; i < 3; ++i){ - // for (int j = 0; j< 5; ++j){ - // printf(" I am child process: %d. iteration %d.\n", 666, i); - // } - // } - // printf("========== END test_yield ==========\n"); - // fflush(stdout); - // } - - // int skip = 0; while ((entry = readdir(dir)) != NULL) { memset(case_name, 0, sizeof(case_name)); if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; input_argv[0] = "/load.bin"; - - // if entry->d_name in skip_list, continue - int skip = 0; - for (int i = 0; skip_list[i] != NULL; i++) { - if (strcmp(entry->d_name, skip_list[i]) == 0) { - skip = 1; - break; - } - } - if (skip) { - // printf("skip testcase %s\n", entry->d_name); - // fflush(stdout); - continue; - } + fflush(stdout); strcpy(case_name, case_dir); strcat(case_name, entry->d_name); @@ -815,17 +784,6 @@ void boot_testcases(void) } put_proc_node(proc_node); sleep(1); - // struct timespec req, rem; - - // // Set the time to sleep (0.1 second) - // req.tv_sec = 0; // 0 seconds - // req.tv_nsec = 200000000; // 100 million nanoseconds (0.1 second) - - // // Use nanosleep function to pause execution - // int response = nanosleep(&req, &rem); - // if (response == -1) { - // printf("sleep failed\n"); - // } fflush(stdout); } closedir(dir);