bugfixes, change types.h to be linux abi, stat system call

This commit is contained in:
Matheus
2022-08-23 19:44:18 -03:00
parent 9c6ce452f8
commit 023937809d
13 changed files with 92 additions and 44 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ void* alloc(size_t size){
}
void free(void* addr){
if(pageallocator_free(addr))
if(!pageallocator_free(addr))
slab_free(addr);
}
+2 -1
View File
@@ -56,7 +56,8 @@ size_t slab_getentrysize(void* addr){
}
static void free(void* addr){
if(addr == 0)
return;
// align down to page size
slab_t *slab = (size_t)addr & ~(0xFFF);
-17
View File
@@ -71,12 +71,6 @@ static void* stacksetup(char* interp, char** argv, char** env, elf_header64 head
++envc;
}
if(interp){
argdatasize += strlen(interp) + 1;
initialsize += strlen(interp) + 1;
initialsize += sizeof(char*); // interpreter ptr
}
// pointers to args and envs
initialsize += argc*sizeof(char*); //args
@@ -97,8 +91,6 @@ static void* stacksetup(char* interp, char** argv, char** env, elf_header64 head
// count + 1 because of a null entry
char** envstart = (void*)auxvstart - (envc + 1)*sizeof(char*);
char** argstart = (void*)envstart - (argc + 1)*sizeof(char*);
if(interp)
--argstart;
size_t* argcptr = (void*)argstart - sizeof(size_t);
@@ -136,12 +128,6 @@ static void* stacksetup(char* interp, char** argv, char** env, elf_header64 head
// copy the data
if(interp){
strcpy(argdatastart, interp);
*argstart++ = argdatastart;
argdatastart += strlen(interp) + 1;
}
for(size_t i = 0; i < argc; ++i){
strcpy(argdatastart, argv[i]);
*argstart++ = argdatastart;
@@ -158,9 +144,6 @@ static void* stacksetup(char* interp, char** argv, char** env, elf_header64 head
*envstart = NULL;
if(interp)
argc++;
*argcptr = argc;
+3 -8
View File
@@ -72,12 +72,8 @@ static thread_t* allocthread(proc_t* proc, state_t state, pid_t tid, size_t ksta
return NULL;
}
// XXX use alloc() when it's better
size_t pagec = kstacksize / PAGE_SIZE + 1;
thread->kernelstackbase = pmm_hhdmalloc(pagec);
thread->kernelstackbase = alloc(kstacksize);
if(!thread->kernelstackbase){
@@ -98,8 +94,7 @@ static thread_t* allocthread(proc_t* proc, state_t state, pid_t tid, size_t ksta
static thread_t* freethread(thread_t* thread){
free(thread->regs);
// XXX use free() when it's better
pmm_free(thread->kernelstackbase, thread->stacksize / PAGE_SIZE + 1);
free(thread->kernelstack);
free(thread);
}
@@ -330,7 +325,7 @@ void sched_runinit(){
_panic("Could not load init", 0);
}
char* argv[] = {"/sbin/init", NULL};
char* argv[] = {"/usr/bin/bash", NULL};
char* env[] = {NULL};
ret = elf_load(thread, node, argv, env);
-1
View File
@@ -5,7 +5,6 @@
#include <arch/spinlock.h>
syscallret syscall_close(int ifd){
syscallret retv;
retv.ret = -1;
+1 -1
View File
@@ -69,7 +69,7 @@ syscallret syscall_open(const char* pathname, int flags, mode_t mode){
fd->flags = flags + 1; // 1 is added to make O_RDONLY etc easier to lookup
fd->offset = 0;
vnode_t* file;
vnode_t* file = NULL;
size_t ret = vfs_open(&file,
*name == '/' ? proc->root : proc->cwd,
+2
View File
@@ -57,6 +57,8 @@ syscallret syscall_read(int ifd, void* buff, size_t count){
retv.errno = 0;
retv.ret = readc;
free(kbuff);
return retv;
}
+51
View File
@@ -0,0 +1,51 @@
#include <kernel/syscalls.h>
#include <sys/stat.h>
#include <kernel/vmm.h>
#include <errno.h>
#include <kernel/vfs.h>
#include <kernel/sched.h>
#include <arch/cls.h>
#include <kernel/alloc.h>
#include <string.h>
syscallret syscall_stat(const char* path, stat* st){
syscallret retv;
retv.ret = -1;
if(st > USER_SPACE_END){
retv.errno = EFAULT;
return retv;
}
char* kpath = alloc(strlen(path)); // XXX use proper user strlen func
if(!path){
retv.errno = ENOMEM;
return retv;
}
strcpy(kpath, path); // XXX use user strcpy func
vnode_t* file;
proc_t* proc = arch_getcls()->thread->proc;
int ret = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath);
if(ret){
retv.errno = ret;
goto _ret;
}
stat stbuff = file->st;
vfs_close(file);
memcpy(st, &stbuff, sizeof(stat)); // XXX use user memcpy
_ret:
free(kpath);
return retv;
}