dl-osinfo.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include <stdint.h>
  11. #include <sys/time.h>
  12. #ifdef IS_IN_libc
  13. #include <ssp-internal.h>
  14. #if 0
  15. #ifndef __SSP_QUICK_CANARY__
  16. #define OPEN __libc_open
  17. #define READ __libc_read
  18. #define CLOSE __libc_close
  19. #endif
  20. #define GETTIMEOFDAY gettimeofday
  21. #endif
  22. #else
  23. #ifndef __SSP_QUICK_CANARY__
  24. #define OPEN _dl_open
  25. #define READ _dl_read
  26. #define CLOSE _dl_close
  27. #endif
  28. #define GETTIMEOFDAY _dl_gettimeofday
  29. #endif
  30. static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
  31. {
  32. uintptr_t ret;
  33. #ifndef __SSP_QUICK_CANARY__
  34. {
  35. int fd = OPEN("/dev/urandom", O_RDONLY, 0);
  36. if (fd >= 0) {
  37. size_t size = READ(fd, &ret, sizeof(ret));
  38. CLOSE(fd);
  39. if (size == (size_t) sizeof(ret))
  40. return ret;
  41. }
  42. }
  43. #endif /* !__SSP_QUICK_CANARY__ */
  44. /* Start with the "terminator canary". */
  45. ret = 0xFF0A0D00UL;
  46. /* Everything failed? Or we are using a weakened model of the
  47. * terminator canary */
  48. {
  49. struct timeval tv;
  50. if (GETTIMEOFDAY(&tv, NULL) != (-1))
  51. ret ^= tv.tv_usec ^ tv.tv_sec;
  52. }
  53. return ret;
  54. }
  55. #endif /* __UCLIBC_HAS_SSP__ */
  56. #endif /* _DL_OSINFO_H */