Path: blob/master/tools/testing/selftests/arm64/signal/signals.S
26292 views
/* SPDX-License-Identifier: GPL-2.0 */1/* Copyright (C) 2019 ARM Limited */23#include <asm/unistd.h>45.section .rodata, "a"6call_fmt:7.asciz "Calling sigreturn with fake sigframe sized:%zd at SP @%08lX\n"89.text1011.globl fake_sigreturn1213/* fake_sigreturn x0:&sigframe, x1:sigframe_size, x2:misalign_bytes */14fake_sigreturn:15stp x29, x30, [sp, #-16]!16mov x29, sp1718mov x20, x019mov x21, x120mov x22, x22122/* create space on the stack for fake sigframe 16 bytes-aligned */23add x0, x21, x2224add x0, x0, #1525bic x0, x0, #15 /* round_up(sigframe_size + misalign_bytes, 16) */26sub sp, sp, x027add x23, sp, x22 /* new sigframe base with misaligment if any */2829ldr x0, =call_fmt30mov x1, x2131mov x2, x2332bl printf3334/* memcpy the provided content, while still keeping SP aligned */35mov x0, x2336mov x1, x2037mov x2, x2138bl memcpy3940/*41* Here saving a last minute SP to current->token acts as a marker:42* if we got here, we are successfully faking a sigreturn; in other43* words we are sure no bad fatal signal has been raised till now44* for unrelated reasons, so we should consider the possibly observed45* fatal signal like SEGV coming from Kernel restore_sigframe() and46* triggered as expected from our test-case.47* For simplicity this assumes that current field 'token' is laid out48* as first in struct tdescr49*/50ldr x0, current51str x23, [x0]52/* finally move SP to misaligned address...if any requested */53mov sp, x235455mov x8, #__NR_rt_sigreturn56svc #05758/*59* Above sigreturn should not return...looping here leads to a timeout60* and ensure proper and clean test failure, instead of jumping around61* on a potentially corrupted stack.62*/63b .646566