summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-17 17:06:16 +0200
committerAnton Kling <anton@kling.gg>2024-04-17 17:06:16 +0200
commit620d37f41747e943648544d1fd1567d386c91e04 (patch)
treebd6d616aca8a853f3b90cfd176bba4d37575e42a /kernel
parentd0cca44913356f8ce15e15216b0e26c2e74b4d06 (diff)
Kernel/LibC: Add fstat() and remove stat() syscall
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/cpu/syscall.c2
-rw-r--r--kernel/includes/syscalls.h7
-rw-r--r--kernel/syscalls/fstat.c11
-rw-r--r--kernel/syscalls/stat.c15
5 files changed, 14 insertions, 23 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 3f09855..8701f13 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,6 +1,6 @@
CC="i686-sb-gcc"
AS="i686-sb-as"
-OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o queue.o syscalls/queue.o syscalls/munmap.o syscalls/open_process.o
+OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/fstat.o libc/string/copy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o queue.o syscalls/queue.o syscalls/munmap.o syscalls/open_process.o
CFLAGS = -std=c99 -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
#CFLAGS = -std=c99 -Ofast -flto -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
#CFLAGS = -std=c99 -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c
index a33a6e2..5412915 100644
--- a/kernel/cpu/syscall.c
+++ b/kernel/cpu/syscall.c
@@ -167,7 +167,7 @@ int (*syscall_functions[])() = {
(void(*))syscall_poll, (void(*))syscall_mmap,
(void(*))syscall_accept, (void(*))syscall_bind,
(void(*))syscall_socket, (void(*))syscall_shm_open,
- (void(*))syscall_ftruncate, (void(*))syscall_stat,
+ (void(*))syscall_ftruncate, (void(*))syscall_fstat,
(void(*))syscall_msleep, (void(*))syscall_uptime,
(void(*))syscall_mkdir, (void(*))syscall_recvfrom,
(void(*))syscall_sendto, (void(*))syscall_kill,
diff --git a/kernel/includes/syscalls.h b/kernel/includes/syscalls.h
index 07a73e3..f187d4b 100644
--- a/kernel/includes/syscalls.h
+++ b/kernel/includes/syscalls.h
@@ -123,11 +123,6 @@ typedef struct SYS_SOCKET_PARAMS {
int syscall_socket(SYS_SOCKET_PARAMS *args);
-typedef struct SYS_STAT_PARAMS {
- const char *pathname;
- struct stat *statbuf;
-} __attribute__((packed)) SYS_STAT_PARAMS;
-
-int syscall_stat(SYS_STAT_PARAMS *args);
+int syscall_fstat(int fd, struct stat *buf);
u32 syscall_uptime(void);
int syscall_isatty(int fd);
diff --git a/kernel/syscalls/fstat.c b/kernel/syscalls/fstat.c
new file mode 100644
index 0000000..38346e3
--- /dev/null
+++ b/kernel/syscalls/fstat.c
@@ -0,0 +1,11 @@
+#include <errno.h>
+#include <fs/vfs.h>
+#include <syscalls.h>
+
+int syscall_fstat(int fd, struct stat *buf) {
+ if (!mmu_is_valid_userpointer(buf, sizeof(struct stat))) {
+ return -EPERM; // TODO: Is this correct? The spec says nothing about
+ // this case.
+ }
+ return vfs_fstat(fd, buf);
+}
diff --git a/kernel/syscalls/stat.c b/kernel/syscalls/stat.c
deleted file mode 100644
index 83ad3f0..0000000
--- a/kernel/syscalls/stat.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <errno.h>
-#include <fs/vfs.h>
-#include <syscalls.h>
-
-int syscall_stat(SYS_STAT_PARAMS *args) {
- const char *pathname = copy_and_allocate_user_string(args->pathname);
- struct stat *statbuf = args->statbuf;
- int fd = vfs_open(pathname, O_READ, 0);
- if (0 > fd) {
- return -ENOENT;
- }
- int rc = vfs_fstat(fd, statbuf);
- vfs_close(fd);
- return rc;
-}