0002-util-cacheinfo-fix-crash-when-compiling-with-uClibc.patch 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From d82b8540ecaf3cb09a033e4971d8645d3343211e Mon Sep 17 00:00:00 2001
  2. From: Carlos Santos <casantos@redhat.com>
  3. Date: Wed, 16 Oct 2019 22:27:30 -0300
  4. Subject: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
  5. uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
  6. but the corresponding sysconf calls returns -1, which is a valid result,
  7. meaning that the limit is indeterminate.
  8. Handle this situation using the fallback values instead of crashing due
  9. to an assertion failure.
  10. Signed-off-by: Carlos Santos <casantos@redhat.com>
  11. ---
  12. util/cacheinfo.c | 10 ++++++++--
  13. 1 file changed, 8 insertions(+), 2 deletions(-)
  14. diff --git a/util/cacheinfo.c b/util/cacheinfo.c
  15. index ea6f3e99bf..d94dc6adc8 100644
  16. --- a/util/cacheinfo.c
  17. +++ b/util/cacheinfo.c
  18. @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
  19. static void sys_cache_info(int *isize, int *dsize)
  20. {
  21. # ifdef _SC_LEVEL1_ICACHE_LINESIZE
  22. - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
  23. + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
  24. + if (tmp_isize > 0) {
  25. + *isize = tmp_isize;
  26. + }
  27. # endif
  28. # ifdef _SC_LEVEL1_DCACHE_LINESIZE
  29. - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
  30. + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
  31. + if (tmp_dsize > 0) {
  32. + *dsize = tmp_dsize;
  33. + }
  34. # endif
  35. }
  36. #endif /* sys_cache_info */
  37. --
  38. 2.18.1