move growproc up higher
This commit is contained in:
		
							parent
							
								
									be29b8e263
								
							
						
					
					
						commit
						1656b1b232
					
				
					 1 changed files with 21 additions and 20 deletions
				
			
		
							
								
								
									
										41
									
								
								proc.c
									
										
									
									
									
								
							
							
						
						
									
										41
									
								
								proc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -54,6 +54,26 @@ setupsegs(struct proc *p)
 | 
			
		|||
  ltr(SEG_TSS << 3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Grow current process's memory by n bytes.
 | 
			
		||||
// Return old size on success, -1 on failure.
 | 
			
		||||
int
 | 
			
		||||
growproc(int n)
 | 
			
		||||
{
 | 
			
		||||
  struct proc *cp = curproc[cpu()];
 | 
			
		||||
  char *newmem, *oldmem;
 | 
			
		||||
 | 
			
		||||
  newmem = kalloc(cp->sz + n);
 | 
			
		||||
  if(newmem == 0)
 | 
			
		||||
    return 0xffffffff;
 | 
			
		||||
  memmove(newmem, cp->mem, cp->sz);
 | 
			
		||||
  memset(newmem + cp->sz, 0, n);
 | 
			
		||||
  oldmem = cp->mem;
 | 
			
		||||
  cp->mem = newmem;
 | 
			
		||||
  kfree(oldmem, cp->sz);
 | 
			
		||||
  cp->sz += n;
 | 
			
		||||
  return cp->sz - n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Look in the process table for an UNUSED proc.
 | 
			
		||||
// If found, change state to EMBRYO and return it.
 | 
			
		||||
// Otherwise return 0.
 | 
			
		||||
| 
						 | 
				
			
			@ -136,26 +156,6 @@ copyproc(struct proc *p)
 | 
			
		|||
  return np;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Grow current process's memory by n bytes.
 | 
			
		||||
// Return old size on success, -1 on failure.
 | 
			
		||||
int
 | 
			
		||||
growproc(int n)
 | 
			
		||||
{
 | 
			
		||||
  struct proc *cp = curproc[cpu()];
 | 
			
		||||
  char *newmem, *oldmem;
 | 
			
		||||
 | 
			
		||||
  newmem = kalloc(cp->sz + n);
 | 
			
		||||
  if(newmem == 0)
 | 
			
		||||
    return 0xffffffff;
 | 
			
		||||
  memmove(newmem, cp->mem, cp->sz);
 | 
			
		||||
  memset(newmem + cp->sz, 0, n);
 | 
			
		||||
  oldmem = cp->mem;
 | 
			
		||||
  cp->mem = newmem;
 | 
			
		||||
  kfree(oldmem, cp->sz);
 | 
			
		||||
  cp->sz += n;
 | 
			
		||||
  return cp->sz - n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//PAGEBREAK: 42
 | 
			
		||||
// Per-CPU process scheduler.
 | 
			
		||||
// Each CPU calls scheduler() after setting itself up.
 | 
			
		||||
| 
						 | 
				
			
			@ -424,3 +424,4 @@ procdump(void)
 | 
			
		|||
    cprintf("%d %d %p\n", p->pid, p->state);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue