From patchwork Thu May 14 13:14:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19684 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B7EB744BB27 for ; Thu, 14 May 2020 16:22:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8FEEE689A2B; Thu, 14 May 2020 16:22:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA4676807D3 for ; Thu, 14 May 2020 16:21:56 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id b91so2371287edf.3 for ; Thu, 14 May 2020 06:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=A+dSIM7uBP/RPMYhWhtb16nRHc0Sw/4JoRRTY51XhDM=; b=x+YPvmcqy295wFmzC7hs3lk3Fv18umzHAMZu9rrKG2UuCxs9YxV6rxkeYEPWNlaSFm VMvdYck5mF9tfPtM0q5JSXlTHjxvamexbgBs+/Sp+OqPEn8ONm/GyPTnsN5V26uFwiFq re8ENdMKkzSdm26TzQw6W+R7bv6VnTS/nxCutoDjdYWsSJOZV8lrWZE+/5wSHIHNk/h3 KPUcditZZRvG8ynZg4S07IAxyrD6GwYY+Bmtkan9p7z3Hzkww0kgVgecdJtgL1qrjmCM wNvbMUg4JafZJFNcAMH2/dp5Jds5lN85rXgHO+CD/Fs3tUDwpmoSJN1DSsSDTR3OU2dg QSLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=A+dSIM7uBP/RPMYhWhtb16nRHc0Sw/4JoRRTY51XhDM=; b=Esihy+1xWuEt+yuNOjuyEc8LUxWZj44FtEghJK+vKovkeqc+Y1+yz5DcwnfWbgbDux IVHbG6rqSQKwM3bQHkFq0AEItsKFlVCjySJYl6Bdr9tDSaS3IPeky3slN1cTCyL6mQKS ZFsibGcv+8kEuLgy1YzWsMOSz7UkK9U/v+lPEc8yd/iiwAn1QK7vz899fXZqGHENcoEk ea/WLg7aghW5MA14I5ozfhAdVgG5FXMIb8WPajrGhsB+Djfn40YJPvZjHcn8bcQG81XU cdjBkmQ20xfz715np2iB6pA78xY0tjX3zBMrEW++mEeqEyDEuAZdsv8AqXZoJz8IHiBD EzoA== X-Gm-Message-State: AOAM5331MYXIsMB3VssFm1cwMFJdr9yI+922BMTyKrdvuP9r9ZhrL8GB kkA3p/VoAXvyjQE+l6zuT1vZ4XEOvfg= X-Google-Smtp-Source: ABdhPJxab/j5Jqrb9PBqc7cUCJTLxPifAN3pq5BnIKZrKH7enBH6xnjTlfQy/feVHNJxj6ZcJzymMQ== X-Received: by 2002:ac2:5182:: with SMTP id u2mr3330170lfi.64.1589462053379; Thu, 14 May 2020 06:14:13 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id s9sm1305164ljc.43.2020.05.14.06.14.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:14:13 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 16:14:08 +0300 Message-Id: <20200514131412.27655-1-martin@martin.st> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/5] aarch64: Explicitly forbid using the x18 register X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On windows and darwin (and modern android), the x18 register is reserved and shouldn't be modified by user code, while it is freely available on linux. Strictly avoid it, to keep the assembly code portable. This would have helped catch the issue fixed in 872790b1f9be6 immediately. --- libavutil/aarch64/asm.S | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S index 3ac2ba0d52..d1fa72b3c6 100644 --- a/libavutil/aarch64/asm.S +++ b/libavutil/aarch64/asm.S @@ -112,3 +112,6 @@ ELF .size \name, . - \name #define GLUE(a, b) a ## b #define JOIN(a, b) GLUE(a, b) #define X(s) JOIN(EXTERN_ASM, s) + +#define x18 do_not_use_x18 +#define w18 do_not_use_w18 From patchwork Thu May 14 13:14:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19687 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 46CB944BB27 for ; Thu, 14 May 2020 16:22:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 303E768A47E; Thu, 14 May 2020 16:22:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BEE268A3DF for ; Thu, 14 May 2020 16:22:19 +0300 (EEST) Received: by mail-lf1-f48.google.com with SMTP id 8so2629395lfp.4 for ; Thu, 14 May 2020 06:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=GC0UQD5lCLz0PQ1E+Vjh9MCLVr6ekOySX0/hBYkQulQ=; b=p7NIcuEpM2KynJS+RHptTvHguSYekXyESemA+4fPA5B9ED3cDsJKsOZxDFHG4+rBT+ qaYID9iLSXIoaw8RXg4CKo2l6ToeQ/JN/8xFlefzIING98bsAAG4yN3pci+B1fXCJJSO HIT+DU+wvDr6t4Cf9Z+ZP6jUpv3NUpMwnV3AUWltnC+KJ4Z0hRMV7f/01NQg++kMPid4 DUxcYJvHpcGy4fSP4vWTtXhE9Ra4aCRoWzHxNtSSNbegMb20IwMjXSArv7WsLP/pgSIF xcuT2g++gurysp9WrmX8Pu9PpguW4f/I+gjCXqgAZiPT0ki0o+uK3tWUP4CZCewCsRL9 oiJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=GC0UQD5lCLz0PQ1E+Vjh9MCLVr6ekOySX0/hBYkQulQ=; b=hbHiSE26NtMLh4BEYlXhl+k47eLJfJ8hyt8SyRE59XVq1snB6Kgci73S9JckcsPgi9 wdtIeo7tK7EM6JrWiqx98aMgo8dqK/2BBT3ehGKbzUxSuD0EfXxZlw53eJvdr5Bl1U/M xv1tkcpTlQN4pGIJSw219HKyTX0xjMOcYXxyBTqXOcCm1+ncjTPlpvHMAcUjMNE58MRX zjVEA7KFg7uHi5lOtLYaDhyWNS/KYp3OHsz8mzPE/MnhhsTpUnogzHuCCoa73UBX1NFl RHtqJ4muaGGN64H7jKTIqm1e12U1JnpOSWJ3s7hZlH8g7is/9Mqijja1GzTKWTvwWLPG 4syA== X-Gm-Message-State: AOAM5326N5h7Cs8uEKAE1lcZXssCOrwK6rwp5ON/r6GXvkBhKywqVd0u pyVPbkrjUk12MotPcaT3T6/xFdYTPEc= X-Google-Smtp-Source: ABdhPJyNEP9hIXrZb32dplqHEcnE/GQp5+EOSgdsV4IUHZqBoTiXG6dLWYjVzWpjwno9RlvHYIN5RA== X-Received: by 2002:a05:6512:1051:: with SMTP id c17mr3318440lfb.206.1589462054097; Thu, 14 May 2020 06:14:14 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id s9sm1305164ljc.43.2020.05.14.06.14.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:14:13 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 16:14:09 +0300 Message-Id: <20200514131412.27655-2-martin@martin.st> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200514131412.27655-1-martin@martin.st> References: <20200514131412.27655-1-martin@martin.st> Subject: [FFmpeg-devel] [PATCH 2/5] checkasm: arm: Make the indentation consistent with other files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This makes it easier to share code with e.g. the dav1d implementation of checkasm. --- tests/checkasm/aarch64/checkasm.S | 196 +++++++++++++++--------------- tests/checkasm/arm/checkasm.S | 144 +++++++++++----------- 2 files changed, 170 insertions(+), 170 deletions(-) diff --git a/tests/checkasm/aarch64/checkasm.S b/tests/checkasm/aarch64/checkasm.S index 89f2b77548..0dbfe8025e 100644 --- a/tests/checkasm/aarch64/checkasm.S +++ b/tests/checkasm/aarch64/checkasm.S @@ -23,29 +23,29 @@ #include "libavutil/aarch64/asm.S" const register_init, align=4 - .quad 0x21f86d66c8ca00ce - .quad 0x75b6ba21077c48ad - .quad 0xed56bb2dcb3c7736 - .quad 0x8bda43d3fd1a7e06 - .quad 0xb64a9c9e5d318408 - .quad 0xdf9a54b303f1d3a3 - .quad 0x4a75479abd64e097 - .quad 0x249214109d5d1c88 - .quad 0x1a1b2550a612b48c - .quad 0x79445c159ce79064 - .quad 0x2eed899d5a28ddcd - .quad 0x86b2536fcd8cf636 - .quad 0xb0856806085e7943 - .quad 0x3f2bf84fc0fcca4e - .quad 0xacbd382dcf5b8de2 - .quad 0xd229e1f5b281303f - .quad 0x71aeaff20b095fd9 - .quad 0xab63e2e11fa38ed9 + .quad 0x21f86d66c8ca00ce + .quad 0x75b6ba21077c48ad + .quad 0xed56bb2dcb3c7736 + .quad 0x8bda43d3fd1a7e06 + .quad 0xb64a9c9e5d318408 + .quad 0xdf9a54b303f1d3a3 + .quad 0x4a75479abd64e097 + .quad 0x249214109d5d1c88 + .quad 0x1a1b2550a612b48c + .quad 0x79445c159ce79064 + .quad 0x2eed899d5a28ddcd + .quad 0x86b2536fcd8cf636 + .quad 0xb0856806085e7943 + .quad 0x3f2bf84fc0fcca4e + .quad 0xacbd382dcf5b8de2 + .quad 0xd229e1f5b281303f + .quad 0x71aeaff20b095fd9 + .quad 0xab63e2e11fa38ed9 endconst const error_message - .asciz "failed to preserve register" + .asciz "failed to preserve register" endconst @@ -55,103 +55,103 @@ endconst #define CLOBBER_STACK ((8*MAX_ARGS + 15) & ~15) function checkasm_stack_clobber, export=1 - mov x3, sp - mov x2, #CLOBBER_STACK + mov x3, sp + mov x2, #CLOBBER_STACK 1: - stp x0, x1, [sp, #-16]! - subs x2, x2, #16 - b.gt 1b - mov sp, x3 - ret + 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 checkasm_checked_call, export=1 - stp x29, x30, [sp, #-16]! - mov x29, sp - stp x19, x20, [sp, #-16]! - stp x21, x22, [sp, #-16]! - stp x23, x24, [sp, #-16]! - stp x25, x26, [sp, #-16]! - stp x27, x28, [sp, #-16]! - stp d8, d9, [sp, #-16]! - stp d10, d11, [sp, #-16]! - stp d12, d13, [sp, #-16]! - stp d14, d15, [sp, #-16]! - - movrel x9, register_init - ldp d8, d9, [x9], #16 - ldp d10, d11, [x9], #16 - ldp d12, d13, [x9], #16 - ldp d14, d15, [x9], #16 - ldp x19, x20, [x9], #16 - ldp x21, x22, [x9], #16 - ldp x23, x24, [x9], #16 - ldp x25, x26, [x9], #16 - ldp x27, x28, [x9], #16 - - sub sp, sp, #ARG_STACK + stp x29, x30, [sp, #-16]! + mov x29, sp + stp x19, x20, [sp, #-16]! + stp x21, x22, [sp, #-16]! + stp x23, x24, [sp, #-16]! + stp x25, x26, [sp, #-16]! + stp x27, x28, [sp, #-16]! + stp d8, d9, [sp, #-16]! + stp d10, d11, [sp, #-16]! + stp d12, d13, [sp, #-16]! + stp d14, d15, [sp, #-16]! + + movrel x9, register_init + ldp d8, d9, [x9], #16 + ldp d10, d11, [x9], #16 + ldp d12, d13, [x9], #16 + ldp d14, d15, [x9], #16 + ldp x19, x20, [x9], #16 + ldp x21, x22, [x9], #16 + ldp x23, x24, [x9], #16 + ldp x25, x26, [x9], #16 + ldp x27, x28, [x9], #16 + + sub sp, sp, #ARG_STACK .equ pos, 0 .rept MAX_ARGS-8 - // Skip the first 8 args, that are loaded into registers - ldr x9, [x29, #16 + 8*8 + pos] - str x9, [sp, #pos] + // Skip the first 8 args, that are loaded into registers + ldr x9, [x29, #16 + 8*8 + pos] + str x9, [sp, #pos] .equ pos, pos + 8 .endr - mov x12, x0 - ldp x0, x1, [x29, #16] - ldp x2, x3, [x29, #32] - ldp x4, x5, [x29, #48] - ldp x6, x7, [x29, #64] - blr x12 - add sp, sp, #ARG_STACK - stp x0, x1, [sp, #-16]! - movrel x9, register_init - movi v3.8h, #0 + mov x12, x0 + ldp x0, x1, [x29, #16] + ldp x2, x3, [x29, #32] + ldp x4, x5, [x29, #48] + ldp x6, x7, [x29, #64] + blr x12 + add sp, sp, #ARG_STACK + stp x0, x1, [sp, #-16]! + movrel x9, register_init + movi v3.8h, #0 .macro check_reg_neon reg1, reg2 - ldr q1, [x9], #16 - uzp1 v2.2d, v\reg1\().2d, v\reg2\().2d - eor v1.16b, v1.16b, v2.16b - orr v3.16b, v3.16b, v1.16b + ldr q1, [x9], #16 + uzp1 v2.2d, v\reg1\().2d, v\reg2\().2d + eor v1.16b, v1.16b, v2.16b + orr v3.16b, v3.16b, v1.16b .endm - check_reg_neon 8, 9 - check_reg_neon 10, 11 - check_reg_neon 12, 13 - check_reg_neon 14, 15 - uqxtn v3.8b, v3.8h - umov x3, v3.d[0] + check_reg_neon 8, 9 + check_reg_neon 10, 11 + check_reg_neon 12, 13 + check_reg_neon 14, 15 + uqxtn v3.8b, v3.8h + umov x3, v3.d[0] .macro check_reg reg1, reg2 - ldp x0, x1, [x9], #16 - eor x0, x0, \reg1 - eor x1, x1, \reg2 - orr x3, x3, x0 - orr x3, x3, x1 + ldp x0, x1, [x9], #16 + eor x0, x0, \reg1 + eor x1, x1, \reg2 + orr x3, x3, x0 + orr x3, x3, x1 .endm - check_reg x19, x20 - check_reg x21, x22 - check_reg x23, x24 - check_reg x25, x26 - check_reg x27, x28 + check_reg x19, x20 + check_reg x21, x22 + check_reg x23, x24 + check_reg x25, x26 + check_reg x27, x28 - cbz x3, 0f + cbz x3, 0f - movrel x0, error_message - bl X(checkasm_fail_func) + movrel x0, error_message + bl X(checkasm_fail_func) 0: - ldp x0, x1, [sp], #16 - ldp d14, d15, [sp], #16 - ldp d12, d13, [sp], #16 - ldp d10, d11, [sp], #16 - ldp d8, d9, [sp], #16 - ldp x27, x28, [sp], #16 - ldp x25, x26, [sp], #16 - ldp x23, x24, [sp], #16 - ldp x21, x22, [sp], #16 - ldp x19, x20, [sp], #16 - ldp x29, x30, [sp], #16 - ret + ldp x0, x1, [sp], #16 + ldp d14, d15, [sp], #16 + ldp d12, d13, [sp], #16 + ldp d10, d11, [sp], #16 + ldp d8, d9, [sp], #16 + ldp x27, x28, [sp], #16 + ldp x25, x26, [sp], #16 + ldp x23, x24, [sp], #16 + ldp x21, x22, [sp], #16 + ldp x19, x20, [sp], #16 + ldp x29, x30, [sp], #16 + ret endfunc diff --git a/tests/checkasm/arm/checkasm.S b/tests/checkasm/arm/checkasm.S index 2051b290f6..838c383671 100644 --- a/tests/checkasm/arm/checkasm.S +++ b/tests/checkasm/arm/checkasm.S @@ -29,22 +29,22 @@ ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch #endif const register_init, align=3 - .quad 0x21f86d66c8ca00ce - .quad 0x75b6ba21077c48ad - .quad 0xed56bb2dcb3c7736 - .quad 0x8bda43d3fd1a7e06 - .quad 0xb64a9c9e5d318408 - .quad 0xdf9a54b303f1d3a3 - .quad 0x4a75479abd64e097 - .quad 0x249214109d5d1c88 + .quad 0x21f86d66c8ca00ce + .quad 0x75b6ba21077c48ad + .quad 0xed56bb2dcb3c7736 + .quad 0x8bda43d3fd1a7e06 + .quad 0xb64a9c9e5d318408 + .quad 0xdf9a54b303f1d3a3 + .quad 0x4a75479abd64e097 + .quad 0x249214109d5d1c88 endconst const error_message_fpscr - .asciz "failed to preserve register FPSCR, changed bits: %x" + .asciz "failed to preserve register FPSCR, changed bits: %x" error_message_gpr: - .asciz "failed to preserve register r%d" + .asciz "failed to preserve register r%d" error_message_vfp: - .asciz "failed to preserve register d%d" + .asciz "failed to preserve register d%d" endconst @ max number of args used by any asm function. @@ -58,107 +58,107 @@ endconst .macro clobbercheck variant .equ pushed, 4*9 function checkasm_checked_call_\variant, export=1 - push {r4-r11, lr} + push {r4-r11, lr} .ifc \variant, vfp - vpush {d8-d15} - fmrx r4, FPSCR - push {r4} + vpush {d8-d15} + fmrx r4, FPSCR + push {r4} .equ pushed, pushed + 16*4 + 4 .endif - movrel r12, register_init + movrel r12, register_init .ifc \variant, vfp - vldm r12, {d8-d15} + vldm r12, {d8-d15} .endif - ldm r12, {r4-r11} + ldm r12, {r4-r11} - sub sp, sp, #ARG_STACK_A + sub sp, sp, #ARG_STACK_A .equ pos, 0 .rept MAX_ARGS-4 - ldr r12, [sp, #ARG_STACK_A + pushed + 8 + pos] - str r12, [sp, #pos] + ldr r12, [sp, #ARG_STACK_A + pushed + 8 + pos] + str r12, [sp, #pos] .equ pos, pos + 4 .endr - mov r12, r0 - mov r0, r2 - mov r1, r3 - ldrd r2, r3, [sp, #ARG_STACK_A + pushed] - blx r12 - add sp, sp, #ARG_STACK_A + mov r12, r0 + mov r0, r2 + mov r1, r3 + ldrd r2, r3, [sp, #ARG_STACK_A + pushed] + blx r12 + add sp, sp, #ARG_STACK_A - push {r0, r1} - movrel r12, register_init + push {r0, r1} + movrel r12, register_init .ifc \variant, vfp .macro check_reg_vfp, dreg, offset - ldrd r2, r3, [r12, #8 * (\offset)] - vmov r0, lr, \dreg - eor r2, r2, r0 - eor r3, r3, lr - orrs r2, r2, r3 - bne 4f + ldrd r2, r3, [r12, #8 * (\offset)] + vmov r0, lr, \dreg + eor r2, r2, r0 + eor r3, r3, lr + orrs r2, r2, r3 + bne 4f .endm .irp n, 8, 9, 10, 11, 12, 13, 14, 15 - @ keep track of the checked double/SIMD register - mov r1, #\n - check_reg_vfp d\n, \n-8 + @ keep track of the checked double/SIMD register + mov r1, #\n + check_reg_vfp d\n, \n-8 .endr .purgem check_reg_vfp - fmrx r1, FPSCR - ldr r3, [sp, #8] - eor r1, r1, r3 - @ Ignore changes in bits 0-4 and 7 - bic r1, r1, #0x9f - @ Ignore changes in the topmost 5 bits - bics r1, r1, #0xf8000000 - bne 3f + fmrx r1, FPSCR + ldr r3, [sp, #8] + eor r1, r1, r3 + @ Ignore changes in bits 0-4 and 7 + bic r1, r1, #0x9f + @ Ignore changes in the topmost 5 bits + bics r1, r1, #0xf8000000 + bne 3f .endif - @ keep track of the checked GPR - mov r1, #4 + @ keep track of the checked GPR + mov r1, #4 .macro check_reg reg1, reg2= - ldrd r2, r3, [r12], #8 - eors r2, r2, \reg1 - bne 2f - add r1, r1, #1 + ldrd r2, r3, [r12], #8 + eors r2, r2, \reg1 + bne 2f + add r1, r1, #1 .ifnb \reg2 - eors r3, r3, \reg2 - bne 2f + eors r3, r3, \reg2 + bne 2f .endif - add r1, r1, #1 + add r1, r1, #1 .endm - check_reg r4, r5 - check_reg r6, r7 + check_reg r4, r5 + check_reg r6, r7 @ r9 is a volatile register in the ios ABI #ifdef __APPLE__ - check_reg r8 + check_reg r8 #else - check_reg r8, r9 + check_reg r8, r9 #endif - check_reg r10, r11 + check_reg r10, r11 .purgem check_reg - b 0f + b 0f 4: - movrel r0, error_message_vfp - b 1f + movrel r0, error_message_vfp + b 1f 3: - movrel r0, error_message_fpscr - b 1f + movrel r0, error_message_fpscr + b 1f 2: - movrel r0, error_message_gpr + movrel r0, error_message_gpr 1: - blx X(checkasm_fail_func) + blx X(checkasm_fail_func) 0: - pop {r0, r1} + pop {r0, r1} .ifc \variant, vfp - pop {r2} - fmxr FPSCR, r2 - vpop {d8-d15} + pop {r2} + fmxr FPSCR, r2 + vpop {d8-d15} .endif - pop {r4-r11, pc} + pop {r4-r11, pc} endfunc .endm From patchwork Thu May 14 13:14:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19683 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A798044AFEB for ; Thu, 14 May 2020 16:20:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FBBF6882E5; Thu, 14 May 2020 16:20:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEC9C68803A for ; Thu, 14 May 2020 16:19:57 +0300 (EEST) Received: by mail-lf1-f47.google.com with SMTP id b26so2605323lfa.5 for ; Thu, 14 May 2020 06:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=91xwyti2emA2FBywfW95H7vQKWDF6KR1PIUmtMJp/ZU=; b=zZW5X6TDFu6ckA9E3M/MeT77s8iy2wKIkH2IQEK3ywWOZmoZCu3yAy6D2fiYD+XG04 7xylHNK410QEyF6wCCidXA81Kcivjy5ROx2bJTGdYAFlptM7DLfqcwUQMrilkNWJ4Q8u saYaMs5ffKGiTxStwPjMGnv59DozMZGVcALTSYX1GD1dANd+3gWbBRtg4gURInwVhOc7 XqgsOYULutlaWCy2iqjp8DYvPHkY0H1p9eZ1u47v87Dj16niBm/fvI/WG9Chw7qR+z4n Di9vYGRjBYQ4oi8G/00JfMuA//RmSj2rNjrj/eF16rODJqeCC+60jJTF79gcyFFWWwLP /amg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=91xwyti2emA2FBywfW95H7vQKWDF6KR1PIUmtMJp/ZU=; b=AThnCPyO1vGb/+7wNVDkmgFLLzi1LGiktldFRAV9ydCP6txravB8NPl46nRVdWP6C5 AQBvvSgPWPaMxCaXZKYn+ipgNIxjRRvCnmGrm6MbDtmao3dt3JG7iiP58ecdOvpcFCVw xmeVCgfipBNNNIOHJHZUnGkqt8GhUwWCKHMAk42zxoaGvXYbwp3zGrQefNeBJoP2VdF4 lWWzVUPiBHQehp1tK8GCWhNjMviurxJZrbCm85OCINbr9zPJR++4WIH4aTFPtEGNwyI1 6JPMKUWLHA75k0g3v+O7GcjibIp0XdpWXzAyZZdiNzrtC6/QSdndmCsx1qu8ujYlrVK7 97Tw== X-Gm-Message-State: AOAM5320Kcg2+NULGgBpAmXhBXM40YJ1phVUKLILxPkxddq8bGT4GVPz codYHFAjORkv4S6pn5T+sGmGPc9sZPg= X-Google-Smtp-Source: ABdhPJwx0lApO9MX+xIfcst5WsuICY5j2dw3wvgKnk/fEoRL69nB0nUG9xtnYZcueombjU9GA7JuGQ== X-Received: by 2002:ac2:4a70:: with SMTP id q16mr3269278lfp.79.1589462054873; Thu, 14 May 2020 06:14:14 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id s9sm1305164ljc.43.2020.05.14.06.14.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:14:14 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 16:14:10 +0300 Message-Id: <20200514131412.27655-3-martin@martin.st> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200514131412.27655-1-martin@martin.st> References: <20200514131412.27655-1-martin@martin.st> Subject: [FFmpeg-devel] [PATCH 3/5] checkasm: arm: Don't use blx to call checkasm_fail_func X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" We should just use a normal bl here, and the linker will add the 'x' bit if necessary. This fixes calling the checkasm_fail_func on windows, where the code is built in thumb mode (and the linker doesn't clear the 'x' bit in the blx instruction). --- tests/checkasm/arm/checkasm.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/checkasm/arm/checkasm.S b/tests/checkasm/arm/checkasm.S index 838c383671..a5ba238684 100644 --- a/tests/checkasm/arm/checkasm.S +++ b/tests/checkasm/arm/checkasm.S @@ -150,7 +150,7 @@ function checkasm_checked_call_\variant, export=1 2: movrel r0, error_message_gpr 1: - blx X(checkasm_fail_func) + bl X(checkasm_fail_func) 0: pop {r0, r1} .ifc \variant, vfp From patchwork Thu May 14 13:14:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19685 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9CD0044BB27 for ; Thu, 14 May 2020 16:22:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8567D689AA9; Thu, 14 May 2020 16:22:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD398689963 for ; Thu, 14 May 2020 16:22:02 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id u6so3480844ljl.6 for ; Thu, 14 May 2020 06:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=F7RuiLX+mlocfStO9zR++TL6ZZbuiVg+8fhyWtM44H0=; b=W5ME2eW6heZtCNio/YCL4P5ztKkw4z0J+SIFfujyFZuVNmN+djMuOjeBPqNAkWPG/X 6vlXCCQkW1mxpbBsq9Ovk2GdsC78Xn1JeBXBVc8SkugPS150IDxRJqXy/9N4qsbE3U8C C4+6Ws9jWNyKhm7DO2pBrrl9PujfLknjoj5lVcmYDmPOuqDetrRqijySBf8ESu0NV/W5 W8/j3wf0Y1o9yzpvJyLqRmwZ7uBhY/oBKWQRXPost9X2JK6ekUOYv8NRsOCy3qA4PE6Q POHfXaBterUm7QPcbu+UNfJrfXNp+O1LSle9oU1ndaSlS+QvTTomsNfdCsCrQ1fN/3AQ yDLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=F7RuiLX+mlocfStO9zR++TL6ZZbuiVg+8fhyWtM44H0=; b=aUYjH+sqQwGdZyVFFLwFiMZmrufxNddu7aglsYipYq/z9wzyWfe/dJjIALeEnESy1J oAyqt+J0SKdrDs/eLTbQGz6407zYJsVLPWJymDhTRVDgxX+HYNUY4aW/m8Vg+8o5hcO+ nUinjbnDZVQMVl2vQWFNpt66XxCyzOS+quw45pm38j9yRJjYP2LgpxKIJWYrZ4Q7hIgS T5kE3rbKy/WA+1XIZtnEF6OI94V/d+3GcywJs8LUdO9JrqFSxu89Exsat/M3CVqcsEtO a2xgFW28OC4j1T4yNpib/gDqhp60gBb4gjR1kp7uOoXM/7xNezgRCszGq4y6I4c5ZFmd 3XQQ== X-Gm-Message-State: AOAM530owkueuL8ufuOwKUtGgIevKAGFPxrHdCVShGAl3dJ+Wz7TOtVH 9fbMxOZUED0JCmYHAACq+bKbXQUGMwA= X-Google-Smtp-Source: ABdhPJxodd9JzSWN/drunRhS2AFITExc+vyWFFi1DMispHTkLSBhjc4wPfZ+KCtP5Lm9PkdR8d5sMA== X-Received: by 2002:ac2:4145:: with SMTP id c5mr3332848lfi.91.1589462055399; Thu, 14 May 2020 06:14:15 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id s9sm1305164ljc.43.2020.05.14.06.14.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:14:15 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 16:14:11 +0300 Message-Id: <20200514131412.27655-4-martin@martin.st> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200514131412.27655-1-martin@martin.st> References: <20200514131412.27655-1-martin@martin.st> Subject: [FFmpeg-devel] [PATCH 4/5] checkasm: arm: Check for stack overflows X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Figure out the number of stack parameters and make sure that the value on the stack after those is untouched. --- tests/checkasm/arm/checkasm.S | 35 ++++++++++++++++++++++++++++++++--- tests/checkasm/checkasm.h | 6 ++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/checkasm/arm/checkasm.S b/tests/checkasm/arm/checkasm.S index a5ba238684..601c2f66b8 100644 --- a/tests/checkasm/arm/checkasm.S +++ b/tests/checkasm/arm/checkasm.S @@ -45,6 +45,8 @@ error_message_gpr: .asciz "failed to preserve register r%d" error_message_vfp: .asciz "failed to preserve register d%d" +error_message_stack: + .asciz "failed to preserve stack" endconst @ max number of args used by any asm function. @@ -52,8 +54,9 @@ endconst #define ARG_STACK 4*(MAX_ARGS - 4) -@ align the used stack space to 8 to preserve the stack alignment -#define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed) +@ Align the used stack space to 8 to preserve the stack alignment. +@ +8 for stack canary reference. +#define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed + 8) .macro clobbercheck variant .equ pushed, 4*9 @@ -80,14 +83,37 @@ function checkasm_checked_call_\variant, export=1 .equ pos, pos + 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, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-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, [sp, r12, lsl #2] + mvn r12, r12 + str r12, [sp, #ARG_STACK_A - 4] + mov r12, r0 mov r0, r2 mov r1, r3 ldrd r2, r3, [sp, #ARG_STACK_A + pushed] + @ Call the target function blx r12 - add sp, sp, #ARG_STACK_A + @ Load the number of stack parameters, stack canary and its reference + ldr r12, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-4)] + ldr r2, [sp, r12, lsl #2] + ldr r3, [sp, #ARG_STACK_A - 4] + + add sp, sp, #ARG_STACK_A push {r0, r1} + + mvn r3, r3 + cmp r2, r3 + bne 5f + movrel r12, register_init .ifc \variant, vfp .macro check_reg_vfp, dreg, offset @@ -141,6 +167,9 @@ function checkasm_checked_call_\variant, export=1 .purgem check_reg b 0f +5: + movrel r0, error_message_stack + b 1f 4: movrel r0, error_message_vfp b 1f diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 0a7f9f25c4..254e28f5e2 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -176,8 +176,10 @@ void checkasm_stack_clobber(uint64_t clobber, ...); void checkasm_checked_call_vfp(void *func, int dummy, ...); void checkasm_checked_call_novfp(void *func, int dummy, ...); extern void (*checkasm_checked_call)(void *func, int dummy, ...); -#define declare_new(ret, ...) ret (*checked_call)(void *, int dummy, __VA_ARGS__) = (void *)checkasm_checked_call; -#define call_new(...) checked_call(func_new, 0, __VA_ARGS__) +#define declare_new(ret, ...) ret (*checked_call)(void *, int dummy, __VA_ARGS__, \ + int, int, int, int, int, int, int, int, \ + int, int, int, int, int, int, int) = (void *)checkasm_checked_call; +#define call_new(...) checked_call(func_new, 0, __VA_ARGS__, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0) #elif ARCH_AARCH64 && !defined(__APPLE__) void checkasm_stack_clobber(uint64_t clobber, ...); void checkasm_checked_call(void *func, ...); From patchwork Thu May 14 13:14:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19686 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8517744BB27 for ; Thu, 14 May 2020 16:22:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 69A6168A460; Thu, 14 May 2020 16:22:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 70F3268A452 for ; Thu, 14 May 2020 16:22:16 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id bs4so2360359edb.6 for ; Thu, 14 May 2020 06:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=Y/Np5IE5+/A6coqsbdDC4J6xLnjqDr5HMlJcsTZDMLM=; b=VtgZghd71BsjrX6p4WQAdmbSoyN/q3cVBZ7kHkQUtdd0c2lLL9CrzhubRvZ3BC7AIW 69B5RtHTZRt/KzODvcSJbn5lMXHG0iHLVKmptNjCjJZLI+HOwoCaf7F5qes/yeonkLFM 5zJfCm0kJmQUHB0exXU1lQzlXKnduXcg+jPUOh/lGr9RDoOuEpBswRUYUa5psYAp0GQi Efhyjs9QTVqTVpO/CAYUFdzyAwzLzF9bc04MYzbw5Igk/B+69Hqh3WIGP4pRGYxwzTUa 5qH7IR5CMURiumB+3Tn7O6AOqOTVZ1X1F0PHOEysJ/lpuvHyCOS91vUoha55VobE4GXr 70/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Y/Np5IE5+/A6coqsbdDC4J6xLnjqDr5HMlJcsTZDMLM=; b=JDd8ccK34mGW7tekqesFxEOVeu+zhoF9wrWd9b0RqBGabT9dF881oFAW/G7Bp/LjbX eo3/YwvuYieaSLGUU1N7p1PnFr5f3KAWePF/dk+vvesNfIOakXxMevZyqEY9bQFM6aoZ UhT4/nkU6E1Jt5MjACo0n17O5QZ2+vfIqQ/PhU52cToZbMlj3Tl7wbk2v7l6GvhHWpgw e2zGjVNmpSx+VCTfj0WPW1G/RGVJOg4XUaKYqgRZZM0IbCysrBG97/HZEniFJCoT81Zw wmfyKy54BsI5dUTI2Qp0Ulju9r41/FpfSjz5L9EhS+QGtYkAu8qhhjblFH+bIXaCvpUY gRBQ== X-Gm-Message-State: AOAM530ss7LWVa2exVojfF7eaDCcA4wFwvA7N3m3Tf6ZGsfbEFZsUzY9 ad+6P6t1q7aChEUM956qB+/5CMJZIuU= X-Google-Smtp-Source: ABdhPJzFuzS4bZqY42LSC6PAbAq4j6wmYehtL54opjc1rZ1fLeu9Brp1i0nv66F0xDyBSL75+hthzQ== X-Received: by 2002:ac2:4c3b:: with SMTP id u27mr3270342lfq.212.1589462056165; Thu, 14 May 2020 06:14:16 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id s9sm1305164ljc.43.2020.05.14.06.14.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:14:15 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 16:14:12 +0300 Message-Id: <20200514131412.27655-5-martin@martin.st> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200514131412.27655-1-martin@martin.st> References: <20200514131412.27655-1-martin@martin.st> Subject: [FFmpeg-devel] [PATCH 5/5] checkasm: aarch64: Check for stack overflows X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also fill x8-x17 with garbage before calling the function. Figure out the number of stack parameters and make sure that the value on the stack after those is untouched. --- tests/checkasm/aarch64/checkasm.S | 47 +++++++++++++++++++++++++++++-- tests/checkasm/checkasm.h | 7 +++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/tests/checkasm/aarch64/checkasm.S b/tests/checkasm/aarch64/checkasm.S index 0dbfe8025e..6d3c738801 100644 --- a/tests/checkasm/aarch64/checkasm.S +++ b/tests/checkasm/aarch64/checkasm.S @@ -44,8 +44,10 @@ const register_init, align=4 endconst -const error_message +const error_message_register .asciz "failed to preserve register" +error_message_stack: + .asciz "stack clobbered" endconst @@ -65,7 +67,8 @@ function checkasm_stack_clobber, export=1 ret endfunc -#define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15) +// + 16 for stack canary reference +#define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15 + 16) function checkasm_checked_call, export=1 stp x29, x30, [sp, #-16]! @@ -100,14 +103,48 @@ function checkasm_checked_call, export=1 .equ pos, pos + 8 .endr + // Fill x8-x17 with garbage. This doesn't have to be preserved, + // but avoids relying on them having any particular value. + movrel x9, register_init + ldp x10, x11, [x9], #32 + ldp x12, x13, [x9], #32 + ldp x14, x15, [x9], #32 + ldp x16, x17, [x9], #32 + ldp x8, x9, [x9] + + // 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 w2, [x29, #16 + 8*8 + (MAX_ARGS-8)*8] + // 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 x2, [sp, x2, lsl #3] + mvn x2, x2 + str x2, [sp, #ARG_STACK-8] + + // Load the in-register arguments mov x12, x0 ldp x0, x1, [x29, #16] ldp x2, x3, [x29, #32] ldp x4, x5, [x29, #48] ldp x6, x7, [x29, #64] + // Call the target function blr x12 + + // Load the number of stack parameters, stack canary and its reference + ldr w2, [x29, #16 + 8*8 + (MAX_ARGS-8)*8] + ldr x2, [sp, x2, lsl #3] + ldr x3, [sp, #ARG_STACK-8] + add sp, sp, #ARG_STACK stp x0, x1, [sp, #-16]! + + mvn x3, x3 + cmp x2, x3 + b.ne 2f + movrel x9, register_init movi v3.8h, #0 @@ -139,7 +176,11 @@ function checkasm_checked_call, export=1 cbz x3, 0f - movrel x0, error_message + movrel x0, error_message_register + b 1f +2: + movrel x0, error_message_stack +1: bl X(checkasm_fail_func) 0: ldp x0, x1, [sp], #16 diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 254e28f5e2..e7d47475f6 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -183,12 +183,15 @@ extern void (*checkasm_checked_call)(void *func, int dummy, ...); #elif ARCH_AARCH64 && !defined(__APPLE__) void checkasm_stack_clobber(uint64_t clobber, ...); void checkasm_checked_call(void *func, ...); -#define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, int, int, __VA_ARGS__)\ +#define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, int, int, __VA_ARGS__,\ + int, int, int, int, int, int, int, int,\ + int, int, int, int, int, int, int)\ = (void *)checkasm_checked_call; #define CLOB (UINT64_C(0xdeadbeefdeadbeef)) #define call_new(...) (checkasm_stack_clobber(CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,\ CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB),\ - checked_call(func_new, 0, 0, 0, 0, 0, 0, 0, __VA_ARGS__)) + checked_call(func_new, 0, 0, 0, 0, 0, 0, 0, __VA_ARGS__,\ + 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0)) #else #define declare_new(ret, ...) #define declare_new_float(ret, ...)