From 2ab4e5b7476479221802683f9b3ae67234e9754c Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 4 Dec 2024 21:34:44 -0700 Subject: [PATCH] Temp fix GCC alloca for cron, etc --- libc/include/alloca.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libc/include/alloca.h b/libc/include/alloca.h index 9b324d113..14a6bb3a8 100644 --- a/libc/include/alloca.h +++ b/libc/include/alloca.h @@ -1,15 +1,27 @@ #ifndef __ALLOCA_H #define __ALLOCA_H +/* + * Stack-checking alloca for GCC and OWC + */ // void *alloca(size_t); -int __stackavail(unsigned int size); -#define __ALLOCA_ALIGN(s) (((s)+(sizeof(int)-1))&~(sizeof(int)-1)) - #define alloca(s) (__stackavail(__ALLOCA_ALIGN(s))? \ __alloca(__ALLOCA_ALIGN(s)): (void *)0) +#define __ALLOCA_ALIGN(s) (((s)+(sizeof(int)-1))&~(sizeof(int)-1)) + +#ifdef __GNUC__ +/* The compiler auto-aligns the stack from the parameter somewhat strangely: + * 0 -> 0, 1 -> 2, 2 -> 4, 3 -> 4, 4 -> 6 etc. + * Thus, __stackavail should check for two more bytes available than asked for. + */ +#define __alloca(s) __builtin_alloca(s) +#define __stackavail(s) 0 /* temp no stack checking */ +#endif + #ifdef __WATCOMC__ +int __stackavail(unsigned int size); #pragma aux __stackavail "*" __modify __nomemory extern void __based(__segname("_STACK")) *__alloca(unsigned int __size);