1 //===-- source/Host/windows/Host.cpp ----------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // C Includes
11 #include <stdio.h>
12 #include "lldb/Host/windows/windows.h"
13 
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Core/Error.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Target/Process.h"
20 
21 #include "lldb/Host/Host.h"
22 #include "lldb/Core/DataBufferHeap.h"
23 #include "lldb/Core/DataExtractor.h"
24 
25 using namespace lldb;
26 using namespace lldb_private;
27 
28 bool
29 Host::GetOSVersion(uint32_t &major,
30                    uint32_t &minor,
31                    uint32_t &update)
32 {
33     OSVERSIONINFOEX info;
34 
35     ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
36     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
37 
38     if (GetVersionEx((LPOSVERSIONINFO) &info) == 0) {
39         return false;
40     }
41 
42     major = (uint32_t) info.dwMajorVersion;
43     minor = (uint32_t) info.dwMinorVersion;
44     update = (uint32_t) info.wServicePackMajor;
45 
46     return true;
47 }
48 
49 Error
50 Host::LaunchProcess (ProcessLaunchInfo &launch_info)
51 {
52     Error error;
53     assert(!"Not implemented yet!!!");
54     return error;
55 }
56 
57 lldb::DataBufferSP
58 Host::GetAuxvData(lldb_private::Process *process)
59 {
60     return 0;
61 }
62 
63 std::string
64 Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
65 {
66     return std::string();
67 }
68 
69 lldb::tid_t
70 Host::GetCurrentThreadID()
71 {
72     return lldb::tid_t(::GetCurrentThreadId());
73 }
74 
75 lldb::thread_t
76 Host::GetCurrentThread ()
77 {
78     return lldb::thread_t(::GetCurrentThread());
79 }
80 
81 bool
82 Host::ThreadCancel (lldb::thread_t thread, Error *error)
83 {
84     int err = ::TerminateThread((HANDLE)thread, 0);
85     return err == 0;
86 }
87 
88 bool
89 Host::ThreadDetach (lldb::thread_t thread, Error *error)
90 {
91     return ThreadCancel(thread, error);
92 }
93 
94 bool
95 Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
96 {
97     WaitForSingleObject((HANDLE) thread, INFINITE);
98     return true;
99 }
100 
101 lldb::thread_key_t
102 Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback)
103 {
104     return TlsAlloc();
105 }
106 
107 void*
108 Host::ThreadLocalStorageGet(lldb::thread_key_t key)
109 {
110     return ::TlsGetValue (key);
111 }
112 
113 void
114 Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value)
115 {
116    ::TlsSetValue (key, value);
117 }
118 
119 bool
120 Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
121 {
122     return false;
123 }
124 
125 bool
126 Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
127                           const char *thread_name, size_t len)
128 {
129     return false;
130 }
131 
132 void
133 Host::Kill(lldb::pid_t pid, int signo)
134 {
135     TerminateProcess((HANDLE) pid, 1);
136 }
137 
138 uint32_t
139 Host::GetNumberCPUS()
140 {
141     static uint32_t g_num_cores = UINT32_MAX;
142     if (g_num_cores == UINT32_MAX)
143     {
144         SYSTEM_INFO system_info;
145         ::GetSystemInfo(&system_info);
146         g_num_cores = system_info.dwNumberOfProcessors;
147     }
148     return g_num_cores;
149 }
150 
151 size_t
152 Host::GetPageSize()
153 {
154     static long g_pagesize = 0;
155     if (!g_pagesize)
156     {
157         SYSTEM_INFO systemInfo;
158         GetNativeSystemInfo(&systemInfo);
159         g_pagesize = systemInfo.dwPageSize;
160     }
161     return g_pagesize;
162 }
163 
164 const char *
165 Host::GetSignalAsCString(int signo)
166 {
167     return NULL;
168 }
169 
170 FileSpec
171 Host::GetModuleFileSpecForHostAddress (const void *host_addr)
172 {
173     FileSpec module_filespec;
174     return module_filespec;
175 }
176 
177 void *
178 Host::DynamicLibraryOpen(const FileSpec &file_spec, uint32_t options, Error &error)
179 {
180     error.SetErrorString("not implemented");
181     return NULL;
182 }
183 
184 Error
185 Host::DynamicLibraryClose (void *opaque)
186 {
187     Error error;
188     error.SetErrorString("not implemented");
189     return error;
190 }
191 
192 void *
193 Host::DynamicLibraryGetSymbol(void *opaque, const char *symbol_name, Error &error)
194 {
195     error.SetErrorString("not implemented");
196     return NULL;
197 }
198 
199 const char *
200 Host::GetUserName (uint32_t uid, std::string &user_name)
201 {
202     return NULL;
203 }
204 
205 const char *
206 Host::GetGroupName (uint32_t gid, std::string &group_name)
207 {
208     return NULL;
209 }
210 
211 uint32_t
212 Host::GetUserID ()
213 {
214     return 0;
215 }
216 
217 uint32_t
218 Host::GetGroupID ()
219 {
220     return 0;
221 }
222 
223 uint32_t
224 Host::GetEffectiveUserID ()
225 {
226     return 0;
227 }
228 
229 uint32_t
230 Host::GetEffectiveGroupID ()
231 {
232     return 0;
233 }
234 
235 lldb::thread_t
236 Host::StartMonitoringChildProcess
237 (
238     Host::MonitorChildProcessCallback callback,
239     void *callback_baton,
240     lldb::pid_t pid,
241     bool monitor_signals
242 )
243 {
244     return LLDB_INVALID_HOST_THREAD;
245 }