dl-osinfo.h 1.5 KB

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