Add the 'akaros' threading model to gcc (XCC)
[akaros.git] / tools / compilers / gcc-glibc / glibc-2.19-akaros / include / alloca.h
1 #ifndef _ALLOCA_H
2
3 /* AKAROS: Modified the alloca cutoff */
4
5 #include <stdlib/alloca.h>
6 #include <stackinfo.h>
7
8 #undef  __alloca
9
10 /* Now define the internal interfaces.  */
11 extern void *__alloca (size_t __size);
12
13 #ifdef  __GNUC__
14 # define __alloca(size) __builtin_alloca (size)
15 #endif /* GCC.  */
16
17 extern int __libc_use_alloca (size_t size) __attribute__ ((const));
18 extern int __libc_alloca_cutoff (size_t size) __attribute__ ((const));
19 libc_hidden_proto (__libc_alloca_cutoff)
20
21 /* AKAROS: Limit to a small amount, so 2LSs and vcore context can have small
22  * stacks.  Glibc typically uses 1/4 of the stack.  Assuming our users have at
23  * least 4K stacks, we can use 1k, but let's be paranoid and use 512 for now. */
24 #define __MAX_ALLOCA_CUTOFF     512
25
26 #include <allocalim.h>
27
28 #ifndef stackinfo_alloca_round
29 # define stackinfo_alloca_round(l) (((l) + 15) & -16)
30 #endif
31
32 #if _STACK_GROWS_DOWN
33 # define extend_alloca(buf, len, newlen) \
34   (__typeof (buf)) ({ size_t __newlen = stackinfo_alloca_round (newlen);      \
35                       char *__newbuf = __alloca (__newlen);                   \
36                       if (__newbuf + __newlen == (char *) buf)                \
37                         len += __newlen;                                      \
38                       else                                                    \
39                         len = __newlen;                                       \
40                       __newbuf; })
41 #elif _STACK_GROWS_UP
42 # define extend_alloca(buf, len, newlen) \
43   (__typeof (buf)) ({ size_t __newlen = stackinfo_alloca_round (newlen);      \
44                       char *__newbuf = __alloca (__newlen);                   \
45                       char *__buf = (buf);                                    \
46                       if (__buf + len == __newbuf)                            \
47                         {                                                     \
48                           len += __newlen;                                    \
49                           __newbuf = __buf;                                   \
50                         }                                                     \
51                       else                                                    \
52                         len = __newlen;                                       \
53                       __newbuf; })
54 #else
55 # define extend_alloca(buf, len, newlen) \
56   __alloca (((len) = (newlen)))
57 #endif
58
59 #if defined stackinfo_get_sp && defined stackinfo_sub_sp
60 # define alloca_account(size, avar) \
61   ({ void *old__ = stackinfo_get_sp ();                                       \
62      void *m__ = __alloca (size);                                             \
63      avar += stackinfo_sub_sp (old__);                                        \
64      m__; })
65 # define extend_alloca_account(buf, len, newlen, avar) \
66   ({ void *old__ = stackinfo_get_sp ();                                       \
67      void *m__ = extend_alloca (buf, len, newlen);                            \
68      avar += stackinfo_sub_sp (old__);                                        \
69      m__; })
70 #else
71 # define alloca_account(size, avar) \
72   ({ size_t s__ = (size);                                                     \
73      avar += s__;                                                             \
74      __alloca (s__); })
75 # define extend_alloca_account(buf, len, newlen, avar) \
76   ({ size_t s__ = (newlen);                                                   \
77      avar += s__;                                                             \
78      extend_alloca (buf, len, s__); })
79 #endif
80
81 #endif