mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
eLua stack overflow fix
DETAILS: for most platforms, the main stack size was set to 256 bytes to save RAM. During a routine Lua debugging session, I discovered that there are at least two data structures in Lua (declared on the stack) that can lead to a stack overflow problem because of their size: lparser.h -> struct FuncState (original size: 572) is allocated on the stack when the parser needs to compile a Lua function lstrlib.c -> MatchState (original size: 272) is allocated on the stack everytime the string library does match-related operations. To fix the first problem I modified these macros in luaconf.h: /* @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function @* (must be smaller than 250). */ LUAI_MAXUPVALUES from 60 to 10 /* @@ LUAI_MAXVARS is the maximum number of local variables per function @* (must be smaller than 250). */ LUAI_MAXVARS from 200 to 25 The new size of the FuncState structure: 124 To fix the second problem I modified this macro in luaconf.g /* @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern @* can do during pattern-matching. ** CHANGE it if you need more captures. This limit is arbitrary. */ LUA_MAXCAPTURES from 32 to 10 The new size of the MatchState structure: 96 All these values are experimental, but they should work well. Also, I forced the main stack to 512 bytes in all the backends. Hopefully this will take care of this problem.
This commit is contained in:
parent
a529d5d835
commit
093108faad
@ -486,14 +486,14 @@
|
||||
@@ LUAI_MAXVARS is the maximum number of local variables per function
|
||||
@* (must be smaller than 250).
|
||||
*/
|
||||
#define LUAI_MAXVARS 200
|
||||
#define LUAI_MAXVARS 25
|
||||
|
||||
|
||||
/*
|
||||
@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
|
||||
@* (must be smaller than 250).
|
||||
*/
|
||||
#define LUAI_MAXUPVALUES 60
|
||||
#define LUAI_MAXUPVALUES 10
|
||||
|
||||
|
||||
/*
|
||||
@ -696,7 +696,7 @@ union luai_Cast { double l_d; long l_l; };
|
||||
@* can do during pattern-matching.
|
||||
** CHANGE it if you need more captures. This limit is arbitrary.
|
||||
*/
|
||||
#define LUA_MAXCAPTURES 32
|
||||
#define LUA_MAXCAPTURES 10
|
||||
|
||||
|
||||
/*
|
||||
|
@ -3,7 +3,7 @@
|
||||
#ifndef __STACKS_H__
|
||||
#define __STACKS_H__
|
||||
|
||||
#define STACK_SIZE_USR 256
|
||||
#define STACK_SIZE_USR 512
|
||||
#define STACK_SIZE_IRQ 64
|
||||
#define STACK_SIZE_TOTAL ( STACK_SIZE_USR + STACK_SIZE_IRQ )
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#ifndef __STACKS_H__
|
||||
#define __STACKS_H__
|
||||
|
||||
#define STACK_SIZE_SVC 256
|
||||
#define STACK_SIZE_SVC 512
|
||||
#define STACK_SIZE_IRQ 32
|
||||
#define STACK_SIZE_TOTAL ( STACK_SIZE_SVC + STACK_SIZE_IRQ )
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#ifndef __STACKS_H__
|
||||
#define __STACKS_H__
|
||||
|
||||
#define STACK_SIZE_USR 256
|
||||
#define STACK_SIZE_USR 512
|
||||
#define STACK_SIZE_TOTAL ( STACK_SIZE_USR )
|
||||
|
||||
#endif
|
||||
|
@ -3,9 +3,8 @@
|
||||
#ifndef __STACKS_H__
|
||||
#define __STACKS_H__
|
||||
|
||||
#define STACK_SIZE_USR 256
|
||||
#define STACK_SIZE_SVC 32
|
||||
#define STACK_SIZE_SVC 512
|
||||
#define STACK_SIZE_IRQ 32
|
||||
#define STACK_SIZE_TOTAL ( STACK_SIZE_USR + STACK_SIZE_SVC + STACK_SIZE_IRQ )
|
||||
#define STACK_SIZE_TOTAL ( STACK_SIZE_SVC + STACK_SIZE_IRQ )
|
||||
|
||||
#endif
|
||||
|
@ -251,13 +251,8 @@ PLL_LOCK_LOOP:
|
||||
sub r0, r0, #STACK_SIZE_IRQ
|
||||
|
||||
# Set up Supervisor Mode and set Supervisor Mode Stack
|
||||
msr CPSR_c, #Mode_SVC|I_BIT|F_BIT
|
||||
msr CPSR_c, #Mode_SVC
|
||||
mov r13, r0
|
||||
sub r0, r0, #STACK_SIZE_SVC
|
||||
|
||||
# Set up User Mode and set User Mode Stack
|
||||
msr CPSR_c, #Mode_USR /* Leave interrupts enabled in user mode */
|
||||
mov r13, r0 /* Note: interrupts will not happen until VIC is enabled */
|
||||
|
||||
#*************************************************************************
|
||||
# Initialise RAM For Compiler Variables
|
||||
|
Loading…
x
Reference in New Issue
Block a user