import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / amd64 / gen / _stack_grow.s
blob58d08ad44f8d0170e92ecc1b0650130a3b44b8c2
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 movq %rdi, %rax
55 movq %fs:UL_USTACK+SS_SP, %rcx
56 movq %fs:UL_USTACK+SS_SIZE, %rdx
57 movq %rax, %rbx
58 subq %rcx, %rbx
59 cmpq %rdx, %rbx
60 jae 1f
61 ret
64 / If the stack size is 0, stack checking is disabled.
66 cmpq $0, %rdx
67 jne 2f
68 ret
71 / Move the stack pointer outside the stack bounds if it isn't already.
73 movq %rsp, %rbx
74 subq %rcx, %rbx
75 cmpq %rdx, %rbx
76 jae 3f
77 pushq %rbp
78 movq %rsp, %rbp
79 movq %rcx, %rsp
80 subq $STACK_ALIGN, %rsp
83 / Dereference an address in the guard page.
85 movb -1(%rcx), %bl
88 / If the above load doesn't raise a SIGSEGV then do it ourselves.
90 SYSTRAP_RVAL1(lwp_self)
91 movl $SIGSEGV, %esi
92 movl %eax, %edi
93 SYSTRAP_RVAL1(lwp_kill)
96 / Try one last time to take out the process.
98 movq 0x0, %rax
99 SET_SIZE(_stack_grow)