64 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//8//===----------------------------------------------------------------------===//9 10#ifndef LIBUNWIND_SHADOW_STACK_UNWIND_H11#define LIBUNWIND_SHADOW_STACK_UNWIND_H12 13#include "libunwind.h"14 15// Currently, CET is implemented on some ELF x86 platforms.16#if defined(__CET__) && defined(__SHSTK__)17#define _LIBUNWIND_USE_CET 118#endif19 20#if defined(_LIBUNWIND_USE_CET)21#include <cet.h>22#include <immintrin.h>23 24#define _LIBUNWIND_POP_SHSTK_SSP(x) \25 do { \26 unsigned long ssp = _get_ssp(); \27 if (ssp != 0) { \28 unsigned int tmp = (x); \29 while (tmp > 255) { \30 _inc_ssp(255); \31 tmp -= 255; \32 } \33 _inc_ssp(tmp); \34 } \35 } while (0)36#endif37 38// On AArch64 we use _LIBUNWIND_USE_GCS to indicate that GCS is supported. We39// need to guard any use of GCS instructions with __chkfeat though, as GCS may40// not be enabled.41#if defined(_LIBUNWIND_TARGET_AARCH64) && defined(__ARM_FEATURE_GCS_DEFAULT)42#include <arm_acle.h>43 44// We can only use GCS if arm_acle.h defines the GCS intrinsics.45#ifdef _CHKFEAT_GCS46#define _LIBUNWIND_USE_GCS 147#endif48 49#define _LIBUNWIND_POP_SHSTK_SSP(x) \50 do { \51 if (__chkfeat(_CHKFEAT_GCS)) { \52 unsigned tmp = (x); \53 while (tmp--) \54 __gcspopm(); \55 } \56 } while (0)57 58#endif59 60extern void *__libunwind_shstk_get_registers(unw_cursor_t *);61extern void *__libunwind_shstk_get_jump_target(void);62 63#endif64