Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2019 ARM Limited */
0003 
0004 #include <asm/unistd.h>
0005 
0006 .section        .rodata, "a"
0007 call_fmt:
0008     .asciz "Calling sigreturn with fake sigframe sized:%zd at SP @%08lX\n"
0009 
0010 .text
0011 
0012 .globl fake_sigreturn
0013 
0014 /*  fake_sigreturn  x0:&sigframe,  x1:sigframe_size,  x2:misalign_bytes */
0015 fake_sigreturn:
0016     stp x29, x30, [sp, #-16]!
0017     mov x29, sp
0018 
0019     mov x20, x0
0020     mov x21, x1
0021     mov x22, x2
0022 
0023     /* create space on the stack for fake sigframe 16 bytes-aligned */
0024     add x0, x21, x22
0025     add x0, x0, #15
0026     bic x0, x0, #15 /* round_up(sigframe_size + misalign_bytes, 16) */
0027     sub sp, sp, x0
0028     add x23, sp, x22 /* new sigframe base with misaligment if any */
0029 
0030     ldr x0, =call_fmt
0031     mov x1, x21
0032     mov x2, x23
0033     bl  printf
0034 
0035     /* memcpy the provided content, while still keeping SP aligned */
0036     mov x0, x23
0037     mov x1, x20
0038     mov x2, x21
0039     bl  memcpy
0040 
0041     /*
0042      * Here saving a last minute SP to current->token acts as a marker:
0043      * if we got here, we are successfully faking a sigreturn; in other
0044      * words we are sure no bad fatal signal has been raised till now
0045      * for unrelated reasons, so we should consider the possibly observed
0046      * fatal signal like SEGV coming from Kernel restore_sigframe() and
0047      * triggered as expected from our test-case.
0048      * For simplicity this assumes that current field 'token' is laid out
0049      * as first in struct tdescr
0050      */
0051     ldr x0, current
0052     str x23, [x0]
0053     /* finally move SP to misaligned address...if any requested */
0054     mov sp, x23
0055 
0056     mov x8, #__NR_rt_sigreturn
0057     svc #0
0058 
0059     /*
0060      * Above sigreturn should not return...looping here leads to a timeout
0061      * and ensure proper and clean test failure, instead of jumping around
0062      * on a potentially corrupted stack.
0063      */
0064     b   .