dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / i386 / gen / _stack_grow.s
blob8649d9b9a53adf1fafd96e9d895f4c44ce17cdca
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 .file "_stack_grow.s"
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;
35 * if (size > (uintptr_t)addr - base)
36 * return (addr);
38 * if (size == 0)
39 * return (addr);
41 * if (size > %sp - base)
42 * %sp = base - STACK_ALIGN;
44 * *((char *)(base - 1));
46 * _lwp_kill(_lwp_self(), SIGSEGV);
47 * }
50 #include "SYS.h"
51 #include <assym.h>
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
64 / If the stack size is 0, stack checking is disabled.
66 cmpl $0, %edx
67 jne 2f
68 ret
71 / Move the stack pointer outside the stack bounds if it isn't already.
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
83 / Dereference an address in the guard page.
85 movb -1(%ecx), %bl
88 / If the above load doesn't raise a SIGSEGV then do it ourselves.
90 SYSTRAP_RVAL1(lwp_self)
91 pushl $SIGSEGV
92 pushl %eax
93 pushl $0
94 SYSTRAP_RVAL1(lwp_kill)
95 addl $12, %esp
98 / Try one last time to take out the process.
100 movl 0x0, %eax
101 SET_SIZE(_stack_grow)