diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2004-12-06 20:12:26 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2004-12-06 20:12:26 +0000 |
commit | 120d8ac9c11b65f4f5ea455c3ece1377f7c9f5e9 (patch) | |
tree | c6379e62ac806f3ca515fd801b4b656553be0348 /sys | |
parent | e8f58ee282d9d19ac7b1f6c8c781fd5af48073cc (diff) |
Use uvm_grow() to account for stack growth, rather than home-grown code
or nothing.
Inspired by a similar recent change in NetBSD.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/trap.c | 13 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/trap.c | 26 | ||||
-rw-r--r-- | sys/arch/hp300/hp300/trap.c | 8 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/trap.c | 13 | ||||
-rw-r--r-- | sys/arch/i386/i386/trap.c | 37 | ||||
-rw-r--r-- | sys/arch/m88k/m88k/trap.c | 32 | ||||
-rw-r--r-- | sys/arch/mac68k/mac68k/trap.c | 14 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/trap.c | 18 | ||||
-rw-r--r-- | sys/arch/mvme68k/mvme68k/trap.c | 12 | ||||
-rw-r--r-- | sys/arch/powerpc/powerpc/trap.c | 11 | ||||
-rw-r--r-- | sys/arch/sparc/sparc/trap.c | 18 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/trap.c | 26 | ||||
-rw-r--r-- | sys/arch/vax/vax/trap.c | 7 |
13 files changed, 76 insertions, 159 deletions
diff --git a/sys/arch/alpha/alpha/trap.c b/sys/arch/alpha/alpha/trap.c index 23e7aa56e74..a21d1de511c 100644 --- a/sys/arch/alpha/alpha/trap.c +++ b/sys/arch/alpha/alpha/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.43 2003/11/13 08:19:20 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.44 2004/12/06 20:12:21 miod Exp $ */ /* $NetBSD: trap.c,v 1.52 2000/05/24 16:48:33 thorpej Exp $ */ /*- @@ -481,15 +481,10 @@ do_fault: * we need to reflect that as an access error. */ if (map != kernel_map && - (caddr_t)va >= vm->vm_maxsaddr && - va < USRSTACK) { + (caddr_t)va >= vm->vm_maxsaddr) { if (rv == 0) { - unsigned nss; - - nss = btoc(USRSTACK - - (unsigned long)va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; + if (p != NULL) + uvm_grow(p, va); } else if (rv == EACCES) rv = EFAULT; } diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 91bb63f9afa..79c5f7c0869 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.3 2004/02/23 08:32:36 mickey Exp $ */ +/* $OpenBSD: trap.c,v 1.4 2004/12/06 20:12:23 miod Exp $ */ /* $NetBSD: trap.c,v 1.2 2003/05/04 23:51:56 fvdl Exp $ */ /*- @@ -404,7 +404,6 @@ copyfault: struct vm_map *map; vm_prot_t ftype; extern struct vm_map *kernel_map; - unsigned long nss; cr2 = rcr2(); KERNEL_PROC_LOCK(p); @@ -440,25 +439,6 @@ faultcommon: } #endif - nss = 0; - if ((caddr_t)va >= vm->vm_maxsaddr - && (caddr_t)va < (caddr_t)VM_MAXUSER_ADDRESS - && map != kernel_map) { - nss = btoc(USRSTACK-(unsigned long)va); - if (nss > (u_long)btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) { - /* - * We used to fail here. However, it may - * just have been an mmap()ed page low - * in the stack, which is legal. If it - * wasn't, uvm_fault() will fail below. - * - * Set nss to 0, since this case is not - * a "stack extension". - */ - nss = 0; - } - } - /* Fault the original page in. */ onfault = pcb->pcb_onfault; pcb->pcb_onfault = NULL; @@ -466,8 +446,8 @@ faultcommon: VM_FAULT_PROTECT : VM_FAULT_INVALID, ftype); pcb->pcb_onfault = onfault; if (error == 0) { - if (nss > (u_long)vm->vm_ssize) - vm->vm_ssize = nss; + if (map != kernel_map) + uvm_grow(p, va); if (type == T_PAGEFLT) { KERNEL_UNLOCK(); diff --git a/sys/arch/hp300/hp300/trap.c b/sys/arch/hp300/hp300/trap.c index 9a9e1a6ebcc..e658888db29 100644 --- a/sys/arch/hp300/hp300/trap.c +++ b/sys/arch/hp300/hp300/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.44 2004/01/15 17:22:25 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.45 2004/12/06 20:12:23 miod Exp $ */ /* $NetBSD: trap.c,v 1.57 1998/02/16 20:58:31 thorpej Exp $ */ /* @@ -653,11 +653,7 @@ dopanic: if ((vm != NULL && (caddr_t)va >= vm->vm_maxsaddr) && map != kernel_map) { if (rv == 0) { - unsigned nss; - - nss = btoc(USRSTACK-(unsigned)va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; + uvm_grow(p, va); } else if (rv == EACCES) rv = EFAULT; } diff --git a/sys/arch/hppa/hppa/trap.c b/sys/arch/hppa/hppa/trap.c index 2b42af14fc2..022bcc0f97e 100644 --- a/sys/arch/hppa/hppa/trap.c +++ b/sys/arch/hppa/hppa/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.81 2004/09/14 22:44:58 mickey Exp $ */ +/* $OpenBSD: trap.c,v 1.82 2004/12/06 20:12:24 miod Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -421,13 +421,10 @@ trap(type, frame) * error. */ if (space != HPPA_SID_KERNEL && - va < (vaddr_t)vm->vm_minsaddr && - va >= (vaddr_t)vm->vm_maxsaddr + ctob(vm->vm_ssize)) { - if (ret == 0) { - vsize_t nss = btoc(va - USRSTACK + NBPG - 1); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (ret == EACCES) + va < (vaddr_t)vm->vm_minsaddr) { + if (ret == 0) + uvm_grow(p, va); + else if (ret == EACCES) ret = EFAULT; } diff --git a/sys/arch/i386/i386/trap.c b/sys/arch/i386/i386/trap.c index a69e15501f7..e0aeb203bfb 100644 --- a/sys/arch/i386/i386/trap.c +++ b/sys/arch/i386/i386/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.66 2004/09/07 10:12:35 niklas Exp $ */ +/* $OpenBSD: trap.c,v 1.67 2004/12/06 20:12:24 miod Exp $ */ /* $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $ */ /*- @@ -476,7 +476,6 @@ trap(frame) struct vmspace *vm; struct vm_map *map; int rv; - unsigned nss; cr2 = rcr2(); KERNEL_PROC_LOCK(p); @@ -506,32 +505,14 @@ trap(frame) } #endif - nss = 0; - if ((caddr_t)va >= vm->vm_maxsaddr - && (caddr_t)va < (caddr_t)VM_MAXUSER_ADDRESS - && map != kernel_map) { - nss = btoc(USRSTACK-(unsigned)va); - if (nss > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) { - /* - * We used to fail here. However, it may - * just have been an mmap()ed page low - * in the stack, which is legal. If it - * wasn't, uvm_fault() will fail below. - * - * Set nss to 0, since this case is not - * a "stack extension". - */ - nss = 0; - } - } - onfault = p->p_addr->u_pcb.pcb_onfault; p->p_addr->u_pcb.pcb_onfault = NULL; rv = uvm_fault(map, va, 0, ftype); p->p_addr->u_pcb.pcb_onfault = onfault; + if (rv == 0) { - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; + if (map != kernel_map) + uvm_grow(p, va); if (type == T_PAGEFLT) { KERNEL_UNLOCK(); return; @@ -617,7 +598,6 @@ int trapwrite(unsigned int addr) { vaddr_t va; - unsigned nss; struct proc *p; struct vmspace *vm; @@ -625,20 +605,13 @@ trapwrite(unsigned int addr) if (va >= VM_MAXUSER_ADDRESS) return 1; - nss = 0; p = curproc; vm = p->p_vmspace; - if ((caddr_t)va >= vm->vm_maxsaddr) { - nss = btoc(USRSTACK-(unsigned)va); - if (nss > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) - nss = 0; - } if (uvm_fault(&vm->vm_map, va, 0, VM_PROT_READ | VM_PROT_WRITE)) return 1; - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; + uvm_grow(p, va); return 0; } diff --git a/sys/arch/m88k/m88k/trap.c b/sys/arch/m88k/m88k/trap.c index aa044746c15..bd627908897 100644 --- a/sys/arch/m88k/m88k/trap.c +++ b/sys/arch/m88k/m88k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.14 2004/11/09 21:49:56 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.15 2004/12/06 20:12:24 miod Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * Copyright (c) 1998 Steve Murphree, Jr. @@ -203,7 +203,7 @@ m88100_trap(unsigned type, struct trapframe *frame) vm_prot_t ftype; int fault_type, pbus_type; u_long fault_code; - unsigned nss, fault_addr; + unsigned fault_addr; struct vmspace *vm; union sigval sv; int result; @@ -397,19 +397,16 @@ user_fault: break; default: result = uvm_fault(map, va, VM_FAULT_INVALID, ftype); - if (result == EACCES) - result = EFAULT; break; } p->p_addr->u_pcb.pcb_onfault = pcb_onfault; if ((caddr_t)va >= vm->vm_maxsaddr) { - if (result == 0) { - nss = btoc(USRSTACK - va);/* XXX check this */ - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } + if (result == 0) + uvm_grow(p, va); + else if (result == EACCES) + result = EFAULT; } /* @@ -610,7 +607,7 @@ m88110_trap(unsigned type, struct trapframe *frame) vm_prot_t ftype; int fault_type; u_long fault_code; - unsigned nss, fault_addr; + unsigned fault_addr; struct vmspace *vm; union sigval sv; int result; @@ -863,8 +860,6 @@ m88110_user_fault: /* segment or page fault */ result = uvm_fault(map, va, VM_FAULT_INVALID, ftype); p->p_addr->u_pcb.pcb_onfault = pcb_onfault; - if (result == EACCES) - result = EFAULT; } else if (frame->tf_dsr & (CMMU_DSR_CP | CMMU_DSR_WA)) { /* copyback or write allocate error */ @@ -911,8 +906,6 @@ m88110_user_fault: #endif result = uvm_fault(map, va, VM_FAULT_INVALID, ftype); p->p_addr->u_pcb.pcb_onfault = pcb_onfault; - if (result == EACCES) - result = EFAULT; } } else { #ifdef TRAPDEBUG @@ -932,8 +925,6 @@ m88110_user_fault: /* segment or page fault */ result = uvm_fault(map, va, VM_FAULT_INVALID, ftype); p->p_addr->u_pcb.pcb_onfault = pcb_onfault; - if (result == EACCES) - result = EFAULT; } else { #ifdef TRAPDEBUG printf("Unexpected Instruction fault isr %x\n", @@ -944,11 +935,10 @@ m88110_user_fault: } if ((caddr_t)va >= vm->vm_maxsaddr) { - if (result == 0) { - nss = btoc(USRSTACK - va);/* XXX check this */ - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } + if (result == 0) + uvm_grow(p, va); + else if (result == EACCES) + result = EFAULT; } /* diff --git a/sys/arch/mac68k/mac68k/trap.c b/sys/arch/mac68k/mac68k/trap.c index d3f9971fc26..610d9214806 100644 --- a/sys/arch/mac68k/mac68k/trap.c +++ b/sys/arch/mac68k/mac68k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.41 2003/06/02 23:27:49 millert Exp $ */ +/* $OpenBSD: trap.c,v 1.42 2004/12/06 20:12:24 miod Exp $ */ /* $NetBSD: trap.c,v 1.68 1998/12/22 08:47:07 scottr Exp $ */ /* @@ -596,13 +596,9 @@ copyfault: */ if ((vm != NULL && (caddr_t)va >= vm->vm_maxsaddr) && map != kernel_map) { - if (rv == 0) { - u_int nss; - - nss = btoc(USRSTACK-(unsigned)va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv == 0) { @@ -633,9 +629,9 @@ copyfault: } sv.sival_ptr = (void *)v; trapsignal(p, i, ucode, typ, sv); +out: if ((type & T_USER) == 0) return; -out: userret(p, &frame, sticks, v, 1); } diff --git a/sys/arch/mips64/mips64/trap.c b/sys/arch/mips64/mips64/trap.c index 105f494b3f0..b67f6829788 100644 --- a/sys/arch/mips64/mips64/trap.c +++ b/sys/arch/mips64/mips64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.18 2004/11/11 19:00:37 kettenis Exp $ */ +/* $OpenBSD: trap.c,v 1.19 2004/12/06 20:12:24 miod Exp $ */ /* tracked to 1.23 */ /* @@ -273,7 +273,7 @@ trap(trapframe) kernel_fault: va = trunc_page((vaddr_t)trapframe->badvaddr); rv = uvm_fault(kernel_map, trunc_page(va), 0, ftype); - if (rv == KERN_SUCCESS) + if (rv == 0) return (trapframe->pc); if ((i = p->p_addr->u_pcb.pcb_onfault) != 0) { p->p_addr->u_pcb.pcb_onfault = 0; @@ -327,16 +327,12 @@ printf("sp %p\n", trapframe->sp); * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == KERN_SUCCESS) { - unsigned nss; - - nss = btoc(USRSTACK-(unsigned)va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == KERN_PROTECTION_FAILURE) - rv = KERN_INVALID_ADDRESS; + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) + rv = EFAULT; } - if (rv == KERN_SUCCESS) { + if (rv == 0) { if (!USERMODE(trapframe->sr)) return (trapframe->pc); goto out; diff --git a/sys/arch/mvme68k/mvme68k/trap.c b/sys/arch/mvme68k/mvme68k/trap.c index 396373cb3b9..e88700dfaee 100644 --- a/sys/arch/mvme68k/mvme68k/trap.c +++ b/sys/arch/mvme68k/mvme68k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.55 2004/07/30 22:29:49 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.56 2004/12/06 20:12:25 miod Exp $ */ /* * Copyright (c) 1995 Theo de Raadt @@ -595,13 +595,9 @@ copyfault: */ if ((vm != NULL && (caddr_t)va >= vm->vm_maxsaddr) && map != kernel_map) { - if (rv == 0) { - u_int nss; - - nss = btoc(USRSTACK-(u_int)va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv == 0) { diff --git a/sys/arch/powerpc/powerpc/trap.c b/sys/arch/powerpc/powerpc/trap.c index 9ec131f8e95..3b7168c2862 100644 --- a/sys/arch/powerpc/powerpc/trap.c +++ b/sys/arch/powerpc/powerpc/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.64 2004/08/05 20:56:24 pefo Exp $ */ +/* $OpenBSD: trap.c,v 1.65 2004/12/06 20:12:25 miod Exp $ */ /* $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $ */ /* @@ -364,8 +364,10 @@ printf("kern dsi on addr %x iar %x\n", frame->dar, frame->srr0); } else vftype = ftype = VM_PROT_READ; if (uvm_fault(&p->p_vmspace->vm_map, - trunc_page(frame->dar), 0, ftype) == 0) + trunc_page(frame->dar), 0, ftype) == 0) { + uvm_grow(p, trunc_page(frame->dar)); break; + } #if 0 printf("dsi on addr %x iar %x lr %x\n", frame->dar, frame->srr0,frame->lr); @@ -388,12 +390,15 @@ printf("dsi on addr %x iar %x lr %x\n", frame->dar, frame->srr0,frame->lr); ftype = VM_PROT_READ | VM_PROT_EXECUTE; if (uvm_fault(&p->p_vmspace->vm_map, - trunc_page(frame->srr0), 0, ftype) == 0) + trunc_page(frame->srr0), 0, ftype) == 0) { + uvm_grow(p, trunc_page(frame->srr0)); break; + } } #if 0 printf("isi iar %x lr %x\n", frame->srr0, frame->lr); #endif + /* FALLTHROUGH */ case EXC_MCHK|EXC_USER: /* XXX Likely that returning from this trap is bogus... */ /* XXX Have to make sure that sigreturn does the right thing. */ diff --git a/sys/arch/sparc/sparc/trap.c b/sys/arch/sparc/sparc/trap.c index dbbc17a2997..ffb05eda902 100644 --- a/sys/arch/sparc/sparc/trap.c +++ b/sys/arch/sparc/sparc/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.41 2004/08/06 22:39:14 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.42 2004/12/06 20:12:25 miod Exp $ */ /* $NetBSD: trap.c,v 1.58 1997/09/12 08:55:01 pk Exp $ */ /* @@ -736,11 +736,9 @@ mem_access_fault(type, ser, v, pc, psr, tf) * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == 0) { - unsigned nss = btoc(USRSTACK - va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv == 0) { @@ -972,11 +970,9 @@ mem_access_fault4m(type, sfsr, sfva, tf) * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == 0) { - unsigned nss = btoc(USRSTACK - va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv != 0) { diff --git a/sys/arch/sparc64/sparc64/trap.c b/sys/arch/sparc64/sparc64/trap.c index b447afb1b64..b7c73f51d41 100644 --- a/sys/arch/sparc64/sparc64/trap.c +++ b/sys/arch/sparc64/sparc64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.32 2004/08/09 10:13:23 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.33 2004/12/06 20:12:25 miod Exp $ */ /* $NetBSD: trap.c,v 1.73 2001/08/09 01:03:01 eeh Exp $ */ /* @@ -887,11 +887,9 @@ data_access_fault(tf, type, pc, addr, sfva, sfsr) * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == 0) { - segsz_t nss = btoc(USRSTACK - va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv != 0) { @@ -1066,11 +1064,9 @@ text_access_fault(tf, type, pc, sfsr) * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == 0) { - segsz_t nss = btoc(USRSTACK - va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv != 0) { @@ -1173,11 +1169,9 @@ text_access_error(tf, type, pc, sfsr, afva, afsr) * error. */ if ((caddr_t)va >= vm->vm_maxsaddr) { - if (rv == 0) { - segsz_t nss = btoc(USRSTACK - va); - if (nss > vm->vm_ssize) - vm->vm_ssize = nss; - } else if (rv == EACCES) + if (rv == 0) + uvm_grow(p, va); + else if (rv == EACCES) rv = EFAULT; } if (rv != 0) { diff --git a/sys/arch/vax/vax/trap.c b/sys/arch/vax/vax/trap.c index a95a59d5d0f..7d4caf6e0ae 100644 --- a/sys/arch/vax/vax/trap.c +++ b/sys/arch/vax/vax/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.28 2004/03/09 22:29:01 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.29 2004/12/06 20:12:25 miod Exp $ */ /* $NetBSD: trap.c,v 1.47 1999/08/21 19:26:20 matt Exp $ */ /* * Copyright (c) 1994 Ludd, University of Lule}, Sweden. @@ -255,8 +255,11 @@ if(faultdebug)printf("trap accflt type %lx, code %lx, pc %lx, psl %lx\n", sig = SIGSEGV; typ = SEGV_MAPERR; } - } else + } else { trapsig = 0; + if (umode != 0) + uvm_grow(p, addr); + } break; case T_PTELEN: |