示例#1
0
static bool syscall_create (const char *file, unsigned initial_size)
{
  lock_acquire (&filesys_lock);
  bool retval = filesys_create (file, initial_size);
  lock_release (&filesys_lock);
  return retval;
}
示例#2
0
static bool mkdir_handler (const char *dir) {
  if (dir == NULL) {
    exit_handler(-1);
  }
  bool success = filesys_create(dir, 0, 1);
  return success;
}
示例#3
0
static bool create_handler (const char *file, unsigned initial_size) {
  if (file == NULL) {
    exit_handler(-1);
  }

  bool success = filesys_create(file, initial_size, 0);
  return success; 
}
示例#4
0
static bool
sys_create (void *file_, unsigned initial_size, struct intr_frame *f)
{
  bool success;
  success = filesys_create ((char*)file_, initial_size);
  f->eax = (uint32_t) success;
  return success;
}
示例#5
0
文件: syscall.c 项目: GunjuKo/Pintos
/* create file */
bool
create(const char *file, unsigned initial_size)
{
	bool result=false;
	if(filesys_create(file,initial_size)==true)
		result=true;
	return result;
}
示例#6
0
文件: syscall.c 项目: ozensoydc/OS-p3
bool
create(const char *file, unsigned initial_size)
{
    lock_acquire(&filesys_lock);
    bool i = filesys_create(file, initial_size);
    lock_release(&filesys_lock);
    return i;
}
示例#7
0
static void sys_create(struct intr_frame *f_)
{
  unsigned int *esp = f_->esp;
  char *file = *(esp + 1);
  unsigned int initial_size = *(esp + 2);
  
  f_->eax = filesys_create(file, initial_size);
}
示例#8
0
bool create (const char* file, unsigned initial_size)
{
    //Do filesys call
    lock_acquire(&file_lock);
    bool ret = filesys_create(file, initial_size);
    lock_release(&file_lock);

    return ret;
}
示例#9
0
bool sys_create(const char* file, unsigned initial_size)
{
    if (filesys_create(file, initial_size) && initial_size >= 0)
    {
        map_insert(get_filemap(), filesys_open(file));
        return true;
    }
    return false;
}
示例#10
0
/* Create system call. */
static int
sys_create (const char *ufile, unsigned initial_size) 
{
  char *kfile = copy_in_string (ufile);
  bool ok = filesys_create (kfile, initial_size, FILE_INODE);
  palloc_free_page (kfile);
 
  return ok;
}
示例#11
0
int sys_create(char* file_name, int size)
{
  int ret;
  if(!*file_name)  // empty string check
    return 0;
  lock_acquire(&filesys_lock);
  ret = filesys_create(file_name, size);
  lock_release(&filesys_lock);
  return ret;
}
示例#12
0
文件: syscall.c 项目: chutchUCD/OS
bool sys_create(const char* filename, unsigned initial_size) {
  bool return_code;

  // memory validation
  check_user((const uint8_t*) filename);

  lock_acquire (&filesys_lock);
  return_code = filesys_create(filename, initial_size, false);
  lock_release (&filesys_lock);
  return return_code;
}
示例#13
0
bool
create(const char *file, unsigned initial_size)
{
  if (not_valid(file))
    exit (-1);

  lock_acquire(&file_lock);
  bool result = filesys_create (file, initial_size);
  lock_release(&file_lock);
  return result;
}
示例#14
0
/*
 * System Call: bool create (const char *file, unsigned initial_size)
 * Creates a new file called file initially initial_size bytes in size.
 * Returns true if successful, false otherwise. Creating a new file does
 * not open it: opening the new file is a separate operation which would
 * require a open system call.
 */
bool create_handler(const char *file, unsigned initial_size) {
	//printf("creating: %c\n",*file);
	if (string_access_ok(file) && *file!='\0') {
		lock_acquire (&fic_m);
		bool ret = filesys_create (file, initial_size);
		lock_release (&fic_m);
		return ret;
	} else {
		//printf("can't create!");
		return false;
	}
}
示例#15
0
/*
 * creates new files
 */
