dl-osinfo.h 1.4 KB

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