diff options
author | Anton Kling <anton@kling.gg> | 2023-11-15 21:13:36 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-15 22:11:26 +0100 |
commit | 835101f96e7c9fca00940e967c471c33e4e4dae9 (patch) | |
tree | 9c48b871d4b547fac8c3a2eda6c21242e593fdfd /kernel | |
parent | c9358cdeac4522922df46fb6e3ab6a517203ec99 (diff) |
VFS/LibC: Add getcwd()
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 2 | ||||
-rw-r--r-- | kernel/scalls/getcwd.c | 11 | ||||
-rw-r--r-- | kernel/scalls/getcwd.h | 3 |
4 files changed, 17 insertions, 1 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index eb8a90f..b5df27e 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 scalls/ppoll.o scalls/ftruncate.o kubsan.o scalls/mmap.o drivers/serial.o scalls/accept.o scalls/bind.o scalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o scalls/shm.o elf.o ksbrk.o sched/scheduler.o scalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o scalls/msleep.o scalls/uptime.o scalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o scalls/recvfrom.o math.o scalls/sendto.o signal.o scalls/kill.o scalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o scalls/chdir.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 scalls/ppoll.o scalls/ftruncate.o kubsan.o scalls/mmap.o drivers/serial.o scalls/accept.o scalls/bind.o scalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o scalls/shm.o elf.o ksbrk.o sched/scheduler.o scalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o scalls/msleep.o scalls/uptime.o scalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o scalls/recvfrom.o math.o scalls/sendto.o signal.o scalls/kill.o scalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o scalls/chdir.o scalls/getcwd.o CFLAGS = -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 INCLUDE=-I./includes/ -I./libc/include/ diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 31fa055..40a5b07 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -11,6 +11,7 @@ #include <scalls/bind.h> #include <scalls/chdir.h> #include <scalls/ftruncate.h> +#include <scalls/getcwd.h> #include <scalls/kill.h> #include <scalls/mkdir.h> #include <scalls/mmap.h> @@ -169,6 +170,7 @@ void (*syscall_functions[])() = { (void(*))syscall_mkdir, (void(*))syscall_recvfrom, (void(*))syscall_sendto, (void(*))syscall_kill, (void(*))syscall_sigaction, (void(*))syscall_chdir, + (void(*))syscall_getcwd, }; void syscall_function_handler(u32 eax, u32 arg1, u32 arg2, u32 arg3, u32 arg4, diff --git a/kernel/scalls/getcwd.c b/kernel/scalls/getcwd.c new file mode 100644 index 0000000..629d0f5 --- /dev/null +++ b/kernel/scalls/getcwd.c @@ -0,0 +1,11 @@ +#include <math.h> +#include <scalls/getcwd.h> +#include <sched/scheduler.h> + +char *syscall_getcwd(char *buf, size_t size) { + kprintf("syscall_getcwd\n"); + const char *cwd = get_current_task()->current_working_directory; + size_t len = min(size, strlen(cwd)); + strlcpy(buf, get_current_task()->current_working_directory, len); + return buf; +} diff --git a/kernel/scalls/getcwd.h b/kernel/scalls/getcwd.h new file mode 100644 index 0000000..671d7bd --- /dev/null +++ b/kernel/scalls/getcwd.h @@ -0,0 +1,3 @@ +#include <stddef.h> + +char *syscall_getcwd(char *buf, size_t size); |