]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/stacktrace/detail/safe_dump_win.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / stacktrace / detail / safe_dump_win.ipp
1 // Copyright Antony Polukhin, 2016-2017.
2 //
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)
6
7 #ifndef BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP
8 #define BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP
9
10 #include <boost/config.hpp>
11 #ifdef BOOST_HAS_PRAGMA_ONCE
12 # pragma once
13 #endif
14
15 #include <boost/stacktrace/safe_dump_to.hpp>
16
17 #include <boost/core/noncopyable.hpp>
18
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>
23
24 namespace boost { namespace stacktrace { namespace detail {
25
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
30 );
31 if (!boost::detail::winapi::WriteFile(fd, frames, bytes_to_write, &written, 0)) {
32 return 0;
33 }
34
35 return frames_count;
36 }
37
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(
40 file,
41 boost::detail::winapi::GENERIC_WRITE_,
42 0,
43 0,
44 boost::detail::winapi::CREATE_ALWAYS_,
45 boost::detail::winapi::FILE_ATTRIBUTE_NORMAL_,
46 0
47 );
48
49 if (fd == boost::detail::winapi::invalid_handle_value) {
50 return 0;
51 }
52
53 const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
54 boost::detail::winapi::CloseHandle(fd);
55 return size;
56 }
57
58 }}} // namespace boost::stacktrace::detail
59
60 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP