diff options
author | Anton Kling <anton@kling.gg> | 2023-11-24 21:29:12 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-24 21:29:12 +0100 |
commit | 08b63b747f9a6b4d1460195f6ca68680abcdd656 (patch) | |
tree | 0a1b8620cd3b56bf1d9b389f44876e8c391bd47e /kernel | |
parent | 6757803629574fe46e9047be8567e0c7e0522973 (diff) |
Refactor open()
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 11 | ||||
-rw-r--r-- | kernel/includes/syscalls.h | 1 | ||||
-rw-r--r-- | kernel/syscalls/open.c | 14 |
4 files changed, 16 insertions, 12 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 99ab586..1b7eea2 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 cpu/int_syscall.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 halts.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 libc/string/strncpy.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 +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 cpu/int_syscall.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 halts.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 libc/string/strncpy.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 CFLAGS = -O3 -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 INCLUDE=-I./includes/ -I../include/ -I./libc/include/ diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 2a67235..cb2b52e 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -13,17 +13,6 @@ #pragma GCC diagnostic ignored "-Wpedantic" -int syscall_open(SYS_OPEN_PARAMS *args) { - char file[256]; - strcpy(file, args->file); - // const char *file = copy_and_allocate_user_string(args->file); - int flags = args->flags; - int mode = args->mode; - int rc = vfs_open(file, flags, mode); - // kfree((void *)file); - return rc; -} - int syscall_exec(SYS_EXEC_PARAMS *args) { const char *filename = copy_and_allocate_user_string(args->path); diff --git a/kernel/includes/syscalls.h b/kernel/includes/syscalls.h index ee7efec..a431d2c 100644 --- a/kernel/includes/syscalls.h +++ b/kernel/includes/syscalls.h @@ -15,6 +15,7 @@ typedef struct SYS_ACCEPT_PARAMS { } __attribute__((packed)) SYS_ACCEPT_PARAMS; int syscall_accept(SYS_ACCEPT_PARAMS *args); +int syscall_open(const char *file, int flags, mode_t mode); void syscall_randomfill(void *buffer, u32 size); diff --git a/kernel/syscalls/open.c b/kernel/syscalls/open.c new file mode 100644 index 0000000..b42a7a8 --- /dev/null +++ b/kernel/syscalls/open.c @@ -0,0 +1,14 @@ +#include <errno.h> +#include <syscalls.h> + +int syscall_open(const char *file, int flags, mode_t mode) { + const char *_file = copy_and_allocate_user_string(file); + if (!_file) { + return -EFAULT; + } + int _flags = flags; + int _mode = mode; + int rc = vfs_open(_file, _flags, _mode); + kfree((void*)_file); + return rc; +} |