summaryrefslogtreecommitdiff
path: root/kernel/syscalls
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-02 09:17:06 +0200
committerAnton Kling <anton@kling.gg>2024-04-02 09:39:03 +0200
commit2229fd91f7230ae7068814ae029b733945852eb1 (patch)
tree416487f8c66c389c57dee465f648362ca59b8f23 /kernel/syscalls
parent7eceb43433634ee253507208baf1d8298b40e377 (diff)
Kernel: Fix some memory leaks
Diffstat (limited to 'kernel/syscalls')
-rw-r--r--kernel/syscalls/kill.c12
-rw-r--r--kernel/syscalls/open_process.c26
2 files changed, 36 insertions, 2 deletions
diff --git a/kernel/syscalls/kill.c b/kernel/syscalls/kill.c
index 0da229a..affade6 100644
--- a/kernel/syscalls/kill.c
+++ b/kernel/syscalls/kill.c
@@ -1,7 +1,15 @@
+#include <errno.h>
#include <sched/scheduler.h>
#include <signal.h>
#include <syscalls.h>
-int syscall_kill(pid_t pid, int sig) {
- return kill(pid, sig);
+int syscall_kill(int fd, int sig) {
+ vfs_fd_t *fd_ptr = get_vfs_fd(fd, NULL);
+ if (!fd_ptr) {
+ return -EBADF;
+ }
+ if (!fd_ptr->inode->send_signal) {
+ return -EBADF;
+ }
+ return process_signal(fd_ptr, sig);
}
diff --git a/kernel/syscalls/open_process.c b/kernel/syscalls/open_process.c
new file mode 100644
index 0000000..8e3a35e
--- /dev/null
+++ b/kernel/syscalls/open_process.c
@@ -0,0 +1,26 @@
+#include <assert.h>
+#include <errno.h>
+#include <sched/scheduler.h>
+
+int syscall_open_process(int pid) {
+ // TODO: Permission check
+ process_t *process = (process_t *)ready_queue;
+ for (; process; process = process->next) {
+ if (pid == process->pid) {
+ break;
+ }
+ }
+ if (!process) {
+ return -ESRCH;
+ }
+
+ vfs_inode_t *inode = vfs_create_inode(
+ process->pid, 0 /*type*/, 0 /*has_data*/, 0 /*can_write*/, 1 /*is_open*/,
+ process /*internal_object*/, 0 /*file_size*/, NULL /*open*/,
+ NULL /*create_file*/, NULL /*read*/, NULL /*write*/, NULL /*close*/,
+ NULL /*create_directory*/, NULL /*get_vm_object*/, NULL /*truncate*/,
+ NULL /*stat*/, process_signal);
+ int rc = vfs_create_fd(0, 0, 0, inode, NULL);
+ assert(rc >= 0);
+ return rc;
+}