0001-folly-Use-SYS_futex-for-syscall.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From ddcc8a9f7e0f0bfee96f2f0a0c10f21f9fa9b05d Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Sun, 15 Nov 2020 15:02:28 -0800
  4. Subject: [PATCH] folly: Use SYS_futex for syscall
  5. glibc defines SYS_futex and on newer 32bit CPUs like RISCV-32, arc there
  6. is no 32bit time_t therefore define SYS_futex in terms of SYS_futex_time64
  7. Upstream-Status: Submitted [https://github.com/facebook/rocksdb/pull/7676]
  8. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  9. ---
  10. third-party/folly/folly/detail/Futex.cpp | 10 ++++++++--
  11. 1 file changed, 8 insertions(+), 2 deletions(-)
  12. diff --git a/third-party/folly/folly/detail/Futex.cpp b/third-party/folly/folly/detail/Futex.cpp
  13. index 62d6ea2b2..a914a8c73 100644
  14. --- a/third-party/folly/folly/detail/Futex.cpp
  15. +++ b/third-party/folly/folly/detail/Futex.cpp
  16. @@ -48,9 +48,15 @@ namespace {
  17. #define FUTEX_CLOCK_REALTIME 256
  18. #endif
  19. +/// Newer 32bit CPUs eg. RISCV-32 are defaulting to 64bit time_t from get go and
  20. +/// therefore do not define __NR_futex
  21. +#if !defined(SYS_futex) && defined(SYS_futex_time64)
  22. +# define SYS_futex SYS_futex_time64
  23. +#endif
  24. +
  25. int nativeFutexWake(const void* addr, int count, uint32_t wakeMask) {
  26. long rv = syscall(
  27. - __NR_futex,
  28. + SYS_futex,
  29. addr, /* addr1 */
  30. FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG, /* op */
  31. count, /* val */
  32. @@ -112,7 +118,7 @@ FutexResult nativeFutexWaitImpl(
  33. // Unlike FUTEX_WAIT, FUTEX_WAIT_BITSET requires an absolute timeout
  34. // value - http://locklessinc.com/articles/futex_cheat_sheet/
  35. long rv = syscall(
  36. - __NR_futex,
  37. + SYS_futex,
  38. addr, /* addr1 */
  39. op, /* op */
  40. expected, /* val */
  41. --
  42. 2.29.2