# 2.11BSD#431 - /usr/src/sys/sys/vm_proc.c

##### Functions

    expand            X

       1: /*
       2:  * Copyright (c) 1986 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  *
       6:  *	@(#)vm_proc.c	1.2 (2.11BSD GTE) 12/24/92
       7:  */
       8:
       9: #include "param.h"
      10: #include "user.h"
      11: #include "proc.h"
      12: #include "text.h"
      13: #include "map.h"
      14: #include "kernel.h"
      15:
      16: /*
      17:  * Change the size of the data+stack regions of the process.
      18:  * If the size is shrinking, it's easy -- just release the extra core.
      19:  * If it's growing, and there is core, just allocate it and copy the
      20:  * image, taking care to reset registers to account for the fact that
      21:  * the system's stack has moved.  If there is no core, arrange for the
      22:  * process to be swapped out after adjusting the size requirement -- when
      23:  * it comes in, enough core will be allocated.  After the expansion, the
      24:  * caller will take care of copying the user's stack towards or away from
      25:  * the data area.  The data and stack segments are separated from each
      26:  * other.  The second argument to expand specifies which to change.  The
      27:  * stack segment will not have to be copied again after expansion.
      28:  */
      29: expand(newsize,segment)
      30:     int newsize, segment;
      31: {
      32:     register struct proc *p;
      33:     register int i, n;
      34:     int a1, a2;
      35:
      36:     p = u.u_procp;
      37:     if (segment == S_DATA) {
      38:         n = p->p_dsize;
      39:         p->p_dsize = newsize;
      40:         a1 = p->p_daddr;
      41:         if(n >= newsize) {
      42:             n -= newsize;
      43:             mfree(coremap, n, a1+newsize);
      44:             return;
      45:         }
      46:     } else {
      47:         n = p->p_ssize;
      48:         p->p_ssize = newsize;
      49:         a1 = p->p_saddr;
      50:         if(n >= newsize) {
      51:             n -= newsize;
      52:             p->p_saddr += n;
      53:             mfree(coremap, n, a1);
      54:             /*
      55: 			 *  Since the base of stack is different,
      56: 			 *  segmentation registers must be repointed.
      57: 			 */
      58:             sureg();
      59:             return;
      60:         }
      61:     }
      62:     if (setjmp(&u.u_ssave)) {
      63:         /*
      64: 		 * If we had to swap, the stack needs moving up.
      65: 		 */
      66:         if (segment == S_STACK) {
      67:             a1 = p->p_saddr;
      68:             i = newsize - n;
      69:             a2 = a1 + i;
      70:             /*
      71: 			 * i is the amount of growth.  Copy i clicks
      72: 			 * at a time, from the top; do the remainder
      73: 			 * (n % i) separately.
      74: 			 */
      75:             while (n >= i) {
      76:                 n -= i;
      77:                 copy(a1+n, a2+n, i);
      78:             }
      79:             copy(a1, a2, n);
      80:         }
      81:         sureg();
      82:         return;
      83:     }
      84:     if (u.u_fpsaved == 0) {
      85:         savfp(&u.u_fps);
      86:         u.u_fpsaved = 1;
      87:     }
      88:     a2 = malloc(coremap, newsize);
      89:     if (a2 == NULL) {
      90:         if (segment == S_DATA)
      91:             swapout(p, X_FREECORE, n, X_OLDSIZE);
      92:         else
      93:             swapout(p, X_FREECORE, X_OLDSIZE, n);
      94:         p->p_flag |= SSWAP;
      95:         swtch();
      96:         /* NOTREACHED */
      97:     }
      98:     if (segment == S_STACK) {
      99:         p->p_saddr = a2;
     100:         /*
     101: 		 * Make the copy put the stack at the top of the new area.
     102: 		 */
     103:         a2 += newsize - n;
     104:     } else
     105:         p->p_daddr = a2;
     106:     copy(a1, a2, n);
     107:     mfree(coremap, n, a1);
     108:     sureg();
     109: }

#### Defined functions

expand defined in line 29; used 7 times

- in /usr/src/sys/pdp/kern_pdp.c line 128
- in /usr/src/sys/sys/init_main.c line 243-244(2)
- in /usr/src/sys/sys/kern_exec.c line 575, 585
- in /usr/src/sys/sys/kern_mman.c line 36, 69

Last modified: 1992-12-27 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 608 |