Exemplo n.º 1
0
static void
syscall_handler (struct intr_frame *f ) 
{
  /* VALUE */	
  int syscall_num;
  int arg[5];
  void *esp = f->esp;
  /* VALUE */
  check_address(esp, f->esp);
  syscall_num = *(int *)esp;
  switch(syscall_num)
  {
	  case SYS_HALT:
		  halt();
		  break;
	  case SYS_EXIT:
		  get_argument(esp,arg,1);
		  exit(arg[0]);
		  break;
	  case SYS_EXEC:
		  get_argument(esp,arg,1);
		  check_valid_string((const void *)arg[0], f->esp);
		  f->eax = exec((const char *)arg[0]);
		  break;
	  case SYS_WAIT:
		  get_argument(esp,arg,1);
		  f->eax = wait(arg[0]);
		  break;
	  case SYS_CREATE:
		  get_argument(esp,arg,2);
		  check_valid_string((const void *)arg[0], f->esp);
		  f->eax = create((const char *)arg[0],(unsigned)arg[1]);
		  break;
	  case SYS_REMOVE:
		  get_argument(esp,arg,1);
		  check_valid_string((const void *)arg[0], f->esp);
		  f->eax=remove((const char *)arg[0]);
		  break;
	  case SYS_OPEN:
		  get_argument(esp,arg,1);
		  check_valid_string((const void *)arg[0], f->esp);
		  f->eax = open((const char *)arg[0]);
		  break;
	  case SYS_FILESIZE:
		  get_argument(esp,arg,1);
		  f->eax = filesize(arg[0]);
		  break;
	  case SYS_READ:
		  get_argument(esp,arg,3);
		  check_valid_buffer((void *)arg[1], (unsigned)arg[2], f->esp, true);
		  f->eax = read(arg[0],(void *)arg[1],(unsigned)arg[2]);
		  break;
	  case SYS_WRITE:
		  get_argument(esp,arg,3);
		  check_valid_buffer((void *)arg[1], (unsigned)arg[2], f->esp, false);
		  f->eax = write(arg[0],(void *)arg[1],(unsigned)arg[2]);
		  break;
	  case SYS_SEEK:
		  get_argument(esp,arg,2);
		  seek(arg[0],(unsigned)arg[1]);
		  break;
	  case SYS_TELL:
		  get_argument(esp,arg,1);
		  f->eax = tell(arg[0]);
		  break;
	  case SYS_CLOSE:
		  get_argument(esp,arg,1);
		  close(arg[0]);
		  break;
	  case SYS_MMAP:
		  get_argument(esp,arg,2);
		  f->eax = mmap(arg[0],(void *)arg[1]);
		  break;
	  case SYS_MUNMAP:
		  get_argument(esp,arg,1);
		  munmap(arg[0]);
		  break;
  }
}
Exemplo n.º 2
0
static void// 
syscall_handler (struct intr_frame *f) 
{
    int args[3];
    // The f-esp is void *, stack memory location, so dereference at location to get value
    switch (* (int *) f->esp)
    {
        case SYS_HALT:
            {
                halt();
                break;
            }
        case SYS_EXIT:
            {
                //printf("exiting\n");
                get_args(f, args, 1);
                f->eax = args[0];
                exit(args[0]);
                break;
            }
        case SYS_EXEC:
            {
                f->eax = 10;
                get_args(f, args, 1);
                args[0] = user_to_kernel_pointer((const void *) args[0]);
                f->eax = exec((const char *) args[0]);
                break;
            }
        case SYS_WRITE:
            {
                //printf("writing file\n");
                get_args(f, args, 3);
                check_valid_buffer((void *) args[1], (unsigned) args[2]);
                const void *test = user_to_kernel_pointer((const void *) args[1]);
                f->eax = write(args[0], test, (unsigned) args[2]);
                break;
            }
        case SYS_WAIT:
            {
                get_args(f, args, 1);
                f->eax = wait(args[0]);
                break;
            }
        case SYS_CREATE:
            {
                //printf("creating file\n");
                get_args(f, args, 2);
                args[0] = user_to_kernel_pointer((const void *) args[0]);
                f->eax = create((const char *) args[0], (unsigned) args[1]);
                break;
            }
        case SYS_REMOVE:
            {
                //printf("removing file\n");
                get_args(f, args, 1);
                args[0] = user_to_kernel_pointer((const void *) args[0]);
                f->eax = remove((const char *) args[0]);
            }
        case SYS_OPEN:
            {
                //printf("opening file\n");
                get_args(f, args, 1);
                args[0] = user_to_kernel_pointer((const void *) args[0]);
                f->eax = open((const char *) args[0]);
                break;
            }
        case SYS_FILESIZE:
            {
                //printf("checking filesize\n");
                get_args(f, args, 1);
                f->eax = filesize(args[0]);
            }
        case SYS_READ:
            {
                //printf("reading file\n");
                get_args(f, args, 3);
                check_valid_buffer((void *) args[1], (unsigned) args[2]);
                args[1] = user_to_kernel_pointer((const void *) args[1]);
                f->eax = read(args[0], (void *) args[1], (unsigned) args[2]);
                break;
            }
        case SYS_SEEK:
            {
                //printf("seeking file\n");
                get_args(f, args, 2);
                seek(args[0], (unsigned) args[1]);
                break;
            }
        case SYS_TELL:
            {
                //printf("telling file\n");
                get_args(f, args, 1);
                seek(args[0], (unsigned) args[1]);
                break;
            }
        case SYS_CLOSE:
            {
                //printf("closing file\n");
                get_args(f, args, 1);
                close(args[0]);
                break;
            }


    }
}