diff options
author | Anton Kling <anton@kling.gg> | 2023-11-24 21:47:02 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-24 21:47:02 +0100 |
commit | 4764846cc2afe0e56f4490e3973b7322c2129e29 (patch) | |
tree | 64aa0b7df0f5422a6c52f0b67f4b9a9158bfa8da /kernel | |
parent | 08b63b747f9a6b4d1460195f6ca68680abcdd656 (diff) |
Refactor write() and pwrite()
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 47 | ||||
-rw-r--r-- | kernel/includes/syscalls.h | 2 | ||||
-rw-r--r-- | kernel/syscalls/pwrite.c | 6 | ||||
-rw-r--r-- | kernel/syscalls/write.c | 12 |
5 files changed, 38 insertions, 31 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 1b7eea2..0778cb3 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 syscalls/open.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 syscalls/write.o syscalls/pwrite.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 cb2b52e..9aecc42 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -53,19 +53,6 @@ int syscall_read(SYS_READ_PARAMS *args) { return rc; } -int syscall_pwrite(SYS_PWRITE_PARAMS *args) { - return vfs_pwrite(args->fd, args->buf, args->count, args->offset); -} - -int syscall_write(int fd, const char *buf, size_t count) { - vfs_fd_t *fd_ptr = get_vfs_fd(fd); - if (!fd_ptr) - return -EBADF; - int rc = vfs_pwrite(fd, (char *)buf, count, fd_ptr->offset); - fd_ptr->offset += rc; - return rc; -} - int syscall_dup2(SYS_DUP2_PARAMS *args) { return vfs_dup2(args->org_fd, args->new_fd); } @@ -127,23 +114,23 @@ int syscall_openpty(SYS_OPENPTY_PARAMS *args) { } void (*syscall_functions[])() = { - (void(*))syscall_open, (void(*))syscall_read, - (void(*))syscall_write, (void(*))syscall_pread, - (void(*))syscall_pwrite, (void(*))syscall_fork, - (void(*))syscall_exec, (void(*))syscall_getpid, - (void(*))syscall_exit, (void(*))syscall_wait, - (void(*))syscall_brk, (void(*))syscall_sbrk, - (void(*))syscall_pipe, (void(*))syscall_dup2, - (void(*))syscall_close, (void(*))syscall_openpty, - (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_msleep, (void(*))syscall_uptime, - (void(*))syscall_mkdir, (void(*))syscall_recvfrom, - (void(*))syscall_sendto, (void(*))syscall_kill, - (void(*))syscall_sigaction, (void(*))syscall_chdir, - (void(*))syscall_getcwd, (void(*))syscall_isatty, + (void(*))syscall_open, (void(*))syscall_read, + (void(*))syscall_write, (void(*))syscall_pread, + (void(*))syscall_pwrite, (void(*))syscall_fork, + (void(*))syscall_exec, (void(*))syscall_getpid, + (void(*))syscall_exit, (void(*))syscall_wait, + (void(*))syscall_brk, (void(*))syscall_sbrk, + (void(*))syscall_pipe, (void(*))syscall_dup2, + (void(*))syscall_close, (void(*))syscall_openpty, + (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_msleep, (void(*))syscall_uptime, + (void(*))syscall_mkdir, (void(*))syscall_recvfrom, + (void(*))syscall_sendto, (void(*))syscall_kill, + (void(*))syscall_sigaction, (void(*))syscall_chdir, + (void(*))syscall_getcwd, (void(*))syscall_isatty, (void(*))syscall_randomfill, }; diff --git a/kernel/includes/syscalls.h b/kernel/includes/syscalls.h index a431d2c..7b2a966 100644 --- a/kernel/includes/syscalls.h +++ b/kernel/includes/syscalls.h @@ -16,6 +16,8 @@ typedef struct SYS_ACCEPT_PARAMS { int syscall_accept(SYS_ACCEPT_PARAMS *args); int syscall_open(const char *file, int flags, mode_t mode); +int syscall_write(int fd, const char *buf, size_t count); +int syscall_pwrite(int fd, const char *buf, size_t count, size_t offset); void syscall_randomfill(void *buffer, u32 size); diff --git a/kernel/syscalls/pwrite.c b/kernel/syscalls/pwrite.c new file mode 100644 index 0000000..b1e47fe --- /dev/null +++ b/kernel/syscalls/pwrite.c @@ -0,0 +1,6 @@ +#include <fs/vfs.h> +#include <syscalls.h> + +int syscall_pwrite(int fd, const char *buf, size_t count, size_t offset) { + return vfs_pwrite(fd, (char*)buf, count, offset); +} diff --git a/kernel/syscalls/write.c b/kernel/syscalls/write.c new file mode 100644 index 0000000..bdd3927 --- /dev/null +++ b/kernel/syscalls/write.c @@ -0,0 +1,12 @@ +#include <fs/vfs.h> +#include <syscalls.h> +#include <errno.h> + +int syscall_write(int fd, const char *buf, size_t count) { + vfs_fd_t *fd_ptr = get_vfs_fd(fd); + if (!fd_ptr) + return -EBADF; + int rc = vfs_pwrite(fd, (char *)buf, count, fd_ptr->offset); + fd_ptr->offset += rc; + return rc; +} |