thread: remove struct proc abstraction

struct proc was a redundant abstraction. everything can be tracked by
just threads

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-12 21:24:38 -04:00
commit e41877b268
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
16 changed files with 646 additions and 120 deletions

View file

@ -8,12 +8,12 @@
static struct file *check_fd(int fd)
{
struct proc *proc = get_cur_proc();
struct thread *thread = get_cur_thread();
if (fd >= proc->fd_array_size)
if (fd >= thread->fd_array_size)
return NULL;
struct file *f = proc->fdt + fd;
struct file *f = thread->fdt + fd;
if (!f->dirent)
return NULL;
@ -68,7 +68,7 @@ static ssize_t sys_write(int fd, const void *buf, size_t nbyte)
static int sys_open(const char *path, int flags)
{
struct proc *proc = get_cur_proc();
struct thread *thread = get_cur_thread();
dirent_t *f;
int res = vfs_open(path, &f);
@ -76,12 +76,12 @@ static int sys_open(const char *path, int flags)
if (res < 0)
return res;
spinlock_acquire(&proc->fd_lock);
spinlock_acquire(&thread->fd_lock);
int fdno = -1;
for (int i = 0; i < proc->fd_array_size; i++) {
struct file *fd = proc->fdt + i;
for (int i = 0; i < thread->fd_array_size; i++) {
struct file *fd = thread->fdt + i;
if (!fd->dirent) {
memset(fd, 0, sizeof(struct file));
fdno = i;
@ -90,47 +90,47 @@ static int sys_open(const char *path, int flags)
}
if (fdno == -1) {
size_t osize = proc->fd_array_size;
size_t osize = thread->fd_array_size;
size_t newsize = MAX(osize * 2, 32);
void *new = krealloc(proc->fdt, newsize, ALLOC_KERN);
void *new = krealloc(thread->fdt, newsize, ALLOC_KERN);
if (!new) {
vfs_close(f);
return -ENOMEM;
}
proc->fd_array_size = newsize;
proc->fdt = new;
thread->fd_array_size = newsize;
thread->fdt = new;
memset(proc->fdt + osize, 0, newsize - osize);
struct file *fd = proc->fdt + osize;
memset(thread->fdt + osize, 0, newsize - osize);
struct file *fd = thread->fdt + osize;
fd->dirent = f;
fd->flags = flags;
fd->refcount = 1;
fdno = osize;
}
spinlock_release(&proc->fd_lock);
spinlock_release(&thread->fd_lock);
return fdno;
}
static int sys_close(int fd)
{
struct proc *proc = get_cur_proc();
struct thread *thread = get_cur_thread();
if (fd >= proc->fd_array_size)
if (fd >= thread->fd_array_size)
return -EBADF;
struct file *f = proc->fdt + fd;
struct file *f = thread->fdt + fd;
if (!f->dirent)
return -EBADF;
spinlock_acquire(&proc->fd_lock);
spinlock_acquire(&thread->fd_lock);
vfs_close(f->dirent);
memset(f, 0, sizeof(struct file));
spinlock_acquire(&proc->fd_lock);
spinlock_acquire(&thread->fd_lock);
return 0;
}