]>
Commit | Line | Data |
---|---|---|
88f4b692 | 1 | /* Pointer guard implementation. Alpha version. |
dff8da6b | 2 | Copyright (C) 2006-2024 Free Software Foundation, Inc. |
88f4b692 FW |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library. If not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #ifndef POINTER_GUARD_H | |
20 | #define POINTER_GUARD_H | |
21 | ||
22 | /* Pointer mangling support. Note that tls access is slow enough that | |
23 | we don't deoptimize things by placing the pointer check value there. */ | |
24 | ||
25 | #ifdef __ASSEMBLER__ | |
26 | # if IS_IN (rtld) | |
27 | # define PTR_MANGLE(dst, src, tmp) \ | |
28 | ldah tmp, __pointer_chk_guard_local($29) !gprelhigh; \ | |
29 | ldq tmp, __pointer_chk_guard_local(tmp) !gprellow; \ | |
30 | xor src, tmp, dst | |
31 | # define PTR_MANGLE2(dst, src, tmp) \ | |
32 | xor src, tmp, dst | |
33 | # elif defined SHARED | |
34 | # define PTR_MANGLE(dst, src, tmp) \ | |
35 | ldq tmp, __pointer_chk_guard; \ | |
36 | xor src, tmp, dst | |
37 | # else | |
38 | # define PTR_MANGLE(dst, src, tmp) \ | |
39 | ldq tmp, __pointer_chk_guard_local; \ | |
40 | xor src, tmp, dst | |
41 | # endif | |
42 | # define PTR_MANGLE2(dst, src, tmp) \ | |
43 | xor src, tmp, dst | |
44 | # define PTR_DEMANGLE(dst, tmp) PTR_MANGLE(dst, dst, tmp) | |
45 | # define PTR_DEMANGLE2(dst, tmp) PTR_MANGLE2(dst, dst, tmp) | |
46 | #else | |
47 | # include <stdint.h> | |
48 | # if (IS_IN (rtld) \ | |
49 | || (!defined SHARED && (IS_IN (libc) \ | |
50 | || IS_IN (libpthread)))) | |
51 | extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden; | |
52 | # define PTR_MANGLE(var) \ | |
53 | (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local) | |
54 | # else | |
55 | extern uintptr_t __pointer_chk_guard attribute_relro; | |
56 | # define PTR_MANGLE(var) \ | |
57 | (var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard) | |
58 | # endif | |
59 | # define PTR_DEMANGLE(var) PTR_MANGLE(var) | |
60 | #endif /* ASSEMBLER */ | |
61 | ||
62 | #endif /* POINTER_GUARD_H */ |