vm_unix.c revision 12206
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1988 University of Utah.
31541Srgrimes * Copyright (c) 1991, 1993
41541Srgrimes *	The Regents of the University of California.  All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software contributed to Berkeley by
71541Srgrimes * the Systems Programming Group of the University of Utah Computer
81541Srgrimes * Science Department.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
381541Srgrimes * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
391541Srgrimes *
401541Srgrimes *	@(#)vm_unix.c	8.1 (Berkeley) 6/11/93
4112206Sbde * $Id: vm_unix.c,v 1.6 1995/10/07 19:02:56 davidg Exp $
421541Srgrimes */
431541Srgrimes
441541Srgrimes/*
451541Srgrimes * Traditional sbrk/grow interface to VM
461541Srgrimes */
471541Srgrimes#include <sys/param.h>
481541Srgrimes#include <sys/systm.h>
491541Srgrimes#include <sys/proc.h>
501541Srgrimes#include <sys/resourcevar.h>
511541Srgrimes
521541Srgrimes#include <vm/vm.h>
5311317Sdg#include <vm/swap_pager.h>
541541Srgrimes
551541Srgrimesstruct obreak_args {
5612206Sbde	char *nsize;
571541Srgrimes};
581549Srgrimes
591541Srgrimes/* ARGSUSED */
601541Srgrimesint
611541Srgrimesobreak(p, uap, retval)
621541Srgrimes	struct proc *p;
631541Srgrimes	struct obreak_args *uap;
641541Srgrimes	int *retval;
651541Srgrimes{
661541Srgrimes	register struct vmspace *vm = p->p_vmspace;
671541Srgrimes	vm_offset_t new, old;
681541Srgrimes	int rv;
691541Srgrimes	register int diff;
701541Srgrimes
715455Sdg	old = (vm_offset_t) vm->vm_daddr;
7212206Sbde	new = round_page(uap->nsize);
735455Sdg	if ((int) (new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur)
745455Sdg		return (ENOMEM);
751541Srgrimes	old = round_page(old + ctob(vm->vm_dsize));
761541Srgrimes	diff = new - old;
771541Srgrimes	if (diff > 0) {
781549Srgrimes		if (swap_pager_full) {
795455Sdg			return (ENOMEM);
801549Srgrimes		}
816572Sdg		rv = vm_map_find(&vm->vm_map, NULL, 0, &old, diff, FALSE);
821541Srgrimes		if (rv != KERN_SUCCESS) {
835455Sdg			return (ENOMEM);
841541Srgrimes		}
851541Srgrimes		vm->vm_dsize += btoc(diff);
861541Srgrimes	} else if (diff < 0) {
871541Srgrimes		diff = -diff;
886572Sdg		rv = vm_map_remove(&vm->vm_map, new, new + diff);
891541Srgrimes		if (rv != KERN_SUCCESS) {
905455Sdg			return (ENOMEM);
911541Srgrimes		}
921541Srgrimes		vm->vm_dsize -= btoc(diff);
931541Srgrimes	}
945455Sdg	return (0);
951541Srgrimes}
961541Srgrimes
971541Srgrimesstruct ovadvise_args {
985455Sdg	int anom;
991541Srgrimes};
1001549Srgrimes
1011541Srgrimes/* ARGSUSED */
1021541Srgrimesint
1031541Srgrimesovadvise(p, uap, retval)
1041541Srgrimes	struct proc *p;
1051541Srgrimes	struct ovadvise_args *uap;
1061541Srgrimes	int *retval;
1071541Srgrimes{
1081541Srgrimes
1091541Srgrimes	return (EINVAL);
1101541Srgrimes}
111