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