summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mm/memlock.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 17dee1c9..dfc0d42b 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -124,8 +124,12 @@ static void _touch_memory(void *mem, size_t size)
static void _allocate_memory(void)
{
void *stack_mem, *temp_malloc_mem;
+ struct rlimit limit;
- if ((stack_mem = alloca(_size_stack)))
+ /* Check if we could preallocate requested stack */
+ if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
+ ((_size_stack * 2) < limit.rlim_cur) &&
+ ((stack_mem = alloca(_size_stack))))
_touch_memory(stack_mem, _size_stack);
if ((temp_malloc_mem = malloc(_size_malloc_tmp)))