dl-osinfo.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #ifndef _DL_OSINFO_H
  7. #define _DL_OSINFO_H 1
  8. #include <features.h>
  9. #ifdef __UCLIBC_HAS_SSP__
  10. # if defined IS_IN_libc || defined IS_IN_rtld
  11. # if defined __SSP__ || defined __SSP_ALL__
  12. # error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
  13. # endif
  14. # include <stdint.h>
  15. # include <sys/time.h>
  16. # ifdef IS_IN_libc
  17. # ifndef __SSP_QUICK_CANARY__
  18. # define OPEN __open
  19. # define READ __read
  20. # define CLOSE __close
  21. # endif
  22. # define GETTIMEOFDAY gettimeofday
  23. # else
  24. # ifndef __SSP_QUICK_CANARY__
  25. # define OPEN _dl_open
  26. # define READ _dl_read
  27. # define CLOSE _dl_close
  28. # endif
  29. # define GETTIMEOFDAY _dl_gettimeofday
  30. # endif
  31. static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
  32. {
  33. uintptr_t ret;
  34. # ifndef __SSP_QUICK_CANARY__
  35. {
  36. int fd = OPEN("/dev/urandom", O_RDONLY, 0);
  37. if (fd >= 0) {
  38. size_t size = READ(fd, &ret, sizeof(ret));
  39. CLOSE(fd);
  40. if (size == (size_t) sizeof(ret))
  41. return ret;
  42. }
  43. }
  44. # endif /* !__SSP_QUICK_CANARY__ */
  45. /* Start with the "terminator canary". */
  46. ret = 0xFF0A0D00UL;
  47. /* Everything failed? Or we are using a weakened model of the
  48. * terminator canary */
  49. {
  50. struct timeval tv;
  51. if (GETTIMEOFDAY(&tv, NULL) != (-1))
  52. ret ^= tv.tv_usec ^ tv.tv_sec;
  53. }
  54. return ret;
  55. }
  56. # endif /* libc || rtld */
  57. #endif /* __UCLIBC_HAS_SSP__ */
  58. #endif /* _DL_OSINFO_H */