Skip to content

Commit

Permalink
Temp fix GCC alloca for cron, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Dec 5, 2024
1 parent b5f6cb3 commit 2ab4e5b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libc/include/alloca.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 2ab4e5b

Please sign in to comment.