signals.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2019 ARM Limited */
  3. #include <asm/unistd.h>
  4. .section .rodata, "a"
  5. call_fmt:
  6. .asciz "Calling sigreturn with fake sigframe sized:%zd at SP @%08lX\n"
  7. .text
  8. .globl fake_sigreturn
  9. /* fake_sigreturn x0:&sigframe, x1:sigframe_size, x2:misalign_bytes */
  10. fake_sigreturn:
  11. stp x29, x30, [sp, #-16]!
  12. mov x29, sp
  13. mov x20, x0
  14. mov x21, x1
  15. mov x22, x2
  16. /* create space on the stack for fake sigframe 16 bytes-aligned */
  17. add x0, x21, x22
  18. add x0, x0, #15
  19. bic x0, x0, #15 /* round_up(sigframe_size + misalign_bytes, 16) */
  20. sub sp, sp, x0
  21. add x23, sp, x22 /* new sigframe base with misaligment if any */
  22. ldr x0, =call_fmt
  23. mov x1, x21
  24. mov x2, x23
  25. bl printf
  26. /* memcpy the provided content, while still keeping SP aligned */
  27. mov x0, x23
  28. mov x1, x20
  29. mov x2, x21
  30. bl memcpy
  31. /*
  32. * Here saving a last minute SP to current->token acts as a marker:
  33. * if we got here, we are successfully faking a sigreturn; in other
  34. * words we are sure no bad fatal signal has been raised till now
  35. * for unrelated reasons, so we should consider the possibly observed
  36. * fatal signal like SEGV coming from Kernel restore_sigframe() and
  37. * triggered as expected from our test-case.
  38. * For simplicity this assumes that current field 'token' is laid out
  39. * as first in struct tdescr
  40. */
  41. ldr x0, current
  42. str x23, [x0]
  43. /* finally move SP to misaligned address...if any requested */
  44. mov sp, x23
  45. mov x8, #__NR_rt_sigreturn
  46. svc #0
  47. /*
  48. * Above sigreturn should not return...looping here leads to a timeout
  49. * and ensure proper and clean test failure, instead of jumping around
  50. * on a potentially corrupted stack.
  51. */
  52. b .