* add p cc
[mascara-docs.git] / compilers / pcc / pcc-libs-1.0.0 / libpcc / _alloca.c
blob6c4be739d511f8f2f7ccff7af6f521764dba032c
1 /* $Id: _alloca.c,v 1.4 2009/03/15 00:20:41 gmcgarry Exp $ */
2 /*
3 * This explanation of _alloca() comes from Chris Giese, posted to
4 * alt.os.dev:
6 * By default, Windows reserves 1 meg of virtual memory for the stack.
7 * No page of stack memory is actually allocated (commited) until the
8 * page is accessed. This is demand-allocation. The page beyond the
9 * top of the stack is the guard page. If this page is accessed,
10 * memory will be allocated for it, and the guard page moved downward
11 * by 4K (one page). Thus, the stack can grow beyond the initial 1 meg.
12 * Windows will not, however, let you grow the stack by accessing
13 * discontiguous pages of memory. Going beyond the guard page causes
14 * an exception. Stack-probing code prevents this.
17 #ifndef __MSC__
19 asm( " .text\n"
20 " .globl __alloca\n"
21 "__alloca:\n"
22 #ifdef __i386__
23 " pop %edx\n"
24 " pop %eax\n"
25 " add $3,%eax\n"
26 " and $-4,%eax\n"
27 "1: cmp $4096,%eax\n"
28 " jge 2f\n"
29 " sub %eax,%esp\n"
30 " test %eax,(%esp)\n"
31 " mov %esp,%eax\n"
32 " push %edx\n"
33 " push %edx\n"
34 " ret\n"
35 "2: sub $4096,%esp\n"
36 " sub $4096,%eax\n"
37 " test %eax,(%esp)\n"
38 " jmp 1b\n"
39 #endif
42 #endif