vm_unix.c revision 1541
1191762Simp/* 2191762Simp * Copyright (c) 1988 University of Utah. 3191762Simp * Copyright (c) 1991, 1993 4191762Simp * The Regents of the University of California. All rights reserved. 5191762Simp * 6191762Simp * This code is derived from software contributed to Berkeley by 7191762Simp * the Systems Programming Group of the University of Utah Computer 8191762Simp * Science Department. 9191762Simp * 10191762Simp * Redistribution and use in source and binary forms, with or without 11191762Simp * modification, are permitted provided that the following conditions 12191762Simp * are met: 13191762Simp * 1. Redistributions of source code must retain the above copyright 14191762Simp * notice, this list of conditions and the following disclaimer. 15191762Simp * 2. Redistributions in binary form must reproduce the above copyright 16191762Simp * notice, this list of conditions and the following disclaimer in the 17191762Simp * documentation and/or other materials provided with the distribution. 18191762Simp * 3. All advertising materials mentioning features or use of this software 19191762Simp * must display the following acknowledgement: 20191762Simp * This product includes software developed by the University of 21191762Simp * California, Berkeley and its contributors. 22191762Simp * 4. Neither the name of the University nor the names of its contributors 23191762Simp * may be used to endorse or promote products derived from this software 24191762Simp * without specific prior written permission. 25191762Simp * 26191762Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27191762Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28191762Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29191762Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30191762Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31191762Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32191762Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33191762Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34191762Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35191762Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36191762Simp * SUCH DAMAGE. 37235338Sadrian * 38235338Sadrian * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$ 39191762Simp * 40191762Simp * @(#)vm_unix.c 8.1 (Berkeley) 6/11/93 41191762Simp */ 42191762Simp 43191762Simp/* 44191762Simp * Traditional sbrk/grow interface to VM 45191762Simp */ 46191762Simp#include <sys/param.h> 47191762Simp#include <sys/systm.h> 48191762Simp#include <sys/proc.h> 49191762Simp#include <sys/resourcevar.h> 50191762Simp 51191762Simp#include <vm/vm.h> 52191762Simp 53191762Simpstruct obreak_args { 54191762Simp char *nsiz; 55191762Simp}; 56191762Simp/* ARGSUSED */ 57191762Simpint 58191762Simpobreak(p, uap, retval) 59191762Simp struct proc *p; 60191762Simp struct obreak_args *uap; 61191762Simp int *retval; 62191762Simp{ 63191762Simp register struct vmspace *vm = p->p_vmspace; 64191762Simp vm_offset_t new, old; 65191762Simp int rv; 66191762Simp register int diff; 67191762Simp 68191762Simp old = (vm_offset_t)vm->vm_daddr; 69191762Simp new = round_page(uap->nsiz); 70191762Simp if ((int)(new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur) 71191762Simp return(ENOMEM); 72191762Simp old = round_page(old + ctob(vm->vm_dsize)); 73191762Simp diff = new - old; 74191762Simp if (diff > 0) { 75191762Simp rv = vm_allocate(&vm->vm_map, &old, diff, FALSE); 76191762Simp if (rv != KERN_SUCCESS) { 77191762Simp uprintf("sbrk: grow failed, return = %d\n", rv); 78191762Simp return(ENOMEM); 79191762Simp } 80191762Simp vm->vm_dsize += btoc(diff); 81191762Simp } else if (diff < 0) { 82191762Simp diff = -diff; 83191762Simp rv = vm_deallocate(&vm->vm_map, new, diff); 84191762Simp if (rv != KERN_SUCCESS) { 85192277Simp uprintf("sbrk: shrink failed, return = %d\n", rv); 86192277Simp return(ENOMEM); 87192277Simp } 88192277Simp vm->vm_dsize -= btoc(diff); 89192277Simp } 90192277Simp return(0); 91192277Simp} 92192277Simp 93192277Simp/* 94192277Simp * Enlarge the "stack segment" to include the specified 95192277Simp * stack pointer for the process. 96209892Sweongyo */ 97209892Sweongyoint 98191762Simpgrow(p, sp) 99191762Simp struct proc *p; 100191762Simp unsigned sp; 101191762Simp{ 102191762Simp register struct vmspace *vm = p->p_vmspace; 103191762Simp register int si; 104191762Simp 105191762Simp /* 106191762Simp * For user defined stacks (from sendsig). 107191762Simp */ 108191762Simp if (sp < (unsigned)vm->vm_maxsaddr) 109191762Simp return (0); 110191762Simp /* 111191762Simp * For common case of already allocated (from trap). 112191762Simp */ 113191762Simp if (sp >= USRSTACK - ctob(vm->vm_ssize)) 114191762Simp return (1); 115191762Simp /* 116191762Simp * Really need to check vs limit and increment stack size if ok. 117191762Simp */ 118191762Simp si = clrnd(btoc(USRSTACK-sp) - vm->vm_ssize); 119191762Simp if (vm->vm_ssize + si > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) 120191762Simp return (0); 121191762Simp vm->vm_ssize += si; 122191762Simp return (1); 123191762Simp} 124191762Simp 125191762Simpstruct ovadvise_args { 126191762Simp int anom; 127191762Simp}; 128191762Simp/* ARGSUSED */ 129191762Simpint 130191762Simpovadvise(p, uap, retval) 131191762Simp struct proc *p; 132191762Simp struct ovadvise_args *uap; 133191762Simp int *retval; 134191762Simp{ 135191762Simp 136191762Simp return (EINVAL); 137191762Simp} 138191762Simp