exit: properly set the process' exit code when calling exit()
In order to detect the exit status using WSTATUSCODE ((status & 0xff00) >> 8) the exit code must be shifted by 8 to the left. Separate the kernel process exit logic from the actual system call.
This commit is contained in:
@@ -112,3 +112,7 @@ int sys_waitperiod(void);
|
||||
/// @param gid ID of the group
|
||||
/// @return 1 if the group is orphan, 0 otherwise.
|
||||
int is_orphaned_pgrp(pid_t gid);
|
||||
|
||||
/// @brief Exit the current process with status
|
||||
/// @param status The exit status of the current process
|
||||
void do_exit(int status);
|
||||
|
||||
@@ -517,7 +517,7 @@ pid_t sys_waitpid(pid_t pid, int *status, int options)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sys_exit(int exit_code)
|
||||
void do_exit(int exit_code)
|
||||
{
|
||||
// Get the current task.
|
||||
if (runqueue.curr == NULL) {
|
||||
@@ -573,6 +573,11 @@ void sys_exit(int exit_code)
|
||||
pr_debug("Process %d exited with value %d\n", runqueue.curr->pid, exit_code);
|
||||
}
|
||||
|
||||
void sys_exit(int exit_code)
|
||||
{
|
||||
do_exit(exit_code << 8);
|
||||
}
|
||||
|
||||
int sys_sched_setparam(pid_t pid, const sched_param_t *param)
|
||||
{
|
||||
list_head *it;
|
||||
|
||||
+10
-10
@@ -495,38 +495,38 @@ int do_signal(struct pt_regs *f)
|
||||
|
||||
continue;
|
||||
case SIGQUIT:
|
||||
sys_exit(GET_EXIT_STATUS(1));
|
||||
do_exit(GET_EXIT_STATUS(1));
|
||||
continue;
|
||||
case SIGILL:
|
||||
sys_exit(GET_EXIT_STATUS(132));
|
||||
do_exit(GET_EXIT_STATUS(132));
|
||||
continue;
|
||||
case SIGTRAP:
|
||||
sys_exit(GET_EXIT_STATUS(133));
|
||||
do_exit(GET_EXIT_STATUS(133));
|
||||
continue;
|
||||
case SIGABRT:
|
||||
sys_exit(GET_EXIT_STATUS(134));
|
||||
do_exit(GET_EXIT_STATUS(134));
|
||||
continue;
|
||||
case SIGFPE:
|
||||
sys_exit(GET_EXIT_STATUS(136) | signr);
|
||||
do_exit(GET_EXIT_STATUS(136) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGBUS:
|
||||
sys_exit(GET_EXIT_STATUS(138) | signr);
|
||||
do_exit(GET_EXIT_STATUS(138) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGSEGV:
|
||||
sys_exit(GET_EXIT_STATUS(139) | signr);
|
||||
do_exit(GET_EXIT_STATUS(139) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGXCPU:
|
||||
sys_exit(GET_EXIT_STATUS(158) | signr);
|
||||
do_exit(GET_EXIT_STATUS(158) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
case SIGXFSZ:
|
||||
sys_exit(GET_EXIT_STATUS(159) | signr);
|
||||
do_exit(GET_EXIT_STATUS(159) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
case SIGSYS:
|
||||
default:
|
||||
sys_exit(GET_EXIT_STATUS(exit_code) | signr);
|
||||
do_exit(GET_EXIT_STATUS(exit_code) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user