Home | History | Annotate | Line # | Download | only in uvm
uvm_unix.c revision 1.18.2.7
      1  1.18.2.7   nathanw /*	$NetBSD: uvm_unix.c,v 1.18.2.7 2002/07/12 01:40:46 nathanw Exp $	*/
      2       1.1       mrg 
      3       1.1       mrg /*
      4       1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5  1.18.2.3   nathanw  * Copyright (c) 1991, 1993 The Regents of the University of California.
      6       1.1       mrg  * Copyright (c) 1988 University of Utah.
      7       1.1       mrg  *
      8       1.1       mrg  * All rights reserved.
      9       1.1       mrg  *
     10       1.1       mrg  * This code is derived from software contributed to Berkeley by
     11       1.1       mrg  * the Systems Programming Group of the University of Utah Computer
     12       1.1       mrg  * Science Department.
     13       1.1       mrg  *
     14       1.1       mrg  * Redistribution and use in source and binary forms, with or without
     15       1.1       mrg  * modification, are permitted provided that the following conditions
     16       1.1       mrg  * are met:
     17       1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     18       1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     19       1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     20       1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     21       1.1       mrg  *    documentation and/or other materials provided with the distribution.
     22       1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     23       1.1       mrg  *    must display the following acknowledgement:
     24       1.1       mrg  *      This product includes software developed by Charles D. Cranor,
     25  1.18.2.3   nathanw  *	Washington University, the University of California, Berkeley and
     26       1.1       mrg  *	its contributors.
     27       1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     28       1.1       mrg  *    may be used to endorse or promote products derived from this software
     29       1.1       mrg  *    without specific prior written permission.
     30       1.1       mrg  *
     31       1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     32       1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     33       1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     34       1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     35       1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     39       1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     40       1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     41       1.1       mrg  * SUCH DAMAGE.
     42       1.1       mrg  *
     43       1.1       mrg  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
     44       1.1       mrg  *      @(#)vm_unix.c   8.1 (Berkeley) 6/11/93
     45       1.3       mrg  * from: Id: uvm_unix.c,v 1.1.2.2 1997/08/25 18:52:30 chuck Exp
     46       1.1       mrg  */
     47       1.1       mrg 
     48       1.1       mrg /*
     49       1.1       mrg  * uvm_unix.c: traditional sbrk/grow interface to vm.
     50       1.1       mrg  */
     51  1.18.2.4   nathanw 
     52  1.18.2.4   nathanw #include <sys/cdefs.h>
     53  1.18.2.7   nathanw __KERNEL_RCSID(0, "$NetBSD: uvm_unix.c,v 1.18.2.7 2002/07/12 01:40:46 nathanw Exp $");
     54       1.1       mrg 
     55       1.1       mrg #include <sys/param.h>
     56       1.1       mrg #include <sys/systm.h>
     57       1.1       mrg #include <sys/proc.h>
     58       1.1       mrg #include <sys/resourcevar.h>
     59       1.1       mrg #include <sys/vnode.h>
     60       1.1       mrg 
     61       1.1       mrg #include <sys/mount.h>
     62  1.18.2.6   nathanw #include <sys/sa.h>
     63       1.1       mrg #include <sys/syscallargs.h>
     64       1.1       mrg 
     65       1.1       mrg #include <uvm/uvm.h>
     66       1.1       mrg 
     67       1.1       mrg /*
     68       1.1       mrg  * sys_obreak: set break
     69       1.1       mrg  */
     70       1.1       mrg 
     71       1.4       mrg int
     72  1.18.2.1   nathanw sys_obreak(l, v, retval)
     73  1.18.2.1   nathanw 	struct lwp *l;
     74       1.4       mrg 	void *v;
     75       1.4       mrg 	register_t *retval;
     76       1.1       mrg {
     77       1.4       mrg 	struct sys_obreak_args /* {
     78       1.4       mrg 		syscallarg(char *) nsize;
     79       1.4       mrg 	} */ *uap = v;
     80  1.18.2.1   nathanw 	struct proc *p = l->l_proc;
     81      1.12  augustss 	struct vmspace *vm = p->p_vmspace;
     82       1.6       eeh 	vaddr_t new, old;
     83  1.18.2.2   nathanw 	int error;
     84       1.4       mrg 
     85       1.6       eeh 	old = (vaddr_t)vm->vm_daddr;
     86      1.11    kleink 	new = round_page((vaddr_t)SCARG(uap, nsize));
     87  1.18.2.3   nathanw 	if ((new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur && new > old)
     88      1.14   thorpej 		return (ENOMEM);
     89       1.4       mrg 
     90      1.14   thorpej 	old = round_page(old + ptoa(vm->vm_dsize));
     91       1.4       mrg 
     92  1.18.2.3   nathanw 	if (new == old)
     93      1.14   thorpej 		return (0);
     94      1.14   thorpej 
     95       1.4       mrg 	/*
     96       1.4       mrg 	 * grow or shrink?
     97       1.4       mrg 	 */
     98  1.18.2.3   nathanw 	if (new > old) {
     99  1.18.2.3   nathanw 		error = uvm_map(&vm->vm_map, &old, new - old, NULL,
    100  1.18.2.2   nathanw 		    UVM_UNKNOWN_OFFSET, 0,
    101  1.18.2.2   nathanw 		    UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
    102       1.4       mrg 		    UVM_ADV_NORMAL, UVM_FLAG_AMAPPAD|UVM_FLAG_FIXED|
    103  1.18.2.3   nathanw 		    UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
    104  1.18.2.2   nathanw 		if (error) {
    105  1.18.2.2   nathanw 			uprintf("sbrk: grow %ld failed, error = %d\n",
    106  1.18.2.3   nathanw 				new - old, error);
    107  1.18.2.2   nathanw 			return error;
    108       1.4       mrg 		}
    109  1.18.2.3   nathanw 		vm->vm_dsize += atop(new - old);
    110      1.14   thorpej 	} else {
    111  1.18.2.3   nathanw 		uvm_deallocate(&vm->vm_map, new, old - new);
    112  1.18.2.3   nathanw 		vm->vm_dsize -= atop(old - new);
    113      1.14   thorpej 	}
    114  1.18.2.2   nathanw 	return 0;
    115       1.1       mrg }
    116       1.1       mrg 
    117       1.1       mrg /*
    118       1.1       mrg  * uvm_grow: enlarge the "stack segment" to include sp.
    119       1.1       mrg  */
    120       1.1       mrg 
    121       1.4       mrg int
    122       1.4       mrg uvm_grow(p, sp)
    123       1.4       mrg 	struct proc *p;
    124       1.6       eeh 	vaddr_t sp;
    125       1.1       mrg {
    126      1.12  augustss 	struct vmspace *vm = p->p_vmspace;
    127      1.12  augustss 	int si;
    128       1.1       mrg 
    129       1.4       mrg 	/*
    130       1.4       mrg 	 * For user defined stacks (from sendsig).
    131       1.4       mrg 	 */
    132       1.6       eeh 	if (sp < (vaddr_t)vm->vm_maxsaddr)
    133       1.4       mrg 		return (0);
    134       1.4       mrg 
    135       1.4       mrg 	/*
    136       1.4       mrg 	 * For common case of already allocated (from trap).
    137       1.4       mrg 	 */
    138       1.4       mrg 	if (sp >= USRSTACK - ctob(vm->vm_ssize))
    139       1.4       mrg 		return (1);
    140       1.4       mrg 
    141       1.4       mrg 	/*
    142       1.4       mrg 	 * Really need to check vs limit and increment stack size if ok.
    143       1.4       mrg 	 */
    144       1.9      fvdl 	si = btoc(USRSTACK-sp) - vm->vm_ssize;
    145       1.4       mrg 	if (vm->vm_ssize + si > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur))
    146       1.4       mrg 		return (0);
    147       1.4       mrg 	vm->vm_ssize += si;
    148       1.4       mrg 	return (1);
    149       1.1       mrg }
    150       1.1       mrg 
    151       1.1       mrg /*
    152       1.1       mrg  * sys_oadvise: old advice system call
    153       1.1       mrg  */
    154       1.1       mrg 
    155       1.1       mrg /* ARGSUSED */
    156       1.4       mrg int
    157  1.18.2.1   nathanw sys_ovadvise(l, v, retval)
    158  1.18.2.1   nathanw 	struct lwp *l;
    159       1.4       mrg 	void *v;
    160       1.4       mrg 	register_t *retval;
    161       1.1       mrg {
    162       1.1       mrg #if 0
    163       1.4       mrg 	struct sys_ovadvise_args /* {
    164       1.4       mrg 		syscallarg(int) anom;
    165       1.4       mrg 	} */ *uap = v;
    166       1.1       mrg #endif
    167       1.4       mrg 
    168       1.4       mrg 	return (EINVAL);
    169      1.10       eeh }
    170