[libunwind] Support stack unwind in CET environment
authorgejin <ge.jin@intel.com>
Thu, 26 Aug 2021 08:20:38 +0000 (16:20 +0800)
committergejin <ge.jin@intel.com>
Thu, 26 Aug 2021 08:20:38 +0000 (16:20 +0800)
commit21b25a1fb32ecd2e1f336123c2715f8ef1a49f97
tree579b8628fe5a573f1852e82d0e298b694aea3000
parent9016b2a1cae244eb8f26826427eeb90eded0da20
[libunwind] Support stack unwind in CET environment

Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.

Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968

Signed-off-by: gejin <ge.jin@intel.com>
13 files changed:
libunwind/CMakeLists.txt
libunwind/src/CMakeLists.txt
libunwind/src/Registers.hpp
libunwind/src/UnwindCursor.hpp
libunwind/src/UnwindLevel1.c
libunwind/src/UnwindRegistersRestore.S
libunwind/src/UnwindRegistersSave.S
libunwind/src/assembly.h
libunwind/src/cet_unwind.h [new file with mode: 0644]
libunwind/src/libunwind.cpp
libunwind/test/CMakeLists.txt
libunwind/test/libunwind/test/config.py
libunwind/test/lit.site.cfg.in