dl-osinfo.h 1.5 KB

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