1*5d9d9091SRichard Lowe/* 2*5d9d9091SRichard Lowe * CDDL HEADER START 3*5d9d9091SRichard Lowe * 4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the 5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License"). 6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License. 7*5d9d9091SRichard Lowe * 8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions 11*5d9d9091SRichard Lowe * and limitations under the License. 12*5d9d9091SRichard Lowe * 13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*5d9d9091SRichard Lowe * 19*5d9d9091SRichard Lowe * CDDL HEADER END 20*5d9d9091SRichard Lowe */ 21*5d9d9091SRichard Lowe/* 22*5d9d9091SRichard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 23*5d9d9091SRichard Lowe * Use is subject to license terms. 24*5d9d9091SRichard Lowe */ 25*5d9d9091SRichard Lowe 26*5d9d9091SRichard Lowe .file "_stack_grow.s" 27*5d9d9091SRichard Lowe 28*5d9d9091SRichard Lowe/* 29*5d9d9091SRichard Lowe * void * 30*5d9d9091SRichard Lowe * _stack_grow(void *addr) 31*5d9d9091SRichard Lowe * { 32*5d9d9091SRichard Lowe * uintptr_t base = (uintptr_t)curthread->ul_ustack.ss_sp; 33*5d9d9091SRichard Lowe * size_t size = curthread->ul_ustack.ss_size; 34*5d9d9091SRichard Lowe * 35*5d9d9091SRichard Lowe * if (size > (uintptr_t)addr - base) 36*5d9d9091SRichard Lowe * return (addr); 37*5d9d9091SRichard Lowe * 38*5d9d9091SRichard Lowe * if (size == 0) 39*5d9d9091SRichard Lowe * return (addr); 40*5d9d9091SRichard Lowe * 41*5d9d9091SRichard Lowe * if (size > %sp - base) 42*5d9d9091SRichard Lowe * %sp = base - STACK_ALIGN; 43*5d9d9091SRichard Lowe * 44*5d9d9091SRichard Lowe * *((char *)(base - 1)); 45*5d9d9091SRichard Lowe * 46*5d9d9091SRichard Lowe * _lwp_kill(_lwp_self(), SIGSEGV); 47*5d9d9091SRichard Lowe * } 48*5d9d9091SRichard Lowe */ 49*5d9d9091SRichard Lowe 50*5d9d9091SRichard Lowe#include "SYS.h" 51*5d9d9091SRichard Lowe#include <../assym.h> 52*5d9d9091SRichard Lowe 53*5d9d9091SRichard Lowe ENTRY(_stack_grow) 54*5d9d9091SRichard Lowe movq %rdi, %rax 55*5d9d9091SRichard Lowe movq %fs:UL_USTACK+SS_SP, %rcx 56*5d9d9091SRichard Lowe movq %fs:UL_USTACK+SS_SIZE, %rdx 57*5d9d9091SRichard Lowe movq %rax, %rbx 58*5d9d9091SRichard Lowe subq %rcx, %rbx 59*5d9d9091SRichard Lowe cmpq %rdx, %rbx 60*5d9d9091SRichard Lowe jae 1f 61*5d9d9091SRichard Lowe ret 62*5d9d9091SRichard Lowe1: 63*5d9d9091SRichard Lowe / 64*5d9d9091SRichard Lowe / If the stack size is 0, stack checking is disabled. 65*5d9d9091SRichard Lowe / 66*5d9d9091SRichard Lowe cmpq $0, %rdx 67*5d9d9091SRichard Lowe jne 2f 68*5d9d9091SRichard Lowe ret 69*5d9d9091SRichard Lowe2: 70*5d9d9091SRichard Lowe / 71*5d9d9091SRichard Lowe / Move the stack pointer outside the stack bounds if it isn't already. 72*5d9d9091SRichard Lowe / 73*5d9d9091SRichard Lowe movq %rsp, %rbx 74*5d9d9091SRichard Lowe subq %rcx, %rbx 75*5d9d9091SRichard Lowe cmpq %rdx, %rbx 76*5d9d9091SRichard Lowe jae 3f 77*5d9d9091SRichard Lowe pushq %rbp 78*5d9d9091SRichard Lowe movq %rsp, %rbp 79*5d9d9091SRichard Lowe movq %rcx, %rsp 80*5d9d9091SRichard Lowe subq $STACK_ALIGN, %rsp 81*5d9d9091SRichard Lowe3: 82*5d9d9091SRichard Lowe / 83*5d9d9091SRichard Lowe / Dereference an address in the guard page. 84*5d9d9091SRichard Lowe / 85*5d9d9091SRichard Lowe movb -1(%rcx), %bl 86*5d9d9091SRichard Lowe 87*5d9d9091SRichard Lowe / 88*5d9d9091SRichard Lowe / If the above load doesn't raise a SIGSEGV then do it ourselves. 89*5d9d9091SRichard Lowe / 90*5d9d9091SRichard Lowe SYSTRAP_RVAL1(lwp_self) 91*5d9d9091SRichard Lowe movl $SIGSEGV, %esi 92*5d9d9091SRichard Lowe movl %eax, %edi 93*5d9d9091SRichard Lowe SYSTRAP_RVAL1(lwp_kill) 94*5d9d9091SRichard Lowe 95*5d9d9091SRichard Lowe / 96*5d9d9091SRichard Lowe / Try one last time to take out the process. 97*5d9d9091SRichard Lowe / 98*5d9d9091SRichard Lowe movq 0x0, %rax 99*5d9d9091SRichard Lowe SET_SIZE(_stack_grow) 100