The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/uvm/uvm_unix.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 30771caba5ced6c12f29920f64051f57


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.