1 // Copyright Antony Polukhin, 2016-2017.
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/detail/winapi/get_current_process.hpp>
20 #include <boost/detail/winapi/file_management.hpp>
21 #include <boost/detail/winapi/handles.hpp>
22 #include <boost/detail/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 boost::detail::winapi::DWORD_ written;
28 const boost::detail::winapi::DWORD_ bytes_to_write = static_cast<boost::detail::winapi::DWORD_>(
29 sizeof(native_frame_ptr_t) * frames_count
31 if (!boost::detail::winapi::WriteFile(fd, frames, bytes_to_write, &written, 0)) {
38 std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT {
39 void* const fd = boost::detail::winapi::CreateFileA(
41 boost::detail::winapi::GENERIC_WRITE_,
44 boost::detail::winapi::CREATE_ALWAYS_,
45 boost::detail::winapi::FILE_ATTRIBUTE_NORMAL_,
49 if (fd == boost::detail::winapi::invalid_handle_value) {
53 const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
54 boost::detail::winapi::CloseHandle(fd);
58 }}} // namespace boost::stacktrace::detail
60 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP