sched: properly implement blocking for read

This is a milestone update, as userspace applications are now able to
properly read from TTY devices, be blocked while waiting, and write the
output back. Userspace development will move much faster now that these
kinks have been worked out.

This version will be tagged as vbos v0.01

Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
Michael Shaw 2024-06-17 22:19:25 -04:00
commit b753afd4fb
9 changed files with 74 additions and 54 deletions

View file

@ -1,4 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include "lib/errno.h"
#include <kernel/lock.h>
#include <kernel/common.h>
#include <kernel/proc.h>
@ -15,14 +16,19 @@ typedef void *(*syscall_t)(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t
syscall_t syscall_table[SYSCALL_MAX];
slab_t *fd_slab;
uint64_t syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5)
void syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5)
{
syscall_t syscall = (void *)syscall_table[syscall_no];
if (syscall == NULL)
return -ENOSYS;
sys_set_return(proc_find(getpid()), ENOSYS);
return (uint64_t)syscall(arg1, arg2, arg3, arg4, arg5);
ssize_t ret = (ssize_t)syscall(arg1, arg2, arg3, arg4, arg5);
if (ret >= 0)
sys_set_return(proc_find(getpid()), ret);
schedule();
}
void sys_set_return(struct proc *proc, uint64_t ret)
@ -62,7 +68,7 @@ ssize_t sys_read(int fd, void *buf, size_t count)
if (file_type == VFS_VNO_CHARDEV && ret == -EAGAIN) {
struct char_device *dev = vfs_file_dev(file);
proc_block(proc, dev, buf, true, count);
schedule();
return -ESYSCALLBLK;
}
proc->state = PROC_RUNNING;