1*0b57cec5SDimitry Andric //===-- OperatingSystem.cpp -----------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/Target/OperatingSystem.h"
10*0b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
11*0b57cec5SDimitry Andric #include "lldb/Target/Thread.h"
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric using namespace lldb;
14*0b57cec5SDimitry Andric using namespace lldb_private;
15*0b57cec5SDimitry Andric 
FindPlugin(Process * process,const char * plugin_name)16*0b57cec5SDimitry Andric OperatingSystem *OperatingSystem::FindPlugin(Process *process,
17*0b57cec5SDimitry Andric                                              const char *plugin_name) {
18*0b57cec5SDimitry Andric   OperatingSystemCreateInstance create_callback = nullptr;
19*0b57cec5SDimitry Andric   if (plugin_name) {
20*0b57cec5SDimitry Andric     create_callback =
21*0b57cec5SDimitry Andric         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
22*0b57cec5SDimitry Andric             plugin_name);
23*0b57cec5SDimitry Andric     if (create_callback) {
24*0b57cec5SDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
25*0b57cec5SDimitry Andric           create_callback(process, true));
26*0b57cec5SDimitry Andric       if (instance_up)
27*0b57cec5SDimitry Andric         return instance_up.release();
28*0b57cec5SDimitry Andric     }
29*0b57cec5SDimitry Andric   } else {
30*0b57cec5SDimitry Andric     for (uint32_t idx = 0;
31*0b57cec5SDimitry Andric          (create_callback =
32*0b57cec5SDimitry Andric               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
33*0b57cec5SDimitry Andric          nullptr;
34*0b57cec5SDimitry Andric          ++idx) {
35*0b57cec5SDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
36*0b57cec5SDimitry Andric           create_callback(process, false));
37*0b57cec5SDimitry Andric       if (instance_up)
38*0b57cec5SDimitry Andric         return instance_up.release();
39*0b57cec5SDimitry Andric     }
40*0b57cec5SDimitry Andric   }
41*0b57cec5SDimitry Andric   return nullptr;
42*0b57cec5SDimitry Andric }
43*0b57cec5SDimitry Andric 
OperatingSystem(Process * process)44*0b57cec5SDimitry Andric OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
45*0b57cec5SDimitry Andric 
IsOperatingSystemPluginThread(const lldb::ThreadSP & thread_sp)46*0b57cec5SDimitry Andric bool OperatingSystem::IsOperatingSystemPluginThread(
47*0b57cec5SDimitry Andric     const lldb::ThreadSP &thread_sp) {
48*0b57cec5SDimitry Andric   if (thread_sp)
49*0b57cec5SDimitry Andric     return thread_sp->IsOperatingSystemPluginThread();
50*0b57cec5SDimitry Andric   return false;
51*0b57cec5SDimitry Andric }
52*0b57cec5SDimitry Andric