__stack_chk_fail.c 807 B

12345678910111213141516171819202122232425262728293031
  1. #include <string.h>
  2. #include <stdint.h>
  3. #include "pthread_impl.h"
  4. uintptr_t __stack_chk_guard;
  5. void __init_ssp(void *entropy)
  6. {
  7. if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
  8. else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
  9. #if UINTPTR_MAX >= 0xffffffffffffffff
  10. /* Sacrifice 8 bits of entropy on 64bit to prevent leaking/
  11. * overwriting the canary via string-manipulation functions.
  12. * The NULL byte is on the second byte so that off-by-ones can
  13. * still be detected. Endianness is taken care of
  14. * automatically. */
  15. ((char *)&__stack_chk_guard)[1] = 0;
  16. #endif
  17. __pthread_self()->canary = __stack_chk_guard;
  18. }
  19. void __stack_chk_fail(void)
  20. {
  21. a_crash();
  22. }
  23. hidden void __stack_chk_fail_local(void);
  24. weak_alias(__stack_chk_fail, __stack_chk_fail_local);