Nucleus
Barry More syscalls 315b2be (3 years, 2 months ago)
diff --git a/kernel/uname.c b/kernel/uname.c
new file mode 100644
index 0000000..c930faf
--- /dev/null
+++ b/kernel/uname.c
@@ -0,0 +1,33 @@
+/*
+ * This file implements the uname system call. It stores information about the
+ * kernel to a buffer for userspace to read.
+ */
+
+#include <string.h>
+#include <sys/utsname.h>
+#include <errno.h>
+#include <nucleus/memory.h>
+
+static const char *SYSNAME = "Nucleus";
+static const char *RELEASE = "0.9.0";
+static const char *VERSION = "SMP PREEMPT "__DATE__" "__TIME__;
+static const char *MACHINE = "x86";
+
+/* Get information about current kernel */
+int
+uname(struct utsname *buf)
+{
+ strcpy(buf->sysname, SYSNAME);
+ strcpy(buf->release, RELEASE);
+ strcpy(buf->version, VERSION);
+ strcpy(buf->machine, MACHINE);
+}
+
+/* Kernel information system call */
+int
+sys_uname(struct utsname *buf)
+{
+ if (!buf || !verify_access(buf, sizeof(struct utsname), PROT_WRITE))
+ return -EFAULT;
+ uname(buf);
+}
diff --git a/task/syscall.c b/task/syscall.c
index 40754e3..e0b2d23 100644
--- a/task/syscall.c
+++ b/task/syscall.c
@@ -12,10 +12,12 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/utsname.h>
#include <errno.h>
#include <nucleus/cpu.h>
+#include <nucleus/kernel.h>
#include <nucleus/memory.h>
-#include <nucleus/panic.h>
#include <nucleus/task.h>
#include <nucleus/vfs.h>
@@ -27,8 +29,11 @@ struct SyscallEntry {
/* List of syscalls */
struct SyscallEntry syscalls[] = {
- /* Task */
+ /* Kernel */
[SYSCALL_DBGPRINTF] = { 1, dbgprintf },
+ [SYSCALL_UNAME] = { 1, uname },
+
+ /* Task */
[SYSCALL_CLONE] = { 1, clone },
[SYSCALL_EXIT] = { 1, exit },
[SYSCALL_GETPID] = { 0, getpid },
@@ -53,15 +58,15 @@ struct SyscallEntry syscalls[] = {
[SYSCALL_WRITE] = { 3, write },
[SYSCALL_IOCTL] = { 3, ioctl },
[SYSCALL_LSEEK] = { 3, lseek },
-// [SYSCALL_STAT] = { 2, stat },
-// [SYSCALL_FSTAT] = { 2, fstat },
-// [SYSCALL_GETDENTS] = { 3, getdents },
-// [SYSCALL_MKDIR] = { 2, mkdir },
+ [SYSCALL_STAT] = { 2, stat },
+ [SYSCALL_FSTAT] = { 2, fstat },
+ [SYSCALL_GETDENTS] = { 3, getdents },
+ [SYSCALL_MKDIR] = { 2, mkdir },
// [SYSCALL_RMDIR] = { 1, rmdir },
-// [SYSCALL_MKNOD] = { 3, mknod },
+ [SYSCALL_MKNOD] = { 3, mknod },
// [SYSCALL_RENAME] = { 2, rename },
-// [SYSCALL_DUP] = { 1, dup },
-// [SYSCALL_DUP2] = { 2, dup2 },
+ [SYSCALL_DUP] = { 1, dup },
+ [SYSCALL_DUP2] = { 2, dup2 },
// [SYSCALL_ISATTY] = { 1, isatty },
// [SYSCALL_PIPE] = { 1, pipe },
@@ -86,7 +91,7 @@ int
syscall_handler(int num, uintptr_t args)
{
int ret = -EINVAL;
- current->inSyscall = 1;
+ enter_syscall_context(num);
/* Find syscall entry */
if (num >= sizeof(syscalls) / sizeof(syscalls[0]))
@@ -109,6 +114,6 @@ syscall_handler(int num, uintptr_t args)
asm volatile("call *%1" : "=a" (ret) : "r" (syscall->function));
end:
- current->inSyscall = 0;
+ exit_syscall_context();
return ret;
}