aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libunwind/src/cet_unwind.h
blob: 9a548151b385a38b675751823fff4ed7a5cbe6be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//===----------------------------------------------------------------------===// 
// 
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 
// See https://llvm.org/LICENSE.txt for license information. 
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 
// 
// 
//===----------------------------------------------------------------------===// 
 
#ifndef LIBUNWIND_CET_UNWIND_H 
#define LIBUNWIND_CET_UNWIND_H 
 
#include "libunwind.h" 
 
// Currently, CET is implemented on Linux x86 platforms. 
#if defined(_LIBUNWIND_TARGET_LINUX) && defined(__CET__) && defined(__SHSTK__) 
#define _LIBUNWIND_USE_CET 1 
#endif 
 
#if defined(_LIBUNWIND_USE_CET) 
#include <cet.h> 
#include <immintrin.h> 
 
#define _LIBUNWIND_POP_CET_SSP(x)                                              \ 
  do {                                                                         \ 
    unsigned long ssp = _get_ssp();                                            \ 
    if (ssp != 0) {                                                            \ 
      unsigned int tmp = (x);                                                  \ 
      while (tmp > 255) {                                                      \ 
        _inc_ssp(255);                                                         \ 
        tmp -= 255;                                                            \ 
      }                                                                        \ 
      _inc_ssp(tmp);                                                           \ 
    }                                                                          \ 
  } while (0) 
#endif 
 
extern void *__libunwind_cet_get_registers(unw_cursor_t *); 
extern void *__libunwind_cet_get_jump_target(); 
 
#endif