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 #ifndef _SSPRET_H 17 #define _SSPRET_H 18 19 #if defined(__SSP_RET_STRONG__) || defined(__SSP_RET_ALL__) 20 #if defined(__aarch64__) 21 # define SSPRET_CALC_RETCOOKIE(reg) \ 22 eor reg, reg, x30 23 24 # define SSPRET_LOAD_COOKIE(x, reg) \ 25 mov reg, x29 26 27 # define SSPRET_SETUP(x, reg) \ 28 SSPRET_LOAD_COOKIE(x, reg); \ 29 SSPRET_CALC_RETCOOKIE(reg) 30 31 # define SSPRET_CHECK(x, reg) \ 32 SSPRET_LOAD_COOKIE(x, x9); \ 33 SSPRET_CALC_RETCOOKIE(x9); \ 34 subs reg, reg, x9; \ 35 cbz reg, 6788f; \ 36 brk #0x1; \ 37 6788: 38 39 # define SSPRET_PUSH(reg) \ 40 str reg, [sp, #-16]! 41 42 # define SSPRET_POP(reg) \ 43 ldr reg, [sp, #16]! 44 45 #endif /* __aarch64__ */ 46 #else 47 # define SSPRET_CALC_RETCOOKIE(reg) 48 # define SSPRET_LOAD_COOKIE(x, reg) 49 # define SSPRET_SETUP(x, reg) 50 # define SSPRET_CHECK(x, reg) 51 # define SSPRET_PUSH(reg) 52 # define SSPRET_POP(reg) 53 #endif /* __SSP_RET_STRONG__ || __SSP_RET_ALL__ */ 54 55 #endif /* _SSPRET_H */ 56