@@ -19,16 +19,16 @@ _Atomic volatile pid_t now_pid = 0;
1919_Atomic volatile pid_t now_tid = 0 ;
2020extern volatile bool smp_enable ;
2121
22- USED void foreach_task (){
22+ USED void foreach_task () {
2323 pcb_t process = NULL ;
24- cow_foreach (process_list ,process ) {
25- logkf ("PID:%d - %s %p\n\r" ,process -> pid ,process -> name ,process );
24+ cow_foreach (process_list , process ) {
25+ logkf ("PID:%d - %s %p\n\r" , process -> pid , process -> name , process );
2626 tcb_t thread = NULL ;
27- cow_foreach (process -> child_threads ,thread ) {
28- logkf ("\t TID:%d - %s %p\n\r" ,thread -> tid ,thread -> name ,thread );
27+ cow_foreach (process -> child_threads , thread ) {
28+ logkf ("\t TID:%d - %s %p\n\r" , thread -> tid , thread -> name , thread );
2929 struct sched_entity * entity = thread -> sched_handle ;
3030 //logkf("\t deadline: %x - vruntime: %x\n\r",entity->deadline,entity->vruntime);
31- logkf ("\t deadline: %lx - vruntime: %lx\n\r" ,entity -> deadline ,entity -> vruntime );
31+ logkf ("\t deadline: %lx - vruntime: %lx\n\r" , entity -> deadline , entity -> vruntime );
3232 }
3333 }
3434}
@@ -66,7 +66,7 @@ static void kill_thread0(pcb_t parent, tcb_t task) {
6666
6767static void kill_proc0 (pcb_t pcb ) {
6868 do {
69- if (pcb -> child_threads -> size == 0 ) break ;
69+ if (pcb -> child_threads -> size == 0 ) break ;
7070 tcb_t thread = NULL ;
7171 cow_foreach (pcb -> child_threads , thread ) {
7272 break ;
@@ -82,19 +82,11 @@ static void kill_proc0(pcb_t pcb) {
8282
8383 procfs_on_exit_task (pcb );
8484
85- for (size_t i = 0 ; i < pcb -> fdts -> fds_length ; i ++ ) {
86- fd_t * handle = pcb -> fdts -> fds [i ];
87- if (handle != NULL ) {
88- vfs_close (handle -> node );
89- free (handle );
90- }
91- }
92-
9385 lazy_free (pcb );
9486
9587 free_fdt (pcb -> fdts );
9688 ipc_queue_release (pcb -> ipc_queue );
97- free_llist_queue (pcb -> virt_queue ,NULL ,NULL );
89+ free_llist_queue (pcb -> virt_queue , NULL , NULL );
9890 free (pcb -> cmdline );
9991 vfs_close (pcb -> cwd );
10092 vfs_close (pcb -> exec );
@@ -135,7 +127,7 @@ void kill_proc(pcb_t pcb, int exit_code, bool is_zombie) {
135127 }
136128 }
137129 pcb_t parent = pcb -> parent ;
138- cow_list_remove (parent -> child_process ,pcb -> ppl_index );
130+ cow_list_remove (parent -> child_process , pcb -> ppl_index );
139131 pcb -> status = T_ZOMBIE ;
140132 ipc_message_t msg = malloc (sizeof (struct ipc_message ));
141133 msg -> pid = pcb -> pid ;
@@ -145,6 +137,15 @@ void kill_proc(pcb_t pcb, int exit_code, bool is_zombie) {
145137 msg -> data [2 ] = (exit_code >> 16 ) & 0xFF ;
146138 msg -> data [3 ] = (exit_code >> 24 ) & 0xFF ;
147139 ipc_send (pcb -> parent -> ipc_queue , msg );
140+
141+ for (size_t i = 0 ; i < pcb -> fdts -> fds_length ; i ++ ) {
142+ fd_t * handle = pcb -> fdts -> fds [i ];
143+ if (handle != NULL ) {
144+ vfs_close (handle -> node );
145+ free (handle );
146+ }
147+ }
148+
148149 enable_scheduler ();
149150 } else {
150151 cow_list_remove (pcb -> parent -> child_process , pcb -> ppl_index );
@@ -164,7 +165,7 @@ int waitpid(pid_t pid, pid_t *pid_ret) {
164165 int exit_code ;
165166 while (1 ) {
166167 change_task_weight (get_current_task (), NICE_TO_PRIO (10 ));
167- mesg = ipc_recv_wait (process -> ipc_queue ,IPC_MSG_TYPE_EPID );
168+ mesg = ipc_recv_wait (process -> ipc_queue , IPC_MSG_TYPE_EPID );
168169 change_task_weight (get_current_task (), NICE_TO_PRIO (0 ));
169170 exit_code =
170171 (mesg -> data [3 ] << 24 ) | (mesg -> data [2 ] << 16 ) | (mesg -> data [1 ] << 8 ) | mesg -> data [0 ];
@@ -251,6 +252,6 @@ void setup_task() {
251252 bsp_idle_thread -> status = T_RUNNING ;
252253 bsp_idle_thread -> signal_stack = (uint64_t )aligned_alloc (PAGE_SIZE , STACK_SIZE ) + STACK_SIZE ;
253254 bsp_idle_thread -> syscall_stack = (uint64_t )aligned_alloc (PAGE_SIZE , STACK_SIZE ) + STACK_SIZE ;
254- arch_context_init (bsp_idle_thread ,& bsp_idle_thread -> context );
255+ arch_context_init (bsp_idle_thread , & bsp_idle_thread -> context );
255256 kinfo ("kernel process(%s) PID: %d " , kernel_process -> name , kernel_process -> pid );
256257}
0 commit comments