dl-osinfo.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Operating system specific code for generic dynamic loader functions.
  2. Copyright (C) 2009-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <endian.h>
  16. #include <stdint.h>
  17. static inline uintptr_t __attribute__ ((always_inline))
  18. _dl_setup_stack_chk_guard (void *dl_random)
  19. {
  20. union
  21. {
  22. uintptr_t num;
  23. unsigned char bytes[sizeof (uintptr_t)];
  24. } ret = { 0 };
  25. if (dl_random == NULL)
  26. {
  27. ret.bytes[sizeof (ret) - 1] = 255;
  28. ret.bytes[sizeof (ret) - 2] = '\n';
  29. }
  30. else
  31. {
  32. memcpy (ret.bytes, dl_random, sizeof (ret));
  33. #if BYTE_ORDER == LITTLE_ENDIAN
  34. ret.num &= ~(uintptr_t) 0xff;
  35. #elif BYTE_ORDER == BIG_ENDIAN
  36. ret.num &= ~((uintptr_t) 0xff << (8 * (sizeof (ret) - 1)));
  37. #else
  38. # error "BYTE_ORDER unknown"
  39. #endif
  40. }
  41. return ret.num;
  42. }
  43. static inline uintptr_t __attribute__ ((always_inline))
  44. _dl_setup_pointer_guard (void *dl_random, uintptr_t stack_chk_guard)
  45. {
  46. uintptr_t ret;
  47. if (dl_random == NULL)
  48. ret = stack_chk_guard;
  49. else
  50. memcpy (&ret, (char *) dl_random + sizeof (ret), sizeof (ret));
  51. return ret;
  52. }