fs: fix bugs that broke processes in userspace

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-21 05:50:22 -04:00
commit b603eacbb7
3 changed files with 6 additions and 7 deletions

View file

@ -84,25 +84,24 @@ static int sys_open(const char *path, int flags)
struct file *fd = proc->fdt + i; struct file *fd = proc->fdt + i;
if (!fd->dirent) { if (!fd->dirent) {
memset(fd, 0, sizeof(struct file)); memset(fd, 0, sizeof(struct file));
fd->dirent = f;
fd->flags = flags;
fd->refcount = 1;
fdno = i; fdno = i;
break;
} }
} }
if (fdno == -1) { if (fdno == -1) {
size_t osize = proc->fd_array_size; size_t osize = proc->fd_array_size;
size_t newsize = MIN(osize * 2, 32); size_t newsize = MAX(osize * 2, 32);
void *new = krealloc(proc->fdt, newsize, ALLOC_KERN); void *new = krealloc(proc->fdt, newsize, ALLOC_KERN);
if (!new) { if (!new) {
vfs_close(f); vfs_close(f);
return -ENOMEM; return -ENOMEM;
} }
proc->fd_array_size = newsize;
proc->fdt = new; proc->fdt = new;
memset(proc->fdt + osize, 0, osize); memset(proc->fdt + osize, 0, newsize - osize);
struct file *fd = proc->fdt + osize; struct file *fd = proc->fdt + osize;
fd->dirent = f; fd->dirent = f;
fd->flags = flags; fd->flags = flags;

View file

@ -126,7 +126,7 @@ void *krealloc(void *old, size_t size, u64 flags)
rbnode_t *node = rbt_search(&kalloc_tree, (u64)old); rbnode_t *node = rbt_search(&kalloc_tree, (u64)old);
if (!node) if (!node)
return NULL; return kalloc(size, flags);
struct alloc_entry *entry = (void *)node->value; struct alloc_entry *entry = (void *)node->value;

View file

@ -105,7 +105,7 @@ static void map_hhdm_zones(pgd_t *pgd_table)
} }
hhdm_end = top_paddr; hhdm_end = top_paddr;
device_base = ALIGN_UP(hhdm_end + PAGE_SIZE, PAGE_SIZE); device_base = ALIGN_UP((u64)TO_VIRT(hhdm_end) + PAGE_SIZE, PAGE_SIZE);
for (paddr_t p = 0; p < top_paddr; p += 0x200000) { for (paddr_t p = 0; p < top_paddr; p += 0x200000) {
vaddr_t v = (vaddr_t)TO_VIRT(p); vaddr_t v = (vaddr_t)TO_VIRT(p);