1061da546Spatrick //===-- AppleGetPendingItemsHandler.h ----------------------------*- C++ 2061da546Spatrick //-*-===// 3061da546Spatrick // 4061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 6061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7061da546Spatrick // 8061da546Spatrick //===----------------------------------------------------------------------===// 9061da546Spatrick 10dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETPENDINGITEMSHANDLER_H 11dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETPENDINGITEMSHANDLER_H 12061da546Spatrick 13061da546Spatrick #include <map> 14061da546Spatrick #include <mutex> 15061da546Spatrick #include <vector> 16061da546Spatrick 17061da546Spatrick #include "lldb/Symbol/CompilerType.h" 18061da546Spatrick #include "lldb/Utility/Status.h" 19061da546Spatrick #include "lldb/lldb-public.h" 20061da546Spatrick 21061da546Spatrick // This class will insert a UtilityFunction into the inferior process for 22061da546Spatrick // calling libBacktraceRecording's 23061da546Spatrick // __introspection_dispatch_queue_get_pending_items() 24061da546Spatrick // function. The function in the inferior will return a struct by value 25061da546Spatrick // with these members: 26061da546Spatrick // 27061da546Spatrick // struct get_pending_items_return_values 28061da546Spatrick // { 29061da546Spatrick // introspection_dispatch_item_info_ref *items_buffer; 30061da546Spatrick // uint64_t items_buffer_size; 31061da546Spatrick // uint64_t count; 32061da546Spatrick // }; 33061da546Spatrick // 34061da546Spatrick // The items_buffer pointer is an address in the inferior program's address 35061da546Spatrick // space (items_buffer_size in size) which must be mach_vm_deallocate'd by 36061da546Spatrick // lldb. count is the number of items that were stored in the buffer. 37061da546Spatrick // 38061da546Spatrick // The AppleGetPendingItemsHandler object should persist so that the 39061da546Spatrick // UtilityFunction 40061da546Spatrick // can be reused multiple times. 41061da546Spatrick 42061da546Spatrick namespace lldb_private { 43061da546Spatrick 44061da546Spatrick class AppleGetPendingItemsHandler { 45061da546Spatrick public: 46061da546Spatrick AppleGetPendingItemsHandler(lldb_private::Process *process); 47061da546Spatrick 48061da546Spatrick ~AppleGetPendingItemsHandler(); 49061da546Spatrick 50061da546Spatrick struct GetPendingItemsReturnInfo { 51*be691f3bSpatrick lldb::addr_t items_buffer_ptr = 52*be691f3bSpatrick LLDB_INVALID_ADDRESS; /* the address of the pending items buffer 53061da546Spatrick from libBacktraceRecording */ 54*be691f3bSpatrick lldb::addr_t items_buffer_size = 0; /* the size of the pending items buffer 55*be691f3bSpatrick from libBacktraceRecording */ 56*be691f3bSpatrick uint64_t count = 0; /* the number of pending items included in the buffer */ 57061da546Spatrick 58*be691f3bSpatrick GetPendingItemsReturnInfo() = default; 59061da546Spatrick }; 60061da546Spatrick 61061da546Spatrick /// Get the list of pending items for a given queue via a call to 62061da546Spatrick /// __introspection_dispatch_queue_get_pending_items. If there's a page of 63061da546Spatrick /// memory that needs to be freed, pass in the address and size and it will 64061da546Spatrick /// be freed before getting the list of queues. 65061da546Spatrick /// 66061da546Spatrick /// \param [in] thread 67061da546Spatrick /// The thread to run this plan on. 68061da546Spatrick /// 69061da546Spatrick /// \param [in] queue 70061da546Spatrick /// The dispatch_queue_t value for the queue of interest. 71061da546Spatrick /// 72061da546Spatrick /// \param [in] page_to_free 73061da546Spatrick /// An address of an inferior process vm page that needs to be 74061da546Spatrick /// deallocated, 75061da546Spatrick /// LLDB_INVALID_ADDRESS if this is not needed. 76061da546Spatrick /// 77061da546Spatrick /// \param [in] page_to_free_size 78061da546Spatrick /// The size of the vm page that needs to be deallocated if an address was 79061da546Spatrick /// passed in to page_to_free. 80061da546Spatrick /// 81061da546Spatrick /// \param [out] error 82061da546Spatrick /// This object will be updated with the error status / error string from 83061da546Spatrick /// any failures encountered. 84061da546Spatrick /// 85061da546Spatrick /// \returns 86061da546Spatrick /// The result of the inferior function call execution. If there was a 87061da546Spatrick /// failure of any kind while getting 88061da546Spatrick /// the information, the items_buffer_ptr value will be 89061da546Spatrick /// LLDB_INVALID_ADDRESS. 90061da546Spatrick GetPendingItemsReturnInfo GetPendingItems(Thread &thread, lldb::addr_t queue, 91061da546Spatrick lldb::addr_t page_to_free, 92061da546Spatrick uint64_t page_to_free_size, 93061da546Spatrick lldb_private::Status &error); 94061da546Spatrick 95061da546Spatrick void Detach(); 96061da546Spatrick 97061da546Spatrick private: 98061da546Spatrick lldb::addr_t 99061da546Spatrick SetupGetPendingItemsFunction(Thread &thread, 100061da546Spatrick ValueList &get_pending_items_arglist); 101061da546Spatrick 102061da546Spatrick static const char *g_get_pending_items_function_name; 103061da546Spatrick static const char *g_get_pending_items_function_code; 104061da546Spatrick 105061da546Spatrick lldb_private::Process *m_process; 106061da546Spatrick std::unique_ptr<UtilityFunction> m_get_pending_items_impl_code; 107061da546Spatrick std::mutex m_get_pending_items_function_mutex; 108061da546Spatrick 109061da546Spatrick lldb::addr_t m_get_pending_items_return_buffer_addr; 110061da546Spatrick std::mutex m_get_pending_items_retbuffer_mutex; 111061da546Spatrick }; 112061da546Spatrick 113061da546Spatrick } // using namespace lldb_private 114061da546Spatrick 115dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETPENDINGITEMSHANDLER_H 116