19394d772SEugene Zelenko //===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===//
256d9a1b3SGreg Clayton //
356d9a1b3SGreg Clayton //                     The LLVM Compiler Infrastructure
456d9a1b3SGreg Clayton //
556d9a1b3SGreg Clayton // This file is distributed under the University of Illinois Open Source
656d9a1b3SGreg Clayton // License. See LICENSE.TXT for details.
756d9a1b3SGreg Clayton //
856d9a1b3SGreg Clayton //===----------------------------------------------------------------------===//
956d9a1b3SGreg Clayton 
1056d9a1b3SGreg Clayton // C Includes
1156d9a1b3SGreg Clayton // C++ Includes
1256d9a1b3SGreg Clayton // Other libraries and framework includes
139394d772SEugene Zelenko // Project includes
149394d772SEugene Zelenko #include "lldb/Target/OperatingSystem.h"
1556d9a1b3SGreg Clayton #include "lldb/Core/PluginManager.h"
16160c9d81SGreg Clayton #include "lldb/Target/Thread.h"
1756d9a1b3SGreg Clayton 
1856d9a1b3SGreg Clayton using namespace lldb;
1956d9a1b3SGreg Clayton using namespace lldb_private;
2056d9a1b3SGreg Clayton 
21*b9c1b51eSKate Stone OperatingSystem *OperatingSystem::FindPlugin(Process *process,
22*b9c1b51eSKate Stone                                              const char *plugin_name) {
239394d772SEugene Zelenko   OperatingSystemCreateInstance create_callback = nullptr;
24*b9c1b51eSKate Stone   if (plugin_name) {
2557abc5d6SGreg Clayton     ConstString const_plugin_name(plugin_name);
26*b9c1b51eSKate Stone     create_callback =
27*b9c1b51eSKate Stone         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
28*b9c1b51eSKate Stone             const_plugin_name);
29*b9c1b51eSKate Stone     if (create_callback) {
30*b9c1b51eSKate Stone       std::unique_ptr<OperatingSystem> instance_ap(
31*b9c1b51eSKate Stone           create_callback(process, true));
329394d772SEugene Zelenko       if (instance_ap)
3356d9a1b3SGreg Clayton         return instance_ap.release();
3456d9a1b3SGreg Clayton     }
35*b9c1b51eSKate Stone   } else {
36*b9c1b51eSKate Stone     for (uint32_t idx = 0;
37*b9c1b51eSKate Stone          (create_callback =
38*b9c1b51eSKate Stone               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
39*b9c1b51eSKate Stone          nullptr;
40*b9c1b51eSKate Stone          ++idx) {
41*b9c1b51eSKate Stone       std::unique_ptr<OperatingSystem> instance_ap(
42*b9c1b51eSKate Stone           create_callback(process, false));
439394d772SEugene Zelenko       if (instance_ap)
4456d9a1b3SGreg Clayton         return instance_ap.release();
4556d9a1b3SGreg Clayton     }
4656d9a1b3SGreg Clayton   }
479394d772SEugene Zelenko   return nullptr;
4856d9a1b3SGreg Clayton }
4956d9a1b3SGreg Clayton 
50*b9c1b51eSKate Stone OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
5156d9a1b3SGreg Clayton 
529394d772SEugene Zelenko OperatingSystem::~OperatingSystem() = default;
53160c9d81SGreg Clayton 
54*b9c1b51eSKate Stone bool OperatingSystem::IsOperatingSystemPluginThread(
55*b9c1b51eSKate Stone     const lldb::ThreadSP &thread_sp) {
56160c9d81SGreg Clayton   if (thread_sp)
57160c9d81SGreg Clayton     return thread_sp->IsOperatingSystemPluginThread();
58160c9d81SGreg Clayton   return false;
59160c9d81SGreg Clayton }
60