Exemplo n.º 1
0
int
sys_sbrk(void)
{
  int addr;
  int n;

  if(argint(0, &n) < 0)
    return -1;
  if((addr = growproc(n)) < 0)
    return -1;
  return addr;
}
Exemplo n.º 2
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if((uint)i >= cp->sz || (uint)i+size >= cp->sz)
    return -1;
  *pp = cp->mem + i;
  return 0;
}
Exemplo n.º 3
0
// lab1-2
int sys_modtickets(void)
{
    int pid;
    int quantity;

    if(argint(0, &pid) < 0) {
        return -1;
    }

    // if we cannot read the quantity, add the default
    argint(1, &quantity);
    if(quantity < 0) {
        quantity = SUPER_ADD;
    }

    if(modifytickets(pid, quantity) != -1) {
        return 1;
    } else {
        return -1;
    }
}
Exemplo n.º 4
0
int sys_write(void)
{
	int fd, len;
	char *p;
	int s;

	fd = argint(0);
	argstr(1, &p);
	len = argint(2);

	if(fd == 1 || fd == 2){  // print to stdout
		if(len == 1)
			put_c(*p);
		else
			printk("%s", p);
	} else {
		sf_write(fd, p, len);
	}

	return 0;
}
Exemplo n.º 5
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if(!validPTR((uint)i) || !validPTR((uint)i+size - 1))	// changed from sz to area[0]
    return -1;
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 6
0
int
sys_set_priority(void)
{
  int priority;

  argint(0,&priority);
  if(priority >= 0 && priority < LEVELS)
    proc-> mlf_level = priority;
  else //if priority isn't valid return an error code
    return -1;
  return 0;
}
Exemplo n.º 7
0
int
sys_clone(void)
{
	void *stack;
	int size;

	if (argint(1, &size) < 0 || argptr(0, (char **) &stack, size) < 0) {
		return -1;
	}

	return clone(stack, size);
}
Exemplo n.º 8
0
int
sys_sbrk(void)
{
    int addr;
    int n;
    if(argint(0, &n) < 0)
        return -1;
    addr = proc->sz;
    if(growproc(n) < 0)
        return -1;
    return addr;
}
Exemplo n.º 9
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;

  if(argint(n, &i) < 0)
    return -1;
  if((uint)i >= proc->sz || (uint)i+size > proc->sz)
    return -1;
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 10
0
int
sys_fork_thread(void)
{
  int pid;
  int stack;
  int addrspace;
  int routine;
  int args;
  struct proc *np;

 if(argint(0, &stack) < 0 || argint(1, &routine) < 0 || argint(2, &args) < 0)
    return -1;

  if((np = copyproc_threads(cp, (int)stack, (int)routine, (int)args)) == 0){
    return -2;
   }

  np->state = RUNNABLE;
  pid = np->pid;
  return pid;
}
Exemplo n.º 11
0
int
sys_wake_lock(void)
{
	int pid;

	if(argint(0, &pid) < 0)
		return -1;

	wake_lock(pid);

	return 0;
}
Exemplo n.º 12
0
int
sys_sbrk(void)
{
  int addr;
  int n;

  if(argint(0, &n) < 0)
    return -1;
  addr = proc->sz;
  proc->sz += n;
  return addr;
}
Exemplo n.º 13
0
int sys_clone(void) {
	int fcn;
	int arg;
	int stack; 
	if (argint(0, &fcn) < 0) {
		return -1; 
	}
	if (argint(1, &arg) < 0) {
		return -1; 
	}
	if (argint(2, &stack) < 0) {
		return -1; 
	}
    if (stack == 0 || fcn == 0) {
		return -1; 
	}
	if (stack%PGSIZE != 0) {
		return -1;
	}
	return clone((void*)fcn, (void*)arg, (void*)stack); 
}
Exemplo n.º 14
0
//count number of syscall per process, Lab 1
int
sys_count(void){//Lab 1

  int count;
  int pid;
  if(argint(0, &pid) < 0){
    return -1;
  }

  count = getting_count(pid);
  return count;

}
Exemplo n.º 15
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  //  if((uint)i >= proc->sz || (uint)i+size > proc->sz) //////
  if(proc->pid != 1 && ((uint)i < PGSIZE || ((uint)i >= proc->sz && (uint)i < proc->stacksz) || ((uint)i+size>proc->sz && (uint)i+size<proc->stacksz) || (uint)i+size>USERTOP))
    return -1;
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 16
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if((uint)i >= proc->sz || (uint)i+size > proc->sz || (uint)i == 0 ||(i < PGSIZE && proc->pid > 1))
    return -1;
  
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 17
0
int
sys_set_priority(int *newprio)
{
  int oldPrio=cpu->proc->priority;
  int val,addr;
  argint(0,&addr);
  fetchint(addr,&val);
  cpu->proc->priority=val;
  if(val>oldPrio){
    yield();
  }
  return oldPrio;
}
Exemplo n.º 18
0
int
sys_alarma(void)
{
int ticks;
void(*handler)();
if(argint(0,&ticks)<0)
	return -1;
if(argptr(1,(char**)&handler,1)<0)
	return -1;
proc-> ticksalarma = ticks;
proc-> alarmhandler = handler;
return 0;
}
Exemplo n.º 19
0
int
sys_rakib(void){
  char *buf, art [] = "This is my system call output";
  int buf_size;
  if(argstr(0,&buf) < 0 || argint(1,&buf_size) < 0)
    return -1;
  if(buf_size < sizeof(art)/sizeof(char))
    return -1;
  else{
    safestrcpy(buf,art,sizeof(art)/sizeof(char));
    return sizeof(art)/sizeof(char);
  }
}
Exemplo n.º 20
0
int sys_unlock(void)
{
	int LockAddress;

	// Get the lock address pointed to by the void pointer argument.
  	if(argint(0, &LockAddress) < 0)
  	{
    	return -1;
    }
    
    xchg((unsigned int*)LockAddress, 0);
    
    return 0;
}
Exemplo n.º 21
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if(((uint)i >= proc->sz && (uint)i < proc->sz_stack) || ((uint)i+size > proc->sz && (uint)i+size < proc->sz_stack))
    return -1;
  if((uint)i < PGSIZE || (uint)i+size > USERTOP)
      return -1;
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 22
0
int sys_updatePartialWindow()
{
	int window_id;
	int x1, y1, x2, y2;
	color16* context;
	WindowLink pWindow;
	if (argint(0, &window_id) < 0)
		return -1;
	pWindow = getWindowById(window_id);
        cprintf("updatePartialWindow called: %d\n", pWindow);
	if (pWindow == 0) return -1;
	int size = ((pWindow->window_position).right_x - (pWindow->window_position).left_x) *
		((pWindow->window_position).right_y - (pWindow->window_position).left_y);
	//cprintf("window size: %d\n", size);
	if (size < 0) return -1;

	if (argptr(1, (void*)&context, sizeof(color16) * size) < 0)
		return -1;
	if (argint(2, &x1) < 0 || argint(3, &y1) < 0 || argint(4, &x2) < 0 || argint(5, &y2) < 0)
		return -1;
	drawArea(pWindow, context, x1, y1, x2, y2);
	return 0;
}
Exemplo n.º 23
0
int
sys_get_tickets() 
{
#ifdef LOTTERY
   int pid;
   if (argint(0, &pid) < 0)
      return -1;
   struct proc* p = get_proc(pid);
   if (p == 0) return -1;
   return p->tickets;
#else
   return -1;
#endif
}
Exemplo n.º 24
0
int
sys_sbrk(void)
{
  int addr;
  int n;

  if(argint(0, &n) < 0)
    return -1;
  addr = proc->sz;
	///cprintf("proc->sz = %d\n",proc->sz);
  if(growproc(n) < 0)
    return -1;
  return addr;
}
Exemplo n.º 25
0
int 
sys_get_tickets()
{
#ifdef LOTTERY
    int pid;
    if(argint(0, &pid) < 0)
        return -1;
    if(pid >= NPROC || pid < 0)
        return -2;
    return proc[pid].tickets;
#else
    return -3;
#endif
}
Exemplo n.º 26
0
int
sys_signal(void)
{
  int signum;
  int handler_addr;
  signum = -2;
  handler_addr = 0;

  if(argint(0,&signum) < -1) {
	  return -1;
  }
  if(argint(1, &handler_addr) < 0) {
	  return -1;
  }
  //cprintf("inside sysproc.c -> signum = %d handler_addr = %x\n", signum, handler_addr);

  if(signum == -1) {
	  proc->restorer = (int *) handler_addr;
  } else {
	  proc->signal_handler_addr[signum] = (int *)handler_addr;
  }
  return 0;
}
Exemplo n.º 27
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if(((uint)i >= proc->sz && (uint)i < proc->stack_top) || ((uint)i+size > proc->sz && (uint)i < proc->stack_top)||((uint)i<PGSIZE)||((uint)i+size>USERTOP)){
   // cprintf("ARGPTR ERROR\n");
    return -1;
  }
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 28
0
int
sys_signal(void){
  
  int signum;
  sighandler_t handler;
  if (argint(0, &signum) <0) {
      return -1;
  }
  if (argptr(1, (void*)&handler, sizeof(handler)) <0 ) {
      return -1;
  }
  return signal(signum-1, handler);

}
Exemplo n.º 29
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(proc->pid != 1 && (uint)i < PGSIZE){
    return -1;}
  if(argint(n, &i) < 0)
    return -1;
  if((uint)i >= proc->sz || (uint)i+size > proc->sz)
    return -1;
  *pp = (char*)i;
  return 0;
}
Exemplo n.º 30
0
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size n bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  
  if(argint(n, &i) < 0)
    return -1;
  if((uint)i >= proc->sz || (uint)i+size > proc->sz || (uint)i == 0) {
    if ((uint)i == 0) cprintf("argptr NULL ptr\n");
    return -1;
  }
  *pp = (char*)i;
  return 0;
}