summaryrefslogtreecommitdiff
path: root/kernel/syscalls.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-18 03:03:28 +0200
committerMiguel <m.i@gmx.at>2018-09-18 03:03:28 +0200
commit2d91384197847a7e8fe2c3f548918a8277d3086d (patch)
tree7c93404e290a0ffbdaf9a8a94766d7bd0fd6e4f2 /kernel/syscalls.c
parent06e6e427c76bdb88a7f72dd04411d95a4bda3270 (diff)
sysfs, errno, improve foolshell, etc
Diffstat (limited to 'kernel/syscalls.c')
-rw-r--r--kernel/syscalls.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 8b5040a..aa20616 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -17,6 +17,15 @@
#include "log.h"
#include "timer.h"
#include "mount.h"
+#include "mem.h"
+#include "reent.h"
+#include "errno.h"
+
+void set_errno(int no)
+{
+ struct _reent *impure_ptr=VMEM_USER_NEWLIB;
+ impure_ptr->_errno=no;
+}
static fd fds[MAX_FD];
static uint32_t next_fd=0;
@@ -148,7 +157,7 @@ int syscall_write(int file, char *buf, int len)
*/
int syscall_read(int file, char *buf, int len)
{
- if(fds[file].type==FD_TYPE_EXT2_FILE && !fd_has(&fds[file]))return 0;
+ if(fd_eof(&fds[file]))return 0;
*buf=fd_read(&fds[file]);
return 1;
}
@@ -217,36 +226,28 @@ int copy_args(char **in, char **out)
return count;
}
-int syscall_execve(char *name, char **argv, char **env,int pid)
+/** does not return on success otherwise -1 and errrno set */
+int syscall_execve(const char *name, char *const argv[], char *const env[], int pid)
{
+
fixme("not overwrite yourself?");
int arg_count=0;
while(argv[arg_count]!=NULL)arg_count++;
char **argv1=VMEM_USER_ENV;
- if(argv!=NULL)
- {
- copy_args(argv,argv1);
- }
- else{
- argv1=NULL;
- }
+ if(argv!=NULL)copy_args(argv,argv1);
+ else argv1=NULL;
char **env1=VMEM_USER_ENV+1024*2;
- if(env!=NULL)
- {
- copy_args(env,env1);
- }
- else{
- env1=NULL;
- }
+ if(env!=NULL)copy_args(env,env1);
+ else env1=NULL;
uint32_t alloc;
uint32_t entry_global=load_elf(name,&alloc);
- if(!entry_global)
- {
- return -1; // errror loading
+ if(!entry_global){
+ set_errno(ENOENT);
+ return -1;
}
uint32_t *stack=VMEM_USER_STACK_TOP-4*32;
@@ -255,26 +256,6 @@ int syscall_execve(char *name, char **argv, char **env,int pid)
*--stack=env1;
task_reset(pid,entry_global,stack,alloc);
return 0;
-
- /* try to move this to asm */
- // asm volatile("jmp ."); // loop forever
- //klog("returning to jump addy (0x%08X)", entry_global);
- /*
- asm volatile("mov $0x08fff000,%esp"); // set stack at high end of process image
-
- asm volatile ("push %0" :: "r" (argv1));
- asm volatile ("push %0" :: "r" (arg_count));
- //asm volatile ("push %0" :: "r" (kballoc(1)));
- asm volatile ("push %0" :: "r" (env1));
-
- // push addr and return to it
- asm volatile ("pushl %0"::"r"(entry_global));
-
- asm volatile ("sti");
- asm volatile ("ret");
- */
-
- // this is never reached!
}
// minihack
@@ -402,7 +383,6 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3,
case SYSCALL_WAIT :
return !task_runs(p1);
case SYSCALL_READ :
- if(fds[p1].type==FD_TYPE_EXT2_FILE)return 1;
return fd_has(&fds[p1]);
case SYSCALL_EXIT :
return 1;