From 8ada354c9b5d72356c34c9ae3f787a6df4d61506 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Wed, 16 Nov 2016 10:57:30 +0200 Subject: [PATCH] checkasm: aarch64: Clobber the stack before calling functions --- tools/checkasm-aarch64.S | 13 +++++++++++++ tools/checkasm.c | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/checkasm-aarch64.S b/tools/checkasm-aarch64.S index af4ed31a..1eb4546b 100644 --- a/tools/checkasm-aarch64.S +++ b/tools/checkasm-aarch64.S @@ -56,6 +56,19 @@ error_message: // max number of args used by any x264 asm function. #define MAX_ARGS 15 +#define CLOBBER_STACK ((8*MAX_ARGS + 15) & ~15) + +function x264_checkasm_stack_clobber, export=1 + mov x3, sp + mov x2, #CLOBBER_STACK +1: + stp x0, x1, [sp, #-16]! + subs x2, x2, #16 + b.gt 1b + mov sp, x3 + ret +endfunc + #define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15) function x264_checkasm_call, export=1 diff --git a/tools/checkasm.c b/tools/checkasm.c index 8785cc89..cd0e275c 100644 --- a/tools/checkasm.c +++ b/tools/checkasm.c @@ -258,7 +258,13 @@ void x264_checkasm_stack_clobber( uint64_t clobber, ... ); uint64_t r = (rand() & 0xffff) * 0x0001000100010001ULL; \ x264_checkasm_stack_clobber( r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r ); /* max_args+6 */ \ x264_checkasm_call(( intptr_t(*)())func, &ok, 0, 0, 0, 0, __VA_ARGS__ ); }) -#elif ARCH_X86 || (ARCH_AARCH64 && !defined(__APPLE__)) || ARCH_ARM +#elif ARCH_AARCH64 && !defined(__APPLE__) +void x264_checkasm_stack_clobber( uint64_t clobber, ... ); +#define call_a1(func,...) ({ \ + uint64_t r = (rand() & 0xffff) * 0x0001000100010001ULL; \ + x264_checkasm_stack_clobber( r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r ); /* max_args+8 */ \ + x264_checkasm_call(( intptr_t(*)())func, &ok, __VA_ARGS__ ); }) +#elif ARCH_X86 || ARCH_ARM #define call_a1(func,...) x264_checkasm_call( (intptr_t(*)())func, &ok, __VA_ARGS__ ) #else #define call_a1 call_c1 -- 2.40.0