1 /* Pointer obfuscation implenentation. LoongArch version.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef POINTER_GUARD_H
20 #define POINTER_GUARD_H
22 /* Load a got-relative EXPR into register G. */
23 #define LD_GLOBAL(G, EXPR) \
27 /* Load a pc-relative EXPR into register G. */
28 #define LD_PCREL(G, EXPR) \
29 pcalau12i G, %pc_hi20(EXPR); \
30 REG_L G, G, %pc_lo12(EXPR);
33 || (!defined SHARED && (IS_IN (libc) \
34 || IS_IN (libpthread))))
37 #define PTR_MANGLE(dst, src, guard) \
38 LD_PCREL (guard, __pointer_chk_guard_local); \
39 PTR_MANGLE2 (dst, src, guard);
40 #define PTR_DEMANGLE(dst, src, guard) \
41 LD_PCREL (guard, __pointer_chk_guard_local); \
42 PTR_DEMANGLE2 (dst, src, guard);
43 /* Use PTR_MANGLE2 for efficiency if guard is already loaded. */
44 #define PTR_MANGLE2(dst, src, guard) \
46 #define PTR_DEMANGLE2(dst, src, guard) \
47 PTR_MANGLE2 (dst, src, guard);
50 extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden
;
51 #define PTR_MANGLE(var) \
52 (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
53 #define PTR_DEMANGLE(var) PTR_MANGLE (var)
59 #define PTR_MANGLE(dst, src, guard) \
60 LD_GLOBAL (guard, __pointer_chk_guard); \
61 PTR_MANGLE2 (dst, src, guard);
62 #define PTR_DEMANGLE(dst, src, guard) \
63 LD_GLOBAL (guard, __pointer_chk_guard); \
64 PTR_DEMANGLE2 (dst, src, guard);
65 /* Use PTR_MANGLE2 for efficiency if guard is already loaded. */
66 #define PTR_MANGLE2(dst, src, guard) \
68 #define PTR_DEMANGLE2(dst, src, guard) \
69 PTR_MANGLE2 (dst, src, guard);
72 extern uintptr_t __pointer_chk_guard attribute_relro
;
73 #define PTR_MANGLE(var) \
74 (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
75 #define PTR_DEMANGLE(var) PTR_MANGLE (var)
80 #endif /* POINTER_GUARD_H */