14bb0738eSEd Maste //===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste // C Includes
11ac7ddfbfSEd Maste // C++ Includes
12ac7ddfbfSEd Maste // Other libraries and framework includes
134bb0738eSEd Maste // Project includes
144bb0738eSEd Maste #include "lldb/Target/OperatingSystem.h"
15ac7ddfbfSEd Maste #include "lldb/Core/PluginManager.h"
16ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
17ac7ddfbfSEd Maste 
18ac7ddfbfSEd Maste using namespace lldb;
19ac7ddfbfSEd Maste using namespace lldb_private;
20ac7ddfbfSEd Maste 
21435933ddSDimitry Andric OperatingSystem *OperatingSystem::FindPlugin(Process *process,
22435933ddSDimitry Andric                                              const char *plugin_name) {
234bb0738eSEd Maste   OperatingSystemCreateInstance create_callback = nullptr;
24435933ddSDimitry Andric   if (plugin_name) {
25ac7ddfbfSEd Maste     ConstString const_plugin_name(plugin_name);
26435933ddSDimitry Andric     create_callback =
27435933ddSDimitry Andric         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
28435933ddSDimitry Andric             const_plugin_name);
29435933ddSDimitry Andric     if (create_callback) {
30435933ddSDimitry Andric       std::unique_ptr<OperatingSystem> instance_ap(
31435933ddSDimitry Andric           create_callback(process, true));
324bb0738eSEd Maste       if (instance_ap)
33ac7ddfbfSEd Maste         return instance_ap.release();
34ac7ddfbfSEd Maste     }
35435933ddSDimitry Andric   } else {
36435933ddSDimitry Andric     for (uint32_t idx = 0;
37435933ddSDimitry Andric          (create_callback =
38435933ddSDimitry Andric               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
39435933ddSDimitry Andric          nullptr;
40435933ddSDimitry Andric          ++idx) {
41435933ddSDimitry Andric       std::unique_ptr<OperatingSystem> instance_ap(
42435933ddSDimitry Andric           create_callback(process, false));
434bb0738eSEd Maste       if (instance_ap)
44ac7ddfbfSEd Maste         return instance_ap.release();
45ac7ddfbfSEd Maste     }
46ac7ddfbfSEd Maste   }
474bb0738eSEd Maste   return nullptr;
48ac7ddfbfSEd Maste }
49ac7ddfbfSEd Maste 
50435933ddSDimitry Andric OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
51ac7ddfbfSEd Maste 
524bb0738eSEd Maste OperatingSystem::~OperatingSystem() = default;
53ac7ddfbfSEd Maste 
54435933ddSDimitry Andric bool OperatingSystem::IsOperatingSystemPluginThread(
55435933ddSDimitry Andric     const lldb::ThreadSP &thread_sp) {
56ac7ddfbfSEd Maste   if (thread_sp)
57ac7ddfbfSEd Maste     return thread_sp->IsOperatingSystemPluginThread();
58ac7ddfbfSEd Maste   return false;
59ac7ddfbfSEd Maste }
60