update for HEAD-2003021201
[reactos.git] / lib / crtdll / stdlib / alloca.c
1 #include <windows.h>
2 #include <msvcrt/stdlib.h>
3
4
5 #undef alloca
6 void *alloca(size_t s)
7 {
8         register unsigned int as = s;
9
10 // alloca(0) should not return the stack pointer
11         if ( s == 0 )
12                 return NULL;
13
14         
15         if ( (s & 0xfffffffc)  != 0 )
16                 as += 4;
17                 
18         as &= 0xfffffffc;
19         
20         __asm__ __volatile__(
21         "mov %0, %%edx          \n"
22 //      "popl %%ebp             \n"
23         "leave                  \n"
24         "popl  %%ecx            \n"
25         "subl  %%edx, %%esp     \n"
26         "movl  %%esp, %%eax     \n"
27         "addl  $20, %%eax        \n"//4 bytes + 16 bytes = arguments
28         "push  %%ecx            \n"
29         "ret                    \n"
30         :
31         :"g" ( as)
32         );
33         
34        
35         return NULL;
36 }
37
38 void *_alloca(size_t s)
39 {
40         register unsigned int as = s;
41
42 // alloca(0) should not return the stack pointer
43         if ( s == 0 )
44                 return NULL;
45
46         
47         if ( (s & 0xfffffffc)  != 0 )
48                 as += 4;
49                 
50         as &= 0xfffffffc;
51         
52         __asm__ __volatile__(
53         "mov %0, %%edx          \n"
54 //      "popl %%ebp             \n"
55         "leave                  \n"
56         "popl  %%ecx            \n"
57         "subl  %%edx, %%esp     \n"
58         "movl  %%esp, %%eax     \n"
59         "addl  $20, %%eax        \n"//4 bytes + 16 bytes = arguments
60         "push  %%ecx            \n"
61         "ret                    \n"
62         :
63         :"g" ( as)
64         );
65         
66        
67         return NULL;
68 }