Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:31

0001 // Copyright Antony Polukhin, 2016-2023.
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See
0004 // accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_STACKTRACE_DETAIL_SAFE_DUMP_POSIX_IPP
0008 #define BOOST_STACKTRACE_DETAIL_SAFE_DUMP_POSIX_IPP
0009 
0010 #include <boost/config.hpp>
0011 #ifdef BOOST_HAS_PRAGMA_ONCE
0012 #   pragma once
0013 #endif
0014 
0015 #include <boost/stacktrace/safe_dump_to.hpp>
0016 
0017 #include <unistd.h>     // ::write
0018 #include <fcntl.h>      // ::open
0019 #include <sys/stat.h>   // S_IWUSR and friends
0020 
0021 
0022 namespace boost { namespace stacktrace { namespace detail {
0023 
0024 std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
0025     // We do not retry, because this function must be typically called from signal handler so it's:
0026     //  * to scary to continue in case of EINTR
0027     //  * EAGAIN or EWOULDBLOCK may occur only in case of O_NONBLOCK is set for fd,
0028     // so it seems that user does not want to block
0029     if (::write(fd, frames, sizeof(native_frame_ptr_t) * frames_count) == -1) {
0030         return 0;
0031     }
0032 
0033     return frames_count;
0034 }
0035 
0036 std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
0037     const int fd = ::open(
0038         file,
0039         O_CREAT | O_WRONLY | O_TRUNC,
0040 #if defined(S_IWUSR) && defined(S_IRUSR)    // Workarounds for some Android OSes
0041         S_IWUSR | S_IRUSR
0042 #elif defined(S_IWRITE) && defined(S_IREAD)
0043         S_IWRITE | S_IREAD
0044 #else
0045         0
0046 #endif
0047     );
0048     if (fd == -1) {
0049         return 0;
0050     }
0051 
0052     const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
0053     ::close(fd);
0054     return size;
0055 }
0056 
0057 }}} // namespace boost::stacktrace::detail
0058 
0059 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_POSIX_IPP