dl-osinfo.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <fcntl.h>
  18. libc_hidden_proto(open)
  19. libc_hidden_proto(read)
  20. libc_hidden_proto(close)
  21. libc_hidden_proto(gettimeofday)
  22. # define OPEN open
  23. # define READ read
  24. # define CLOSE close
  25. # define GETTIMEOFDAY gettimeofday
  26. # else
  27. # define OPEN _dl_open
  28. # define READ _dl_read
  29. # define CLOSE _dl_close
  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 */