1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 .file "_stack_grow.s" 28 29#include "SYS.h" 30#include <../assym.h> 31 32/* 33 * void * 34 * _stack_grow(void *addr) 35 * { 36 * uintptr_t base = (uintptr_t)curthread->ul_ustack.ss_sp; 37 * size_t size = curthread->ul_ustack.ss_size; 38 * 39 * if (size > (uintptr_t)addr - (base - STACK_BIAS)) 40 * return (addr); 41 * 42 * if (size == 0) 43 * return (addr); 44 * 45 * if (size > %sp - (base - STACK_BIAS)) 46 * %sp = base - STACK_BIAS - STACK_ALIGN; 47 * 48 * *((char *)(base - 1)); 49 * 50 * _lwp_kill(_lwp_self(), SIGSEGV); 51 * } 52 */ 53 54#if defined(__sparcv9) 55#define PN ,pn %xcc, 56#else 57#define PN 58#endif 59 60 /* 61 * o0: address to which the stack will be grown (biased) 62 */ 63 ENTRY(_stack_grow) 64 ldn [%g7 + UL_USTACK + SS_SP], %o1 65 ldn [%g7 + UL_USTACK + SS_SIZE], %o2 66 sub %o1, STACK_BIAS, %o3 67 68 sub %o0, %o3, %o4 69 cmp %o2, %o4 70 bleu PN 1f 71 tst %o2 72 73 retl 74 nop 751: 76 /* 77 * If the stack size is 0, stack checking is disabled. 78 */ 79 bnz PN 2f 80 nop 81 retl 82 nop 832: 84 /* 85 * Move the stack pointer outside the stack bounds if it isn't already. 86 */ 87 sub %sp, %o3, %o4 88 cmp %o2, %o4 89 bleu PN 3f 90 nop 91 sub %o3, STACK_ALIGN, %sp 923: 93 /* 94 * Dereference an address in the guard page. 95 */ 96 ldub [%o1 - 1], %g0 97 98 /* 99 * If the above load doesn't raise a SIGSEGV then do it ourselves. 100 */ 101 SYSTRAP_RVAL1(lwp_self) 102 mov SIGSEGV, %o1 103 SYSTRAP_RVAL1(lwp_kill) 104 105 /* 106 * We should never get here; explode if we do. 107 */ 108 illtrap 109 SET_SIZE(_stack_grow) 110