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

Implement kill system call #153

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Documentation/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Not supported.
| 59 | execve | Partially | `v0.0.1` | |
| 60 | exit | Partially | `v0.0.1` | |
| 61 | wait4 | Partially | `v0.0.1` | |
| 62 | kill | Unimplemented | | |
| 62 | kill | Partially | next release | |
| 63 | uname | Partially | `v0.0.1` | |
| 64 | semget | Unimplemented | | |
| 65 | semop | Unimplemented | | |
Expand Down
25 changes: 25 additions & 0 deletions kernel/syscalls/kill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::process::{current_process, signal::Signal, PId, Process};
use crate::result::Errno;
use crate::result::Result;
use crate::syscalls::SyscallHandler;

impl<'a> SyscallHandler<'a> {
pub fn sys_kill(&self, pid: PId, sig: Signal) -> Result<isize> {
let pid_int = pid.as_i32();
match pid_int {
pid_int if pid_int > 0 => match Process::find_by_pid(pid) {
Some(proc) => proc.send_signal(sig),
None => return Err(Errno::ESRCH.into()),
},
0 => current_process().process_group().lock().signal(sig),
-1 => {
// TODO: check for permissions once linux capabilities is implemented
current_process().send_signal(sig);
}
pid_int if pid_int < -1 => current_process().process_group().lock().signal(sig),
_ => (),
}

Ok(0)
}
}
3 changes: 3 additions & 0 deletions kernel/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(self) mod getsockname;
pub(self) mod getsockopt;
pub(self) mod gettid;
pub(self) mod ioctl;
pub(self) mod kill;
pub(self) mod link;
pub(self) mod linkat;
pub(self) mod listen;
Expand Down Expand Up @@ -138,6 +139,7 @@ const SYS_FORK: usize = 57;
const SYS_EXECVE: usize = 59;
const SYS_EXIT: usize = 60;
const SYS_WAIT4: usize = 61;
const SYS_KILL: usize = 62;
const SYS_UNAME: usize = 63;
const SYS_FCNTL: usize = 72;
const SYS_FSYNC: usize = 74;
Expand Down Expand Up @@ -319,6 +321,7 @@ impl<'a> SyscallHandler<'a> {
bitflags_from_user!(WaitOptions, a3 as c_int)?,
UserVAddr::new(a4),
),
SYS_KILL => self.sys_kill(PId::new(a1 as i32), a2 as c_int),
SYS_EXIT => self.sys_exit(a1 as i32),
SYS_EXIT_GROUP => self.sys_exit_group(a1 as i32),
SYS_SOCKET => self.sys_socket(a1 as i32, a2 as i32, a3 as i32),
Expand Down
2 changes: 1 addition & 1 deletion libs/kerla_utils/bitmap_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitvec::{prelude::*, index::BitMask};
use bitvec::{index::BitMask, prelude::*};

use crate::alignment::align_up;

Expand Down