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_WIN_IPP
0008 #define BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_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 <boost/core/noncopyable.hpp>
0018 
0019 #include <boost/winapi/get_current_process.hpp>
0020 #include <boost/winapi/file_management.hpp>
0021 #include <boost/winapi/handles.hpp>
0022 #include <boost/winapi/access_rights.hpp>
0023 
0024 namespace boost { namespace stacktrace { namespace detail {
0025 
0026 std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
0027 #if 0 // This code potentially could cause deadlocks (according to the MSDN). Disabled
0028     boost::winapi::DWORD_ written;
0029     const boost::winapi::DWORD_ bytes_to_write = static_cast<boost::winapi::DWORD_>(
0030         sizeof(native_frame_ptr_t) * frames_count
0031     );
0032     if (!boost::winapi::WriteFile(fd, frames, bytes_to_write, &written, 0)) {
0033         return 0;
0034     }
0035 
0036     return frames_count;
0037 #endif
0038     return 0;
0039 }
0040 
0041 std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
0042 #if 0 // This code causing deadlocks on some platforms. Disabled
0043     void* const fd = boost::winapi::CreateFileA(
0044         file,
0045         boost::winapi::GENERIC_WRITE_,
0046         0,
0047         0,
0048         boost::winapi::CREATE_ALWAYS_,
0049         boost::winapi::FILE_ATTRIBUTE_NORMAL_,
0050         0
0051     );
0052 
0053     if (fd == boost::winapi::invalid_handle_value) {
0054         return 0;
0055     }
0056 
0057     const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
0058     boost::winapi::CloseHandle(fd);
0059     return size;
0060 #endif
0061     return 0;
0062 }
0063 
0064 }}} // namespace boost::stacktrace::detail
0065 
0066 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP