@ -45,6 +45,8 @@ error_message_gpr:
.asciz " failed t o p r e s e r v e r e g i s t e r r % d "
error_message_vfp :
.asciz " failed t o p r e s e r v e r e g i s t e r d % d "
error_message_stack :
.asciz " failed t o p r e s e r v e s t a c k "
endconst
@ max number of args used by any asm function.
@ -52,8 +54,9 @@ endconst
# define A R G _ S T A C K 4 * ( M A X _ A R G S - 4 )
@ align the used stack space to 8 to preserve the stack alignment
# define A R G _ S T A C K _ A ( ( ( A R G _ S T A C K + p u s h e d + 7 ) & ~ 7 ) - p u s h e d )
@ Align the used stack space to 8 to preserve the stack alignment.
@ +8 for stack canary reference.
# define A R G _ S T A C K _ A ( ( ( A R G _ S T A C K + p u s h e d + 7 ) & ~ 7 ) - p u s h e d + 8 )
.macro clobbercheck variant
.equ pushed, 4 * 9
@ -80,14 +83,37 @@ function checkasm_checked_call_\variant, export=1
.equ pos, p o s + 4
.endr
@ For stack overflows, the callee is free to overwrite the parameters
@ that were passed on the stack (if any), so we can only check after
@ that point. First figure out how many parameters the function
@ really took on the stack:
ldr r12 , [ s p , #A R G _ S T A C K _ A + p u s h e d + 8 + 4 * ( M A X _ A R G S - 4 ) ]
@ Load the first non-parameter value from the stack, that should be
@ left untouched by the function. Store a copy of it inverted, so that
@ e.g. overwriting everything with zero would be noticed.
ldr r12 , [ s p , r12 , l s l #2 ]
mvn r12 , r12
str r12 , [ s p , #A R G _ S T A C K _ A - 4 ]
mov r12 , r0
mov r0 , r2
mov r1 , r3
ldrd r2 , r3 , [ s p , #A R G _ S T A C K _ A + p u s h e d ]
@ Call the target function
blx r12
add s p , s p , #A R G _ S T A C K _ A
@ Load the number of stack parameters, stack canary and its reference
ldr r12 , [ s p , #A R G _ S T A C K _ A + p u s h e d + 8 + 4 * ( M A X _ A R G S - 4 ) ]
ldr r2 , [ s p , r12 , l s l #2 ]
ldr r3 , [ s p , #A R G _ S T A C K _ A - 4 ]
add s p , s p , #A R G _ S T A C K _ A
push { r0 , r1 }
mvn r3 , r3
cmp r2 , r3
bne 5 f
movrel r12 , r e g i s t e r _ i n i t
.ifc \ variant, v f p
.macro check_ r e g _ v f p , d r e g , o f f s e t
@ -141,6 +167,9 @@ function checkasm_checked_call_\variant, export=1
.purgem check_reg
b 0 f
5 :
movrel r0 , e r r o r _ m e s s a g e _ s t a c k
b 1 f
4 :
movrel r0 , e r r o r _ m e s s a g e _ v f p
b 1 f