@@ -2969,31 +2969,31 @@ bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
2969
2969
#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
2970
2970
template <typename A, typename R>
2971
2971
bool UnwindCursor<A, R>::isReadableAddr(const pint_t addr) const {
2972
- // This code is heavily based on Abseil's 'address_is_readable.cc',
2973
- // which is Copyright Abseil Authors (2017).
2972
+ // We use SYS_rt_sigprocmask, inspired by Abseil's AddressIsReadable.
2974
2973
2975
2974
const auto sigsetAddr = reinterpret_cast <sigset_t *>(addr);
2976
2975
// We have to check that addr is nullptr because sigprocmask allows that
2977
2976
// as an argument without failure.
2978
2977
if (!sigsetAddr)
2979
2978
return false ;
2979
+ const auto saveErrno = errno;
2980
2980
// We MUST use a raw syscall here, as wrappers may try to access
2981
2981
// sigsetAddr which may cause a SIGSEGV. A raw syscall however is
2982
2982
// safe. Additionally, we need to pass the kernel_sigset_size, which is
2983
2983
// different from libc sizeof(sigset_t). For the majority of architectures,
2984
2984
// it's 64 bits (_NSIG), and libc NSIG is _NSIG + 1.
2985
2985
const auto kernelSigsetSize = NSIG / 8 ;
2986
- const int Result = syscall (SYS_rt_sigprocmask, /* how=*/ ~0 , sigsetAddr,
2987
- nullptr , kernelSigsetSize);
2988
- (void )Result;
2986
+ [[maybe_unused]] const int Result = syscall (
2987
+ SYS_rt_sigprocmask, /* how=*/ ~0 , sigsetAddr, nullptr , kernelSigsetSize);
2989
2988
// Because our "how" is invalid, this syscall should always fail, and our
2990
- // errno should always be EINVAL or an EFAULT. EFAULT is not guaranteed
2991
- // by the POSIX standard. Additionally, this relies on the Linux kernel
2992
- // to check copy_from_user before checking if the "how" argument is
2989
+ // errno should always be EINVAL or an EFAULT. This relies on the Linux
2990
+ // kernel to check copy_from_user before checking if the "how" argument is
2993
2991
// invalid.
2994
2992
assert (Result == -1 );
2995
2993
assert (errno == EFAULT || errno == EINVAL);
2996
- return errno != EFAULT;
2994
+ const auto readable = errno != EFAULT;
2995
+ errno = saveErrno;
2996
+ return readable;
2997
2997
}
2998
2998
#endif
2999
2999
0 commit comments