int sys_link() { char *old_path, *new_path; if(argptr(0, &old_path, 1) < 0 || argptr(1, &new_path, 1) < 0) return -1; return ilink(old_path, new_path); }
//Create a new thread int sys_thread_create(void) { char* tmain, *stack, *arg; if (argptr(0, &tmain, 1) < 0 || argptr(1, &stack, 1) < 0 || argptr(2, &arg, 1) < 0) return -1; return thread_create((void*)tmain, (void*)stack, (void*)arg); }
int sys_waitstat(void) { int *turnaround; int *runningtime; int n; if(argptr(0, &turnaround,n) < 0) return -1; if(argptr(1, &runningtime,n) < 0) return -1; return waitstat(turnaround, runningtime); }
int sys_t_sleep(void) { void *chan, *p_lk; if(argptr(0, (void *)&chan, sizeof(void *)) < 0) { return -1; } if(argptr(1, (void *)&p_lk, sizeof(void *)) < 0) { return -1; } t_sleep(chan, (lock_t*)p_lk); return 0; }
int sys_waitpid(void) { int pid; argptr(0,(char**) &pid, 4); //Read PID variable from stack 4 bytes = int int *status; argptr(1,(char**) &status, 4); //Get reference to Status int options; argptr(2, (char**) &options, 4); return waitpid(pid, status, options); //int stuff; //return waitpid(0, &stuff, 0); }
int sys_clone(void){ void* fcn; void* arg; void* stack; if(argptr(0, (void*)&fcn, sizeof(void *)) < 0){ return -1; } if(argptr(1, (void*)&arg, sizeof(void *)) < 0){ return -1; } if(argptr(2, (void*)&stack, sizeof(void *)) < 0){ return -1; } return clone(fcn, arg, stack); }
int sys_csleep(void) { void *chan; lock_t *lk; if (argptr(0, (void*)&chan, sizeof(chan)) < 0) { return -1; } if (argptr(1, (void*)&lk, sizeof(lk)) < 0) { return -1; } csleep(chan, lk); return 0; }
/********************STUDENT********************/ int sys_wait2(void) { int *w, *r; int m, n; n = argptr(0, (void *) &w, sizeof(*w)); m = argptr(1, (void *) &r, sizeof(*r)); if (m < 0 || n < 0) return -1; return wait2(w, r); }
int sys_clone(void) { void (*fcn)(void*); void* arg; void* stack; if(argptr(0, (void*)&fcn, sizeof(void*)) < 0) return -1; if(argptr(1, (void*)&arg, sizeof(void*)) < 0) return -1; if(argptr(2, (void*)&stack, sizeof(void*)) < 0) return -1; return clone(fcn, arg, stack); }
int sys_unlink() { char *path; if(argptr(0, &path, 1) < 0) return -1; return iunlink(path); }
int sys_checkpoint(void) { char *p = 0; if (argptr(0, &p, sizeof(struct proc)) < 0) return -1; return checkpoint((struct proc *) p); }
int sys_wait(void) { int *status; argptr(0, (char **) &status, sizeof(int*)); return wait(status); }
// thread library int sys_clone(void) { void * ptr; argptr(0, (char **) &ptr, sizeof(void*)); return clone(ptr); }
long sys_write(SyscallFrame *f) { int fd; long l; uintptr buf; usize nbytes; File *file; // fd if (argfd(f, 0, &fd) < 0) return -1; // nbytes (needed for argptr) if (arglong(f, 2, &l) < 0) { // todo errstr return -1; } nbytes = (usize)l; // buf if (argptr(f, 1, &buf, nbytes) < 0) { // todo errstr return -1; } file = proc->files[fd]; if (!(file->omode &(OWRITE | ORDWR))) { // todo errstr return -1; } return file->write(file, (char *)buf, nbytes); }
int clone(void) { char* stack; int i, pid, size; struct proc *np; cprintf("a\n"); // Allocate process. if((np = allocproc()) == 0) return -1; // Point page dir at parent's page dir (shared memory) np->pgdir = proc->pgdir; // This might be an issue later. np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; if(argint(1, &size) < 0 || size <= 0 || argptr(0, &stack, size) < 0) { kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } <<<<<<< HEAD
int sys_alarm(void) { /*PID = fork(); if(PID > 0) { cprintf("PID: %d\n", PID); cprintf("\nSoy el padre\n"); PID=wait(); } else if(PID == 0) { cprintf("PID: %d\n", PID); cprintf("\nSoy el hijo\n"); exit(); }*/ int ticks; void (*handler)(); /* cprintf("funciona\n"); //cprintf("%d\n",ticksG); cprintf("%d\n",handler); cprintf("%d\n",ticks);*/ //cprintf("%d\n",&sys_getpid); if(argint(0, &ticks) < 0) return -1; if(argptr(1, (char**)&handler, 1) < 0) return -1; proc->alarmticks = ticks; proc->alarmhandler = handler; //cprintf("%d\n",proc->pid); //proc->ticksInicio = ticksG; return 0; }
int sys_clone(void) { char* p1; char* p2; //void(*fcn)(void*); char* p0; if(argptr(0, &p0, 4 < 0 || argptr(2, &p2, 4) < 0 || argptr(1, &p1, 1) < 0)) return -1; /*p1 = (void*)p1; p2 = (void*)p2; p0 = (void (*)(void *))p0;*/ return clone((void (*)(void *))p0, (void*)p1, (void*)p2); }
int sys_join(void){ void** stack; if(argptr(0, (void*)&stack, sizeof(void *)) < 0){ return -1; } return join(stack); }
//TODO shai start int sys_wait2(void){ char *wtime; char *rtime; //check and init the arguments int check = argptr(0, &wtime, sizeof(wtime)); check = check + argptr(1, &rtime, sizeof(rtime)); //execute if args are correct if(!check){ return (wait2((int*)wtime, (int*)rtime)); } else{ return -1; } }
int sys_restore(void) { char *p = 0; if (argptr(0, &p, sizeof(struct checkpoint_t)) < 0) return -1; return restore((struct checkpoint_t *)p); }
int sys_write(struct file *f, char *p, int n) { if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) return -1; return filewrite(f, p, n); }
//returns pstat with some basic information about each running process //how many times its run, pid, and which queue its on(high or low) int sys_getpinfo(void) { struct pstat *ps; if(argptr(0,(void*)&ps,sizeof(struct pstat *) < 0)) return -1; //*ps = proc->pstat_t; *ps = pst; return 0; }
int sys_fstat(struct file *f, struct stat *st) { if(argfd(0, 0, &f) < 0 || argptr(1, (void*)&st, sizeof(*st)) < 0) return -1; return filestat(f, st); }
int sys_history(void) { int n; char * p; argptr(0, &p, 128); argint(1, &n); return history(p, n); }
int sys_getMsg() { struct Msg* ptr; if (argptr(0, (void*)&ptr, sizeof(*ptr)) < 0) return -1; getMsg(proc->pid, ptr); return 0; }
int sys_sem_broadcast(void) { struct semaphore * sem; argptr(0, (char **) &sem, sizeof(struct semaphore*)); sem_broadcast(sem); return 0; }
int sys_gettime(void) { struct rtcdate *d; if (argptr(0, (char **)&d, sizeof(struct rtcdate)) < 0) return -1; cmostime(d); return 0; }
int sys_exit(void) { int status; argptr(0, (char **) &status, 4); exit(status); return 0; // not reached }
int sys_cvwait(void) { void *cond; void *lock; if(argptr(0,(char**)&cond,sizeof(cond))<0) { return -1; } if(argptr(1,(char**)&lock,sizeof(lock))<0) { return -1; } cvwait(cond,lock); return 0; }
int sys_wait2(void) { char *rtime=0; char *wtime=0; argptr(1,&rtime,sizeof(rtime)); argptr(0,&wtime,sizeof(wtime)); return wait2((int*)wtime, (int*)rtime); }