• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 
17 #ifndef _SSPRET_H
18 #define _SSPRET_H
19 
20 #if defined(__SSP_RET_STRONG__) || defined(__SSP_RET_ALL__)
21 #if defined(__aarch64__)
22 # define SSPRET_CALC_RETCOOKIE(reg) \
23     eor     reg, reg, x30
24 
25 # define SSPRET_LOAD_COOKIE(x, reg) \
26     mov     reg, x29
27 
28 # define SSPRET_SETUP(x, reg) \
29     SSPRET_LOAD_COOKIE(x, reg); \
30     SSPRET_CALC_RETCOOKIE(reg)
31 
32 # define SSPRET_CHECK(x, reg) \
33     SSPRET_LOAD_COOKIE(x, x9); \
34     SSPRET_CALC_RETCOOKIE(x9); \
35     subs    reg, reg, x9; \
36     cbz     reg, 6788f; \
37     brk     #0x1; \
38 6788:
39 
40 # define SSPRET_PUSH(reg) \
41     str     reg, [sp, #-16]!
42 
43 # define SSPRET_POP(reg) \
44     ldr     reg, [sp, #16]!
45 
46 #endif /* __aarch64__ */
47 #else
48 # define SSPRET_CALC_RETCOOKIE(reg)
49 # define SSPRET_LOAD_COOKIE(x, reg)
50 # define SSPRET_SETUP(x, reg)
51 # define SSPRET_CHECK(x, reg)
52 # define SSPRET_PUSH(reg)
53 # define SSPRET_POP(reg)
54 #endif /* __SSP_RET_STRONG__ || __SSP_RET_ALL__ */
55 
56 #endif /* _SSPRET_H */
57