1 // Copyright Antony Polukhin, 2016-2022.
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP
8 #define BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP
10 #include <boost/config.hpp>
11 #ifdef BOOST_HAS_PRAGMA_ONCE
15 #include <boost/stacktrace/safe_dump_to.hpp>
17 #include <boost/core/noncopyable.hpp>
19 #include <boost/winapi/get_current_process.hpp>
20 #include <boost/winapi/file_management.hpp>
21 #include <boost/winapi/handles.hpp>
22 #include <boost/winapi/access_rights.hpp>
24 namespace boost { namespace stacktrace { namespace detail {
26 std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
27 #if 0 // This code potentially could cause deadlocks (according to the MSDN). Disabled
28 boost::winapi::DWORD_ written;
29 const boost::winapi::DWORD_ bytes_to_write = static_cast<boost::winapi::DWORD_>(
30 sizeof(native_frame_ptr_t) * frames_count
32 if (!boost::winapi::WriteFile(fd, frames, bytes_to_write, &written, 0)) {
41 std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
42 #if 0 // This code causing deadlocks on some platforms. Disabled
43 void* const fd = boost::winapi::CreateFileA(
45 boost::winapi::GENERIC_WRITE_,
48 boost::winapi::CREATE_ALWAYS_,
49 boost::winapi::FILE_ATTRIBUTE_NORMAL_,
53 if (fd == boost::winapi::invalid_handle_value) {
57 const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
58 boost::winapi::CloseHandle(fd);
64 }}} // namespace boost::stacktrace::detail
66 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP