aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-26 18:25:07 -0400
committerIan Moffett <ian@osmora.org>2024-03-26 18:25:32 -0400
commit42ad59bdb6df99ccd146d6d67cb8c838be709ec5 (patch)
tree553958f50359acddb5a2bfbc6a10908e40c70f66
parente9edee7206645adcd48b91aae6ef4734f2e98254 (diff)
kernel: Add sys_close()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/filedesc.h1
-rw-r--r--sys/include/sys/syscall.h1
-rw-r--r--sys/kern/kern_filedesc.c10
-rw-r--r--sys/kern/kern_syscall.c1
4 files changed, 13 insertions, 0 deletions
diff --git a/sys/include/sys/filedesc.h b/sys/include/sys/filedesc.h
index 6eb500e..e0835a5 100644
--- a/sys/include/sys/filedesc.h
+++ b/sys/include/sys/filedesc.h
@@ -58,6 +58,7 @@ int open(const char *pathname, int oflag);
uint64_t sys_write(struct syscall_args *args);
uint64_t sys_open(struct syscall_args *args);
+uint64_t sys_close(struct syscall_args *args);
#endif
#endif
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 0f066e5..5020d3a 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -40,6 +40,7 @@ enum {
SYS_exit = 1,
SYS_write,
SYS_open,
+ SYS_close,
__MAX_SYSCALLS
};
diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c
index c429125..6f59508 100644
--- a/sys/kern/kern_filedesc.c
+++ b/sys/kern/kern_filedesc.c
@@ -330,3 +330,13 @@ sys_open(struct syscall_args *args)
dynfree(pathbuf);
return ret;
}
+
+/*
+ * arg0: fd
+ */
+uint64_t
+sys_close(struct syscall_args *args)
+{
+ fd_close_fdnum(this_td(), args->arg0);
+ return 0;
+}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index dc37274..4acfdc5 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -44,4 +44,5 @@ uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args) = {
sys_exit,
sys_write,
sys_open,
+ sys_close,
};