]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/stacktrace/detail/safe_dump_win.ipp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / stacktrace / detail / safe_dump_win.ipp
1 // Copyright Antony Polukhin, 2016-2022.
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/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>
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 #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
31 );
32 if (!boost::winapi::WriteFile(fd, frames, bytes_to_write, &written, 0)) {
33 return 0;
34 }
35
36 return frames_count;
37 #endif
38 return 0;
39 }
40
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(
44 file,
45 boost::winapi::GENERIC_WRITE_,
46 0,
47 0,
48 boost::winapi::CREATE_ALWAYS_,
49 boost::winapi::FILE_ATTRIBUTE_NORMAL_,
50 0
51 );
52
53 if (fd == boost::winapi::invalid_handle_value) {
54 return 0;
55 }
56
57 const std::size_t size = boost::stacktrace::detail::dump(fd, frames, frames_count);
58 boost::winapi::CloseHandle(fd);
59 return size;
60 #endif
61 return 0;
62 }
63
64 }}} // namespace boost::stacktrace::detail
65
66 #endif // BOOST_STACKTRACE_DETAIL_SAFE_DUMP_WIN_IPP