void
syscall_create (struct intr_frame *f)
{
  const int argz = 2;
  int args[argz];
  syscall_get_args(f,args,argz);
  args[0] = syscall_user_to_kernel_vaddr((const void *) args[0]);

  /* lock so that you can only create one file at a time */
  lock_acquire(&flock);
  f->eax = filesys_create( (const char *)args[0], (unsigned)args[1]);
  lock_release(&flock);
}
示例#16
0
/* Creates a new file in the file system with the name file that is
   initial_size bytes long.  Returns a bool indicating if the file
   creation was successful */
static bool
sys_create (const char *file, unsigned initial_size)
{
  bool success;

  check_ptr (file);
  
  lock_acquire (&fs_lock);
  success = filesys_create (file, initial_size);
  lock_release (&fs_lock);
  
  return success;
}
示例#17
0
/* Creates file called 'file' that is initially 'initial_size' bytes.
   Returns true if successful. Creating a file does NOT open it. */
static bool
sys_create(const char *file, unsigned initial_size) 
{
  check_mem_ptr(file);

  if (file == NULL)
    sys_exit(ERROR);

  lock_acquire(&secure_file);
  bool success = filesys_create(file, initial_size);
  lock_release(&secure_file);

  return success;
}
示例#18
0
/* Create system call. */
static int
sys_create (const char *ufile, unsigned initial_size) 
{
  char *kfile = copy_in_string (ufile);
  bool ok;

  lock_acquire (&fs_lock);
  ok = filesys_create (kfile, initial_size);
  lock_release (&fs_lock);

  palloc_free_page (kfile);
 
  return ok;
}
示例#19
0
void create (struct intr_frame *f) {
	
	char * filename = *(char **)value_stack(f->esp,4);
	unsigned size = *value_stack_int(f->esp,8);
	bool success = false;

	if (strnlen(filename,32) == 0) {
		f->eax = success;
		return;
	}

	success = filesys_create (filename, size,FILE_FILE);

	f->eax = success;
}
示例#20
0
void mkdir (struct intr_frame *f) {

	const char * dirname = *(char **)value_stack(f->esp,4);

	//if empty or root return
	if(strlen(dirname) ==  0 || strcmp( dirname, "/") == 0) { 
		f->eax = 0;
		return;
	}

	bool success = filesys_create(dirname, 0,FILE_DIR);
	
	if ( success ) f->eax = 1;
	else f->eax = 0;
	
}
示例#21
0
文件: syscall.c 项目: roooot/pintos
/* Create new file. */
static bool
sys_create (const char *file, unsigned initial_size)
{
  bool success;

#if PRINT_DEBUG
  printf ("[SYSCALL] SYS_CREATE: file: %s, initial_size: %u\n", file, initial_size);
#endif

  if (file == NULL || !is_user_vaddr (file))
    sys_exit (-1);

  lock_acquire (&file_lock);
  success = filesys_create (file, initial_size);
  lock_release (&file_lock);
  return success;
}
示例#22
0
static bool
my_create(const char *file, unsigned initial_size)
{
	lock_acquire(&filesys_lock);
	
	if(file == NULL){
        lock_release(&filesys_lock);
        my_exit(-1);
	}
	if(!address_valid(file)){
		lock_release(&filesys_lock);
		my_exit(-1);
	}

	bool success = filesys_create(file, initial_size);
	lock_release(&filesys_lock);
	return success;
}
示例#23
0
static void
syscall_handler (struct intr_frame *f)
{
  uint32_t *p = f->esp;
  check_ptr(p);
  switch (*(int *)p)
  {
  /* Halt the operating system.
    IN : void
    OUT: void
  */
  case SYS_HALT:
  {
    shutdown_power_off();
    break;
  }

  /* Terminate this process.
    IN : int status
    OUT: void
  */
  case SYS_EXIT:
  {
    check_ptr(p + 1);
    int status = *(int *)(p + 1);
    exit(status);
    break;
  }


  /* Start another process.
    IN : const char *file
    OUT: pid_t
  */
  case SYS_EXEC:
  {
    check_string(p + 1);
    // f->eax = process_execute(*(char **)(p + 1));
    pid_t pid = process_execute(*(char **)(p + 1));
    struct child_process *cp = get_child_process(pid);
    if(cp->load == LOAD_SUCCESS)
      f->eax = pid;
    else if(cp->load == LOAD_FAIL)
      f->eax = -1;
    break;
  }

  /* Wait for a child process to die.
    IN : pid_t
    OUT: int
  */
  case SYS_WAIT:
  {
    check_ptr(p + 1);
    f->eax = process_wait(*(tid_t *)(p + 1));
    break;
  }

  /* Create a file.
    IN :const char *file, unsigned initial_size
    OUT:bool
  */
  case SYS_CREATE:
  {
    check_string(p + 1);
    check_ptr(p + 2);
    if(*(char**)(p+1)==NULL||*(int *)(p+1)>=PHYS_BASE||
      pagedir_get_page(thread_current()->pagedir, (const void *)*(p+1)) == NULL)
      exit(-1);
    
    f->eax = filesys_create(*(const char **)(p + 1), *(off_t *)(p + 2));
    
    break;
  }

  /* Delete a file.
    IN: const char *file
    OUT: bool
  */
  case SYS_REMOVE:
  {

    check_string(p + 1);
    if(*(char**)(p+1)==NULL||*(int *)(p+1)>=PHYS_BASE||
      pagedir_get_page(thread_current()->pagedir, (const void *)*(p+1)) == NULL)
      exit(-1);
    
    f->eax = filesys_remove(*(char**)(p + 1));
    break;
  }

  /* Open a file.
    IN: const char *file
    OUT: int
  */
  case SYS_OPEN:
  {
    check_string(p + 1);
    
    struct file *file = filesys_open(*(char**)(p + 1));
    if (file == NULL)
    {
      f->eax = -1;
      break;
    }
    struct file_desc *desc = malloc(sizeof(struct file_desc));
    desc->file = file;
    desc->fd = thread_current()->fd;
    thread_current()->fd++;
    list_push_back(&thread_current()->file_list, &desc->elem);
    f->eax = desc->fd;
    break;
  }

  /* Obtain a file's size.
    IN: int fd
    OUT: int
  */
  case SYS_FILESIZE:
  {
    check_ptr(p + 1);
    int fd = *(p + 1);
    
    struct file *file = process_get_file(fd);
    if (file == NULL)
    {
      f->eax = FILE_ERROR;
    }
    else
    {
      f->eax = file_length(file);
    }
    break;
  }

  /* Read from a file.
    IN: int fd, void *buffer, unsigned length
    OUT: int
  */
  case SYS_READ:
  {
    check_ptr(p + 1);
    check_ptr(p + 2);
    check_ptr(p + 3);
    check_buffer(p + 2, *(p + 3));

    int fd = *(int *)(p + 1);
    void *buffer = *(char**)(p + 2);
    unsigned length = *(unsigned *)(p + 3);

    //read from keyboard. Fd 0 reads from keyboard using input_getc(): one each time.
    if (fd == STDIN_FILENO)
    {
      uint8_t *into_buffer = (uint8_t *) buffer;
      unsigned i;
      for (i = 0; i < length; i++)
      {
        into_buffer[i] = input_getc();
      }
      f->eax = length;
    }
    else
    {
      //read from file into buffer
      
      struct file *file = process_get_file(fd);
      //return -1 if file couldn't be read.
      if (file == NULL)
      {
            f->eax = FILE_ERROR;  //-1
      }
      else
      {
        int bytes = file_read(file, buffer, length);
            f->eax = bytes;
      }

    }
    break;
  }

  /* Write to a file.
    IN: int fd, const void *buffer, unsigned length
    OUT: int
  */
  case SYS_WRITE:
  {
    check_ptr(p + 1);
    check_ptr(p + 2);
    check_ptr(p + 3);
    check_buffer(p + 2, *(p + 3));

    int fd = *(int *)(p + 1);
    void *buffer = *(char**)(p + 2);
    unsigned length = *(off_t *)(p + 3);
    if (length <= 0)
    {
      f->eax = 0;
      break;
    }
    //Fd=1(STDOUT_FILENO) writes to the console.
    if (fd == STDOUT_FILENO)
    {
      putbuf(buffer, length);
      f->eax = length;
    }
    else
    {
      // return file by file descriptor.
      struct file *file = process_get_file(fd);
      if (file == NULL)
      {
            f->eax = FILE_ERROR;  //-1
      }
      else
      {
        int bytes = file_write(file, buffer, length);
        f->eax = bytes;
      }
    }
    break;
  }

  /* Change position in a file.
    IN: int fd, unsigned position
    OUT: void
  */
  case SYS_SEEK:
  {
    check_ptr(p + 1);
    check_ptr(p + 2);
    int fd = *(int *)(p+1);
    unsigned position = *(unsigned *)(p+2);
    
    struct file *file = process_get_file(fd);
    if(file != NULL)
    {
      file_seek(file, position);
    }
    break;
  }

  /* Report current position in a file.
    IN: int fd
    OUT: unsigned
  */
  case SYS_TELL:
  {
    check_ptr(p + 1);
    int fd = *(int *)(p+1);

    
    struct file *file = process_get_file(fd);
    if(file != NULL)
    {
      f->eax = file_tell(file);
    }
    else
      f->eax = FILE_ERROR;  //-1
    break;
  }

  /* Close a file.
    IN: int fd
    OUT: void
  */
  case SYS_CLOSE:
  {
    check_ptr(p+1);
    int fd = *(int*)(p+1);
    
    struct thread *t = thread_current();
    struct list_elem *next, *e = list_begin(&t->file_list);
    while (e != list_end (&t->file_list))
    {
      next = list_next(e);
      struct file_desc *fl = list_entry (e, struct file_desc, elem);
      if (fd == fl->fd)
      {
        file_close(fl->file);
        list_remove(&fl->elem);
        free(fl);
        break;
      }
      e = next;
    }
    break;
  }

  default:
    break;
  }

}
示例#24
0
static void
syscall_handler (struct intr_frame *f) 
{
	int nsyscall, i;
	int *esp = (int *)f -> esp;

	if(!is_valid(esp))
		thread_exit();
	
	int *arg_int[3];
	void **arg_ptr[3];

	// Get system call number.
	nsyscall = *(esp++);

	/* argc number
		0:
			SYS_HALT 
		1:
			SYS_EXIT, SYS_EXEC, SYS_WAIT, SYS_TELL, SYS_REMOVE, SYS_OPEN, SYS_CLOSE, SYS_FILESIZE
		2:
			SYS_CREATE, SYS_SEEK
		3:
			SYS_READ, SYS_WRITE
	*/
	if(nsyscall == SYS_HALT) {
		shutdown_power_off();
	}
	else if(nsyscall == SYS_EXIT) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		syscall_exit(*arg_int[0]);
	}
	else if(nsyscall == SYS_EXEC) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}

		if(!is_valid(*arg_ptr[0]))
			thread_exit();
	
		lock_acquire(&lock_sys);
		f->eax = process_execute(*arg_ptr[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_WAIT) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		f->eax = process_wait(*arg_int[0]);
	}
	else if(nsyscall == SYS_TELL) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		f->eax = syscall_tell(*arg_int[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_REMOVE) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}
		
		if(!is_valid(*arg_ptr[0]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = filesys_remove(*arg_ptr[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_OPEN) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}
		
		if(!is_valid(*arg_ptr[0]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_open(*arg_ptr[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_CLOSE) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		syscall_close(*arg_int[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_FILESIZE) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		f->eax = syscall_filesize(*arg_int[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_CREATE) {
		for(i = 0; i < 2; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}

		if(!is_valid(*arg_ptr[0]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = filesys_create(*arg_ptr[0], *arg_int[1]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_SEEK) {
		for(i = 0; i < 2; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		syscall_seek(*arg_int[0], *arg_int[1]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_READ) {
		for(i = 0; i < 3; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}

		if(!is_valid(*arg_ptr[1]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_read(*arg_int[0], *arg_ptr[1], *arg_int[2]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_WRITE) {
		for(i = 0; i < 3; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}

		if(!is_valid(*arg_ptr[1]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_write(*arg_int[0], *arg_ptr[1], *arg_int[2]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_CHDIR) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}
		
		if(!is_valid(*arg_ptr[0]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_chdir(*arg_ptr[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_MKDIR) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}
		
		if(!is_valid(*arg_ptr[0]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_mkdir(*arg_ptr[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_READDIR) {
		for(i = 0; i < 2; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
				arg_ptr[i] = (void **)(esp + i);
			}
			else thread_exit();
		}

		if(!is_valid(*arg_ptr[1]))
			thread_exit();

		lock_acquire(&lock_sys);
		f->eax = syscall_readdir(*arg_int[0], *arg_ptr[1]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_ISDIR) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		f->eax = syscall_isdir(*arg_int[0]);
		lock_release(&lock_sys);
	}
	else if(nsyscall == SYS_INUMBER) {
		for(i = 0; i < 1; i++) {
			if(is_valid((esp+i))) {
				arg_int[i] = esp + i;
			}
			else thread_exit();
		}

		lock_acquire(&lock_sys);
		f->eax = syscall_inumber(*arg_int[0]);
		lock_release(&lock_sys);
	}
	else
		thread_exit();
}
示例#25
0
文件: syscall.c 项目: roomylee/PintOS
bool 
create(const char* file,unsigned initial_size)
{
	if( strlen(file) <= 0 ) return false;
	return (bool)filesys_create(file,(off_t)initial_size);
}
示例#26
0
static void
syscall_handler (struct intr_frame *f)
{
/*  printf ("system call!\n");//TODO remove
  thread_exit ();*/
  uint32_t ret_val;

  offset = f->esp;
  int sys_call = (int) next_arg();

  char *tmp; //TODO remove
  


  switch (sys_call) {
  case SYS_HALT:
    power_off();
    NOT_REACHED ();

  case SYS_EXIT:
    syscall_exit((int) next_arg());
    NOT_REACHED ();

  case SYS_EXEC:
    ret_val = exec();
    break;

  case SYS_WAIT:
    ret_val = process_wait((tid_t) next_arg());
    break;

  case SYS_CREATE:
//    printf("test\n");
//    printf("file_name: %s, size: %d\n", next_str(), next_arg());
    tmp = next_str();
    ret_val = filesys_create(tmp, next_arg());
    break;

  case SYS_REMOVE:
    ret_val = filesys_remove(next_str());
    break;

  case SYS_OPEN:
    next_str();
    break;

  case SYS_FILESIZE:
    next_arg();
    break;

  case SYS_READ:
    /* next_arg(); next_arg(); next_arg(); */
	 ret_val = syscall_read();
    break;

  case SYS_WRITE:
    //FIXME this is just a temporary function to print to console unil real call is implemented
    /*if ((int) next_arg() == STDOUT_FILENO) {
      printf("%s", (char *) next_arg());
    }*/
	 ret_val = syscall_write();
    break;

  case SYS_SEEK:

    break;

  case SYS_TELL:

    break;

  case SYS_CLOSE:

    break;

  default:
    //TODO print error message
    break;
  }
  f->eax = ret_val;
}
示例#27
0
文件: syscall.c 项目: posijon/PintOS
static void
syscall_handler (struct intr_frame *f)
{
  int32_t* esp = (int32_t*)f->esp;
  /*
    Any parameters passed to syscall will be above ESP, see illustration below.
    Number of arguments each syscall expects is in argc[] array above.

    syscall number is pointed to by ESP.
    --------------------------------------
    PHYS_BASE
    .................
    <param>
    <param>
    ESP --->    <syscall_number>

    --------------------------------------
  */

  // verify esp pointer is ok, first parameter: current thread
   if(esp == NULL || verify_fix_length(esp, sizeof(esp)) == false){
	sys_exit(-1);
   }

   // esp adress belongs to thread
  if(pagedir_get_page(thread_current()->pagedir, esp) == NULL){
	sys_exit(-1);
   } 

  // ok syscall nr
  int32_t syscall_nr = *esp;
  if(syscall_nr < 0 || syscall_nr >= SYS_NUMBER_OF_CALLS){
	sys_exit(-1);
  }

  // Make sure our data is not overwriting PHYS_BASE.
  int expected_args = argc[syscall_nr];
  unsigned long highest_addr = esp + (expected_args * sizeof(int));
  if(highest_addr >= PHYS_BASE){
	sys_exit(-1);
  }
  
  if(pagedir_get_page(thread_current()->pagedir, highest_addr) == NULL){
	sys_exit(-1);
  }

  /*
  int i = 1;
  for(; i <= expected_args; i++){
	if(verify_fix_length(&esp[i], sizeof(int) ) == false){
		sys_exit(-1);
	}
      
  }
	*/

  DEBUG_SYSCALL("# SYSCALL received = %s\n", get_system_call_name(syscall_nr));
  
  
  switch (syscall_nr)
    {
  
    case SYS_HALT:
      power_off();
      break;
    case SYS_EXEC:
    {

      	f->eax = SYS_EXEC_handler(esp);
    }
    break;
  
    case SYS_WAIT:
    {
      
      int child_pid = *(esp + 1);
      
      f->eax = process_wait (child_pid);
      break; 
    }
  
    case SYS_EXIT:
    {
      if(is_kernel_vaddr(pg_round_up((void*)esp[1]) )){
	sys_exit(-1);
      }
      int exit_status = *(esp + 1);
      process_exit(exit_status);
      thread_exit();
      break;
    }
    case SYS_PLIST:
        process_print_list();
    break;
    case SYS_CREATE:
      {
        bool success = false;

        char *name = (char*)*(esp + 1);
	if(name == NULL){
		sys_exit(-1);
	}
        unsigned initial_size = *(esp + 2);

	if(verify_fix_length(esp[1], initial_size) == false){
		sys_exit(-1);
	}
	if(verify_variable_length(esp[1]) == false){
		sys_exit(-1);
	}
        success = filesys_create(name, initial_size);

        if(success) {
          DEBUG_SYSCALL("#SYS_CREATE - File with name: %s created. \n", name);

        } else {
          DEBUG_SYSCALL("#SYS_CREATE - filesys_create failed: file named \'%s\' already exists  or internal memory allocation failed \n", name);
        }

        f->eax = success;
        break;
      }
    case SYS_OPEN:
      {
        char *name = (char*)*(esp + 1);
	if(name == NULL){
		sys_exit(-1);
	}
	if(verify_variable_length(esp[1]) == false){
		sys_exit(-1);
	}


        struct file *file;
        file = filesys_open(name);


	int retVal = -1;
        if(file != NULL) {
          DEBUG_SYSCALL("# SYS_OPEN - File with name: '%s' created. \n", name);

	  int fd = flist_add_file(file);
	  retVal = fd;
        } else {
          DEBUG_SYSCALL("# SYS_OPEN - filesys_open failed: no file named \'%s\' exists or internal memory allocation failed \n", name);
          retVal = -1;

        }
	f->eax = retVal;
        break;
      }
    case SYS_READ:
      {
        int retVal = SYS_READ_handler(esp);

        f->eax = retVal;
        break;
      }
    case SYS_CLOSE:
	{
	int retVal = SYS_CLOSE_handler(esp);
	f->eax = retVal;
	
	break;
	}
    case SYS_REMOVE:
	{
		int retVal = SYS_REMOVE_handler(esp);
		f->eax = retVal;
		break;
	}
    case SYS_WRITE:
      {
        int retVal = SYS_WRITE_handler(esp);
        f->eax = retVal;
        break;
      }
    case SYS_SEEK:
	{
	f->eax = SYS_SEEK_handler(esp);
	break;
	}
    case SYS_TELL:

	f->eax = SYS_TELL_handler(esp);
	break;
	

    case SYS_FILESIZE:
	f->eax = SYS_FILESIZE_handler(esp);
	break;
    default:
      {
        DEBUG_SYSCALL ("Executed an unknown system call (nr: %i)!\n", syscall_nr);
        DEBUG_SYSCALL ("Stack top + 0: %d\n", esp[0]);
        DEBUG_SYSCALL ("Stack top + 1: %d\n", esp[1]);

        thread_exit ();
      }
    }
}
示例#28
0
文件: syscall.c 项目: idoitlpg/pintos
/* Create File */
bool create(const char *file, unsigned initial_size)
{
  return filesys_create(file, initial_size);
}
示例#29
0
/* Handles syscalls.  Gets the syscall arguments off the stack (including the
   syscall number) then (either directly or with the aid of helper functions)
   executes the system call and places any return value into the eax register.
   Arguments should be parsed as soon as possible and the offset_lock should
   be held for the least possible amount of time. */
static void
syscall_handler (struct intr_frame *f)
{
  int sys_call;
  uint32_t ret_val = -1;
  void *arg0, *arg1, *arg2;
  struct fd_elem **fdt = thread_current()->open_files;

  /* Acquire lock before manipulating offset */
  lock_acquire(&offset_lock);
  offset = f->esp;
  sys_call = (int) next_arg();

  switch (sys_call) {
  case SYS_HALT:
    lock_release(&offset_lock);
    power_off();
    NOT_REACHED ();

  case SYS_EXIT:
    arg0 = next_arg();/* exit status */
    lock_release(&offset_lock);

    thread_current()->exit_controler->value = (int) arg0;
    thread_exit();
    NOT_REACHED ();

  case SYS_EXEC:
    arg0 = next_str(); /* executable name */
    lock_release(&offset_lock);

    ret_val = syscall_exec((const char *) arg0);
    break;

  case SYS_WAIT:
    arg0 = next_arg(); /* tid */
    lock_release(&offset_lock);

    ret_val = process_wait((tid_t) arg0);
    break;

  case SYS_CREATE:
    arg0 = next_str(); /* File name */
    arg1 = next_arg(); /* Size */
    lock_release(&offset_lock);

    lock_acquire(&fs_lock);
    ret_val = filesys_create((const char *) arg0, (unsigned) arg1);
    lock_release(&fs_lock);
    break;

  case SYS_REMOVE:
    arg0 = next_str();/* file name */
    lock_release(&offset_lock);

    lock_acquire(&fs_lock);
    ret_val = filesys_remove((const char *) arg0);
    lock_release(&fs_lock);
    break;

  case SYS_OPEN:
    arg0 = next_str(); /* file name */
    lock_release(&offset_lock);

    ret_val = syscall_open((const char *) arg0);
    break;

  case SYS_FILESIZE:
    arg0 = next_arg(); /* fd */
    lock_release(&offset_lock);

    lock_acquire(&fs_lock);
    ret_val = file_length(fdt[(int) arg0]->file);
    lock_release(&fs_lock);
    break;

  case SYS_READ:
    arg0 = next_arg(); /* fd */
    arg1 = next_arg(); /* buffer */
    arg2 = next_arg(); /* size */
    lock_release(&offset_lock);

    ret_val = syscall_read((int) arg0, arg1, (unsigned) arg2);
    break;

  case SYS_WRITE:
    arg0 = next_arg(); /* fd */
    arg1 = next_arg(); /* buffer */
    arg2 = next_arg(); /* size */
    lock_release(&offset_lock);

    ret_val = syscall_write((int) arg0, arg1, (unsigned) arg2);
    break;

  case SYS_SEEK:
    arg0 = next_arg(); /* fd */
    arg1 = next_arg(); /* position */
    lock_release(&offset_lock);

    lock_acquire(&fs_lock);
    file_seek(thread_current()->open_files[(int) arg0]->file, (unsigned) arg1);
    lock_release(&fs_lock);
    break;

  case SYS_TELL:
    arg0 = next_arg(); /* fd */
    lock_release(&offset_lock);

    lock_acquire(&fs_lock);
    ret_val = file_tell(fdt[(int) arg0]->file);
    lock_release(&fs_lock);
    break;

  case SYS_CLOSE:
    arg0 = next_arg(); /* fd */
    lock_release(&offset_lock);

    syscall_close((int) arg0);
    break;

  default:
    /* Invalid system call number. */
    lock_release(&offset_lock);
    ret_val = -1;
    break;
  }
  /* Put return value into eax register and return to normal execution. */
  f->eax = ret_val;
}
示例#30
0
static bool sys_create(const char* file_name,unsigned initial_size)
{
  return filesys_create(file_name,initial_size);
}