dl-osinfo.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifdef __SSP__
  24. #error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
  25. #endif
  26. #ifndef __SSP_QUICK_CANARY__
  27. #define OPEN _dl_open
  28. #define READ _dl_read
  29. #define CLOSE _dl_close
  30. #endif
  31. #define GETTIMEOFDAY _dl_gettimeofday
  32. #endif
  33. static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
  34. {
  35. uintptr_t ret;
  36. #ifndef __SSP_QUICK_CANARY__
  37. {
  38. int fd = OPEN("/dev/urandom", O_RDONLY, 0);
  39. if (fd >= 0) {
  40. size_t size = READ(fd, &ret, sizeof(ret));
  41. CLOSE(fd);
  42. if (size == (size_t) sizeof(ret))
  43. return ret;
  44. }
  45. }
  46. #endif /* !__SSP_QUICK_CANARY__ */
  47. /* Start with the "terminator canary". */
  48. ret = 0xFF0A0D00UL;
  49. /* Everything failed? Or we are using a weakened model of the
  50. * terminator canary */
  51. {
  52. struct timeval tv;
  53. if (GETTIMEOFDAY(&tv, NULL) != (-1))
  54. ret ^= tv.tv_usec ^ tv.tv_sec;
  55. }
  56. return ret;
  57. }
  58. #endif /* __UCLIBC_HAS_SSP__ */
  59. #endif /* _DL_OSINFO_H */