Deleted Added
full compact
vm_map.c (125362) vm_map.c (125454)
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 53 unchanged lines hidden (view full) ---

62 * rights to redistribute these changes.
63 */
64
65/*
66 * Virtual memory mapping module.
67 */
68
69#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 53 unchanged lines hidden (view full) ---

62 * rights to redistribute these changes.
63 */
64
65/*
66 * Virtual memory mapping module.
67 */
68
69#include <sys/cdefs.h>
70__FBSDID("$FreeBSD: head/sys/vm/vm_map.c 125362 2004-02-02 23:23:48Z jhb $");
70__FBSDID("$FreeBSD: head/sys/vm/vm_map.c 125454 2004-02-04 21:52:57Z jhb $");
71
72#include <sys/param.h>
73#include <sys/systm.h>
74#include <sys/ktr.h>
75#include <sys/lock.h>
76#include <sys/mutex.h>
77#include <sys/proc.h>
78#include <sys/vmmeter.h>

--- 2383 unchanged lines hidden (view full) ---

2462int
2463vm_map_stack(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize,
2464 vm_prot_t prot, vm_prot_t max, int cow)
2465{
2466 vm_map_entry_t new_entry, prev_entry;
2467 vm_offset_t bot, top;
2468 vm_size_t init_ssize;
2469 int orient, rv;
71
72#include <sys/param.h>
73#include <sys/systm.h>
74#include <sys/ktr.h>
75#include <sys/lock.h>
76#include <sys/mutex.h>
77#include <sys/proc.h>
78#include <sys/vmmeter.h>

--- 2383 unchanged lines hidden (view full) ---

2462int
2463vm_map_stack(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize,
2464 vm_prot_t prot, vm_prot_t max, int cow)
2465{
2466 vm_map_entry_t new_entry, prev_entry;
2467 vm_offset_t bot, top;
2468 vm_size_t init_ssize;
2469 int orient, rv;
2470 rlim_t vmemlim;
2470
2471 /*
2472 * The stack orientation is piggybacked with the cow argument.
2473 * Extract it into orient and mask the cow argument so that we
2474 * don't pass it around further.
2475 * NOTE: We explicitly allow bi-directional stacks.
2476 */
2477 orient = cow & (MAP_STACK_GROWS_DOWN|MAP_STACK_GROWS_UP);
2478 cow &= ~orient;
2479 KASSERT(orient != 0, ("No stack grow direction"));
2480
2481 if (addrbos < vm_map_min(map) || addrbos > map->max_offset)
2482 return (KERN_NO_SPACE);
2483
2484 init_ssize = (max_ssize < sgrowsiz) ? max_ssize : sgrowsiz;
2485
2471
2472 /*
2473 * The stack orientation is piggybacked with the cow argument.
2474 * Extract it into orient and mask the cow argument so that we
2475 * don't pass it around further.
2476 * NOTE: We explicitly allow bi-directional stacks.
2477 */
2478 orient = cow & (MAP_STACK_GROWS_DOWN|MAP_STACK_GROWS_UP);
2479 cow &= ~orient;
2480 KASSERT(orient != 0, ("No stack grow direction"));
2481
2482 if (addrbos < vm_map_min(map) || addrbos > map->max_offset)
2483 return (KERN_NO_SPACE);
2484
2485 init_ssize = (max_ssize < sgrowsiz) ? max_ssize : sgrowsiz;
2486
2487 PROC_LOCK(curthread->td_proc);
2488 vmemlim = lim_cur(curthread->td_proc, RLIMIT_VMEM);
2489 PROC_UNLOCK(curthread->td_proc);
2490
2486 vm_map_lock(map);
2487
2488 /* If addr is already mapped, no go */
2489 if (vm_map_lookup_entry(map, addrbos, &prev_entry)) {
2490 vm_map_unlock(map);
2491 return (KERN_NO_SPACE);
2492 }
2493
2494 /* If we would blow our VMEM resource limit, no go */
2491 vm_map_lock(map);
2492
2493 /* If addr is already mapped, no go */
2494 if (vm_map_lookup_entry(map, addrbos, &prev_entry)) {
2495 vm_map_unlock(map);
2496 return (KERN_NO_SPACE);
2497 }
2498
2499 /* If we would blow our VMEM resource limit, no go */
2495 if (map->size + init_ssize >
2496 curthread->td_proc->p_rlimit[RLIMIT_VMEM].rlim_cur) {
2500 if (map->size + init_ssize > vmemlim) {
2497 vm_map_unlock(map);
2498 return (KERN_NO_SPACE);
2499 }
2500
2501 /*
2502 * If we can't accomodate max_ssize in the current mapping, no go.
2503 * However, we need to be aware that subsequent user mappings might
2504 * map into the space we have reserved for stack, and currently this

--- 56 unchanged lines hidden (view full) ---

2561vm_map_growstack(struct proc *p, vm_offset_t addr)
2562{
2563 vm_map_entry_t next_entry, prev_entry;
2564 vm_map_entry_t new_entry, stack_entry;
2565 struct vmspace *vm = p->p_vmspace;
2566 vm_map_t map = &vm->vm_map;
2567 vm_offset_t end;
2568 size_t grow_amount, max_grow;
2501 vm_map_unlock(map);
2502 return (KERN_NO_SPACE);
2503 }
2504
2505 /*
2506 * If we can't accomodate max_ssize in the current mapping, no go.
2507 * However, we need to be aware that subsequent user mappings might
2508 * map into the space we have reserved for stack, and currently this

--- 56 unchanged lines hidden (view full) ---

2565vm_map_growstack(struct proc *p, vm_offset_t addr)
2566{
2567 vm_map_entry_t next_entry, prev_entry;
2568 vm_map_entry_t new_entry, stack_entry;
2569 struct vmspace *vm = p->p_vmspace;
2570 vm_map_t map = &vm->vm_map;
2571 vm_offset_t end;
2572 size_t grow_amount, max_grow;
2573 rlim_t stacklim, vmemlim;
2569 int is_procstack, rv;
2570
2571 GIANT_REQUIRED;
2572
2573Retry:
2574 int is_procstack, rv;
2575
2576 GIANT_REQUIRED;
2577
2578Retry:
2579 PROC_LOCK(p);
2580 stacklim = lim_cur(p, RLIMIT_STACK);
2581 vmemlim = lim_cur(curthread->td_proc, RLIMIT_VMEM);
2582 PROC_UNLOCK(p);
2583
2574 vm_map_lock_read(map);
2575
2576 /* If addr is already in the entry range, no need to grow.*/
2577 if (vm_map_lookup_entry(map, addr, &prev_entry)) {
2578 vm_map_unlock_read(map);
2579 return (KERN_SUCCESS);
2580 }
2581

--- 71 unchanged lines hidden (view full) ---

2653 }
2654
2655 is_procstack = (addr >= (vm_offset_t)vm->vm_maxsaddr) ? 1 : 0;
2656
2657 /*
2658 * If this is the main process stack, see if we're over the stack
2659 * limit.
2660 */
2584 vm_map_lock_read(map);
2585
2586 /* If addr is already in the entry range, no need to grow.*/
2587 if (vm_map_lookup_entry(map, addr, &prev_entry)) {
2588 vm_map_unlock_read(map);
2589 return (KERN_SUCCESS);
2590 }
2591

--- 71 unchanged lines hidden (view full) ---

2663 }
2664
2665 is_procstack = (addr >= (vm_offset_t)vm->vm_maxsaddr) ? 1 : 0;
2666
2667 /*
2668 * If this is the main process stack, see if we're over the stack
2669 * limit.
2670 */
2661 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount >
2662 p->p_rlimit[RLIMIT_STACK].rlim_cur)) {
2671 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) {
2663 vm_map_unlock_read(map);
2664 return (KERN_NO_SPACE);
2665 }
2666
2667 /* Round up the grow amount modulo SGROWSIZ */
2668 grow_amount = roundup (grow_amount, sgrowsiz);
2669 if (grow_amount > stack_entry->avail_ssize)
2670 grow_amount = stack_entry->avail_ssize;
2672 vm_map_unlock_read(map);
2673 return (KERN_NO_SPACE);
2674 }
2675
2676 /* Round up the grow amount modulo SGROWSIZ */
2677 grow_amount = roundup (grow_amount, sgrowsiz);
2678 if (grow_amount > stack_entry->avail_ssize)
2679 grow_amount = stack_entry->avail_ssize;
2671 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount >
2672 p->p_rlimit[RLIMIT_STACK].rlim_cur)) {
2673 grow_amount = p->p_rlimit[RLIMIT_STACK].rlim_cur -
2674 ctob(vm->vm_ssize);
2680 if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) {
2681 grow_amount = stacklim - ctob(vm->vm_ssize);
2675 }
2676
2677 /* If we would blow our VMEM resource limit, no go */
2682 }
2683
2684 /* If we would blow our VMEM resource limit, no go */
2678 if (map->size + grow_amount > p->p_rlimit[RLIMIT_VMEM].rlim_cur) {
2685 if (map->size + grow_amount > vmemlim) {
2679 vm_map_unlock_read(map);
2680 return (KERN_NO_SPACE);
2681 }
2682
2683 if (vm_map_lock_upgrade(map))
2684 goto Retry;
2685
2686 if (stack_entry == next_entry) {

--- 427 unchanged lines hidden ---
2686 vm_map_unlock_read(map);
2687 return (KERN_NO_SPACE);
2688 }
2689
2690 if (vm_map_lock_upgrade(map))
2691 goto Retry;
2692
2693 if (stack_entry == next_entry) {

--- 427 unchanged lines hidden ---