(root)/
glibc-2.38/
sysdeps/
arm/
pointer_guard.h
       1  /* Pointer guard implementation.  Arm version.
       2     Copyright (C) 2013-2023 Free Software Foundation, Inc.
       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.  */
      23  #if (IS_IN (rtld) \
      24       || (!defined SHARED && (IS_IN (libc) || IS_IN (libpthread))))
      25  # ifdef __ASSEMBLER__
      26  #  define PTR_MANGLE_LOAD(guard, tmp)                                   \
      27    LDR_HIDDEN (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local), 0)
      28  #  define PTR_MANGLE(dst, src, guard, tmp)                              \
      29    PTR_MANGLE_LOAD(guard, tmp);                                          \
      30    PTR_MANGLE2(dst, src, guard)
      31  /* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
      32  #  define PTR_MANGLE2(dst, src, guard)          \
      33    eor dst, src, guard
      34  #  define PTR_DEMANGLE(dst, src, guard, tmp)    \
      35    PTR_MANGLE (dst, src, guard, tmp)
      36  #  define PTR_DEMANGLE2(dst, src, guard)        \
      37    PTR_MANGLE2 (dst, src, guard)
      38  # else
      39  extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
      40  #  define PTR_MANGLE(var) \
      41    (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
      42  #  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
      43  # endif
      44  #else
      45  # ifdef __ASSEMBLER__
      46  #  define PTR_MANGLE_LOAD(guard, tmp)                                   \
      47    LDR_GLOBAL (guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard), 0);
      48  #  define PTR_MANGLE(dst, src, guard, tmp)                              \
      49    PTR_MANGLE_LOAD(guard, tmp);                                          \
      50    PTR_MANGLE2(dst, src, guard)
      51  /* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
      52  #  define PTR_MANGLE2(dst, src, guard)          \
      53    eor dst, src, guard
      54  #  define PTR_DEMANGLE(dst, src, guard, tmp)    \
      55    PTR_MANGLE (dst, src, guard, tmp)
      56  #  define PTR_DEMANGLE2(dst, src, guard)        \
      57    PTR_MANGLE2 (dst, src, guard)
      58  # else
      59  #  include <stdint.h>
      60  extern uintptr_t __pointer_chk_guard attribute_relro;
      61  #  define PTR_MANGLE(var) \
      62    (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
      63  #  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
      64  # endif
      65  #endif
      66  
      67  #endif /* POINTER_GUARD_H */