Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <syscall.h>
- #include <types.h>
- #include <lib.h>
- //per la exit
- #include <types.h>
- #include <kern/unistd.h>
- #include <clock.h>
- #include <copyinout.h>
- #include <proc.h>
- #include <thread.h>
- #include <addrspace.h>
- // per la wait_proc
- #include <synch.h>
- #include <current.h>
- #include <proc.h>
- #include <opt-syscall.h>
- #include <opt-pidtable.h>
- #if OPT_SYSCALL==1
- ssize_t sys_read(int fd, void *buf, size_t count) {
- unsigned int i;
- char* str = (char*) buf;
- if(fd != 0) //standard input
- return 0;
- for(i=0; i<count; i++) {
- str[i] = getch();
- if( str[i] == '\n') {
- str[i+1] = '\0';
- }
- }
- return i+1;
- }
- ssize_t sys_write(int fd, const void *buf, size_t count) {
- unsigned int i;
- char* str = (char*) buf;
- if(fd != 1) //standard output
- return 0;
- for(i=0; i<count; i++) {
- if( str[i] == '\0') break;
- putch(str[i]);
- }
- return i;
- }
- void sys__exit(int code) {
- kprintf("Code returned to system: %d\n", code);
- //added to work with wait() -> join
- curproc->lastStatus = code; //salvo lo stato che verrà preso nella wait_pid
- V(curproc->sem);
- //
- /*
- as_destroy(as); // libera as
- */
- thread_exit(); //esce dal thread
- panic("thread_exit returned (should not happen)\n");
- //(void) status; // TODO: status handling
- }
- #if OPT_PIDTABLE==1
- // testata correttamente :: //
- int sys_waitpid(pid_t pid) {
- struct proc * p = proc_getproc((int)pid);
- P(p->sem); //il processo si ferma e aspetta
- int status = p->lastStatus;
- /* get address space of current process and destroy */
- while( p->p_numthreads != 0); //destroy si può fare solo quando numthread è 0
- proc_destroy(p);
- //as_destroy(as); // libera as: già fatto in proc destroy
- return status;
- }
- pid_t sys_getpid(void) {
- return proc_getpid();
- }
- int sys_fork(void) {
- ///*
- struct proc* newp = NULL;
- struct addrspace* as = NULL;
- newp = proc_create_runprogram("Test");
- as = proc_getas();
- if ( newp == NULL) return -1;
- spinlock_acquire(&newp->p_lock);
- newp->p_addrspace = as;
- spinlock_release(&newp->p_lock);
- return (int) newp->pid;
- //*/ return 2;
- }
- #endif
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement