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 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26	.file	"_stack_grow.s"
27
28/*
29 * void *
30 * _stack_grow(void *addr)
31 * {
32 *	uintptr_t base = (uintptr_t)curthread->ul_ustack.ss_sp;
33 *	size_t size = curthread->ul_ustack.ss_size;
34 *
35 *	if (size > (uintptr_t)addr - base)
36 *		return (addr);
37 *
38 *	if (size == 0)
39 *		return (addr);
40 *
41 *	if (size > %sp - base)
42 *		%sp = base - STACK_ALIGN;
43 *
44 *	*((char *)(base - 1));
45 *
46 *	_lwp_kill(_lwp_self(), SIGSEGV);
47 * }
48 */
49
50#include "SYS.h"
51#include <assym.h>
52
53	ENTRY(_stack_grow)
54	movl	4(%esp), %eax
55	movl	%gs:UL_USTACK+SS_SP, %ecx
56	movl	%gs:UL_USTACK+SS_SIZE, %edx
57	movl	%eax, %ebx
58	subl	%ecx, %ebx
59	cmpl	%edx, %ebx
60	jae	1f
61	ret
621:
63	/
64	/ If the stack size is 0, stack checking is disabled.
65	/
66	cmpl	$0, %edx
67	jne	2f
68	ret
692:
70	/
71	/ Move the stack pointer outside the stack bounds if it isn't already.
72	/
73	movl	%esp, %ebx
74	subl	%ecx, %ebx
75	cmpl	%edx, %ebx
76	jae	3f
77	pushl	%ebp
78	movl	%esp, %ebp
79	movl	%ecx, %esp
80	subl	$STACK_ALIGN, %esp
813:
82	/
83	/ Dereference an address in the guard page.
84	/
85	movb	-1(%ecx), %bl
86
87	/
88	/ If the above load doesn't raise a SIGSEGV then do it ourselves.
89	/
90	SYSTRAP_RVAL1(lwp_self)
91	pushl	$SIGSEGV
92	pushl	%eax
93	pushl	$0
94	SYSTRAP_RVAL1(lwp_kill)
95	addl	$12, %esp
96
97	/
98	/ Try one last time to take out the process.
99	/
100	movl	0x0, %eax
101	SET_SIZE(_stack_grow)
102