1e996fd30SGreg Clayton //===-- PlatformLinux.cpp ---------------------------------------*- C++ -*-===//
2e996fd30SGreg Clayton //
3e996fd30SGreg Clayton //                     The LLVM Compiler Infrastructure
4e996fd30SGreg Clayton //
5e996fd30SGreg Clayton // This file is distributed under the University of Illinois Open Source
6e996fd30SGreg Clayton // License. See LICENSE.TXT for details.
7e996fd30SGreg Clayton //
8e996fd30SGreg Clayton //===----------------------------------------------------------------------===//
9e996fd30SGreg Clayton 
10e996fd30SGreg Clayton #include "PlatformLinux.h"
11b2f1fb29SVirgile Bello #include "lldb/Host/Config.h"
12e996fd30SGreg Clayton 
13e996fd30SGreg Clayton // C Includes
14ecc11474SStephen Wilson #include <stdio.h>
15b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX
16ecc11474SStephen Wilson #include <sys/utsname.h>
17b2f1fb29SVirgile Bello #endif
18ecc11474SStephen Wilson 
19e996fd30SGreg Clayton // C++ Includes
20e996fd30SGreg Clayton // Other libraries and framework includes
21e996fd30SGreg Clayton // Project includes
2228041352SGreg Clayton #include "lldb/Core/Debugger.h"
23ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h"
2413b18261SZachary Turner #include "lldb/Host/HostInfo.h"
25e996fd30SGreg Clayton #include "lldb/Target/Process.h"
26b9c1b51eSKate Stone #include "lldb/Target/Target.h"
275713a05bSZachary Turner #include "lldb/Utility/FileSpec.h"
286f9e6901SZachary Turner #include "lldb/Utility/Log.h"
29d821c997SPavel Labath #include "lldb/Utility/State.h"
3097206d57SZachary Turner #include "lldb/Utility/Status.h"
31bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h"
32e996fd30SGreg Clayton 
3305097246SAdrian Prantl // Define these constants from Linux mman.h for use when targeting remote linux
3405097246SAdrian Prantl // systems even when host has different values.
3596ad3de5SRobert Flack #define MAP_PRIVATE 2
3696ad3de5SRobert Flack #define MAP_ANON 0x20
3796ad3de5SRobert Flack 
38e996fd30SGreg Clayton using namespace lldb;
39e996fd30SGreg Clayton using namespace lldb_private;
40db264a6dSTamas Berghammer using namespace lldb_private::platform_linux;
41e996fd30SGreg Clayton 
4228041352SGreg Clayton static uint32_t g_initialize_count = 0;
4328041352SGreg Clayton 
44281961a8STodd Fiala //------------------------------------------------------------------
45281961a8STodd Fiala 
46b9c1b51eSKate Stone PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) {
47db264a6dSTamas Berghammer   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
480e92fbb5SPavel Labath   LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
490e92fbb5SPavel Labath            arch ? arch->GetArchitectureName() : "<null>",
500e92fbb5SPavel Labath            arch ? arch->GetTriple().getTriple() : "<null>");
51015d818bSTodd Fiala 
52b3a40ba8SGreg Clayton   bool create = force;
53b9c1b51eSKate Stone   if (create == false && arch && arch->IsValid()) {
54b3a40ba8SGreg Clayton     const llvm::Triple &triple = arch->GetTriple();
55b9c1b51eSKate Stone     switch (triple.getOS()) {
5670512317SGreg Clayton     case llvm::Triple::Linux:
57b1da257aSTed Woodward       create = true;
5870512317SGreg Clayton       break;
5970512317SGreg Clayton 
60dbc6c0bbSGreg Clayton #if defined(__linux__)
6105097246SAdrian Prantl     // Only accept "unknown" for the OS if the host is linux and it "unknown"
6205097246SAdrian Prantl     // wasn't specified (it was just returned because it was NOT specified)
63015d818bSTodd Fiala     case llvm::Triple::OSType::UnknownOS:
6470512317SGreg Clayton       create = !arch->TripleOSWasSpecified();
6570512317SGreg Clayton       break;
66dbc6c0bbSGreg Clayton #endif
6770512317SGreg Clayton     default:
6870512317SGreg Clayton       break;
6970512317SGreg Clayton     }
7070512317SGreg Clayton   }
71015d818bSTodd Fiala 
720e92fbb5SPavel Labath   LLDB_LOG(log, "create = {0}", create);
73b9c1b51eSKate Stone   if (create) {
74615eb7e6SGreg Clayton     return PlatformSP(new PlatformLinux(false));
75015d818bSTodd Fiala   }
76615eb7e6SGreg Clayton   return PlatformSP();
77ecc11474SStephen Wilson }
78ecc11474SStephen Wilson 
79b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginNameStatic(bool is_host) {
80b9c1b51eSKate Stone   if (is_host) {
8157abc5d6SGreg Clayton     static ConstString g_host_name(Platform::GetHostPlatformName());
8257abc5d6SGreg Clayton     return g_host_name;
83b9c1b51eSKate Stone   } else {
8457abc5d6SGreg Clayton     static ConstString g_remote_name("remote-linux");
8557abc5d6SGreg Clayton     return g_remote_name;
8657abc5d6SGreg Clayton   }
8728041352SGreg Clayton }
8828041352SGreg Clayton 
89b9c1b51eSKate Stone const char *PlatformLinux::GetPluginDescriptionStatic(bool is_host) {
9028041352SGreg Clayton   if (is_host)
9128041352SGreg Clayton     return "Local Linux user platform plug-in.";
9228041352SGreg Clayton   else
9328041352SGreg Clayton     return "Remote Linux user platform plug-in.";
94ecc11474SStephen Wilson }
95ecc11474SStephen Wilson 
96b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginName() {
9757abc5d6SGreg Clayton   return GetPluginNameStatic(IsHost());
9857abc5d6SGreg Clayton }
9957abc5d6SGreg Clayton 
100b9c1b51eSKate Stone void PlatformLinux::Initialize() {
1013c4f89d7STamas Berghammer   PlatformPOSIX::Initialize();
1023c4f89d7STamas Berghammer 
103b9c1b51eSKate Stone   if (g_initialize_count++ == 0) {
1041c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__)
10528041352SGreg Clayton     PlatformSP default_platform_sp(new PlatformLinux(true));
10613b18261SZachary Turner     default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
107615eb7e6SGreg Clayton     Platform::SetHostPlatform(default_platform_sp);
10828041352SGreg Clayton #endif
109b9c1b51eSKate Stone     PluginManager::RegisterPlugin(
110b9c1b51eSKate Stone         PlatformLinux::GetPluginNameStatic(false),
11128041352SGreg Clayton         PlatformLinux::GetPluginDescriptionStatic(false),
112d65ac229SPavel Labath         PlatformLinux::CreateInstance, nullptr);
113ecc11474SStephen Wilson   }
114e996fd30SGreg Clayton }
115e996fd30SGreg Clayton 
116b9c1b51eSKate Stone void PlatformLinux::Terminate() {
117b9c1b51eSKate Stone   if (g_initialize_count > 0) {
118b9c1b51eSKate Stone     if (--g_initialize_count == 0) {
11928041352SGreg Clayton       PluginManager::UnregisterPlugin(PlatformLinux::CreateInstance);
120e996fd30SGreg Clayton     }
12128041352SGreg Clayton   }
1223c4f89d7STamas Berghammer 
1233c4f89d7STamas Berghammer   PlatformPOSIX::Terminate();
12428041352SGreg Clayton }
125e996fd30SGreg Clayton 
126e996fd30SGreg Clayton //------------------------------------------------------------------
127e996fd30SGreg Clayton /// Default Constructor
128e996fd30SGreg Clayton //------------------------------------------------------------------
129b9c1b51eSKate Stone PlatformLinux::PlatformLinux(bool is_host)
130b9c1b51eSKate Stone     : PlatformPOSIX(is_host) // This is the local host platform
131b9c1b51eSKate Stone {}
132e996fd30SGreg Clayton 
133222b937cSEugene Zelenko PlatformLinux::~PlatformLinux() = default;
134e996fd30SGreg Clayton 
135b9c1b51eSKate Stone bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx,
136b9c1b51eSKate Stone                                                     ArchSpec &arch) {
137b9c1b51eSKate Stone   if (IsHost()) {
138e49b8e06SRobert Flack     ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
139b9c1b51eSKate Stone     if (hostArch.GetTriple().isOSLinux()) {
140b9c1b51eSKate Stone       if (idx == 0) {
141e49b8e06SRobert Flack         arch = hostArch;
142e49b8e06SRobert Flack         return arch.IsValid();
143b9c1b51eSKate Stone       } else if (idx == 1) {
14405097246SAdrian Prantl         // If the default host architecture is 64-bit, look for a 32-bit
14505097246SAdrian Prantl         // variant
146b9c1b51eSKate Stone         if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) {
147e49b8e06SRobert Flack           arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
148e49b8e06SRobert Flack           return arch.IsValid();
149e49b8e06SRobert Flack         }
150e49b8e06SRobert Flack       }
151e49b8e06SRobert Flack     }
152b9c1b51eSKate Stone   } else {
153e49b8e06SRobert Flack     if (m_remote_platform_sp)
154e49b8e06SRobert Flack       return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch);
155bb1e283cSTed Woodward 
156bb1e283cSTed Woodward     llvm::Triple triple;
157bb1e283cSTed Woodward     // Set the OS to linux
158bb1e283cSTed Woodward     triple.setOS(llvm::Triple::Linux);
159bb1e283cSTed Woodward     // Set the architecture
160b9c1b51eSKate Stone     switch (idx) {
161b9c1b51eSKate Stone     case 0:
162b9c1b51eSKate Stone       triple.setArchName("x86_64");
163b9c1b51eSKate Stone       break;
164b9c1b51eSKate Stone     case 1:
165b9c1b51eSKate Stone       triple.setArchName("i386");
166b9c1b51eSKate Stone       break;
167b9c1b51eSKate Stone     case 2:
168b9c1b51eSKate Stone       triple.setArchName("arm");
169b9c1b51eSKate Stone       break;
170b9c1b51eSKate Stone     case 3:
171b9c1b51eSKate Stone       triple.setArchName("aarch64");
172b9c1b51eSKate Stone       break;
173b9c1b51eSKate Stone     case 4:
174b9c1b51eSKate Stone       triple.setArchName("mips64");
175b9c1b51eSKate Stone       break;
176b9c1b51eSKate Stone     case 5:
177b9c1b51eSKate Stone       triple.setArchName("hexagon");
178b9c1b51eSKate Stone       break;
179b9c1b51eSKate Stone     case 6:
180b9c1b51eSKate Stone       triple.setArchName("mips");
181b9c1b51eSKate Stone       break;
182b9c1b51eSKate Stone     case 7:
183b9c1b51eSKate Stone       triple.setArchName("mips64el");
184b9c1b51eSKate Stone       break;
185b9c1b51eSKate Stone     case 8:
186b9c1b51eSKate Stone       triple.setArchName("mipsel");
187b9c1b51eSKate Stone       break;
188b9c1b51eSKate Stone     case 9:
189b9c1b51eSKate Stone       triple.setArchName("s390x");
190b9c1b51eSKate Stone       break;
191b9c1b51eSKate Stone     default:
192b9c1b51eSKate Stone       return false;
193bb1e283cSTed Woodward     }
194b9c1b51eSKate Stone     // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the
19505097246SAdrian Prantl     // vendor by calling triple.SetVendorName("unknown") so that it is a
19605097246SAdrian Prantl     // "unspecified unknown". This means when someone calls
19705097246SAdrian Prantl     // triple.GetVendorName() it will return an empty string which indicates
19805097246SAdrian Prantl     // that the vendor can be set when two architectures are merged
199bb1e283cSTed Woodward 
200bb1e283cSTed Woodward     // Now set the triple into "arch" and return true
201bb1e283cSTed Woodward     arch.SetTriple(triple);
202bb1e283cSTed Woodward     return true;
203e49b8e06SRobert Flack   }
204e996fd30SGreg Clayton   return false;
205e996fd30SGreg Clayton }
206ecc11474SStephen Wilson 
207b9c1b51eSKate Stone void PlatformLinux::GetStatus(Stream &strm) {
2083be69dacSDaniel Malea   Platform::GetStatus(strm);
209ecc11474SStephen Wilson 
210b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX
211b743a803SStephane Sezer   // Display local kernel information only when we are running in host mode.
21205097246SAdrian Prantl   // Otherwise, we would end up printing non-Linux information (when running on
21305097246SAdrian Prantl   // Mac OS for example).
214b9c1b51eSKate Stone   if (IsHost()) {
215b2f1fb29SVirgile Bello     struct utsname un;
216b2f1fb29SVirgile Bello 
2173be69dacSDaniel Malea     if (uname(&un))
2183be69dacSDaniel Malea       return;
2193be69dacSDaniel Malea 
2203be69dacSDaniel Malea     strm.Printf("    Kernel: %s\n", un.sysname);
2213be69dacSDaniel Malea     strm.Printf("   Release: %s\n", un.release);
2223be69dacSDaniel Malea     strm.Printf("   Version: %s\n", un.version);
223b743a803SStephane Sezer   }
224b2f1fb29SVirgile Bello #endif
225ecc11474SStephen Wilson }
226ecc11474SStephen Wilson 
227348fb385STodd Fiala int32_t
228b9c1b51eSKate Stone PlatformLinux::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
229348fb385STodd Fiala   int32_t resume_count = 0;
23028041352SGreg Clayton 
231348fb385STodd Fiala   // Always resume past the initial stop when we use eLaunchFlagDebug
232b9c1b51eSKate Stone   if (launch_info.GetFlags().Test(eLaunchFlagDebug)) {
233348fb385STodd Fiala     // Resume past the stop for the final exec into the true inferior.
234348fb385STodd Fiala     ++resume_count;
235348fb385STodd Fiala   }
236015d818bSTodd Fiala 
237348fb385STodd Fiala   // If we're not launching a shell, we're done.
23810687b0eSZachary Turner   const FileSpec &shell = launch_info.GetShell();
23910687b0eSZachary Turner   if (!shell)
240348fb385STodd Fiala     return resume_count;
241348fb385STodd Fiala 
24210687b0eSZachary Turner   std::string shell_string = shell.GetPath();
243348fb385STodd Fiala   // We're in a shell, so for sure we have to resume past the shell exec.
244348fb385STodd Fiala   ++resume_count;
245348fb385STodd Fiala 
246348fb385STodd Fiala   // Figure out what shell we're planning on using.
24710687b0eSZachary Turner   const char *shell_name = strrchr(shell_string.c_str(), '/');
248348fb385STodd Fiala   if (shell_name == NULL)
24910687b0eSZachary Turner     shell_name = shell_string.c_str();
25028041352SGreg Clayton   else
251348fb385STodd Fiala     shell_name++;
252348fb385STodd Fiala 
253b9c1b51eSKate Stone   if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 ||
254b9c1b51eSKate Stone       strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) {
255348fb385STodd Fiala     // These shells seem to re-exec themselves.  Add another resume.
256348fb385STodd Fiala     ++resume_count;
257ecc11474SStephen Wilson   }
25813e8e1c3SJohnny Chen 
259348fb385STodd Fiala   return resume_count;
260348fb385STodd Fiala }
261348fb385STodd Fiala 
262b9c1b51eSKate Stone bool PlatformLinux::CanDebugProcess() {
263b9c1b51eSKate Stone   if (IsHost()) {
264b36f9178SPavel Labath     return true;
265b9c1b51eSKate Stone   } else {
266015d818bSTodd Fiala     // If we're connected, we can debug.
267015d818bSTodd Fiala     return IsConnected();
268015d818bSTodd Fiala   }
269348fb385STodd Fiala }
270015d818bSTodd Fiala 
271b9c1b51eSKate Stone // For local debugging, Linux will override the debug logic to use llgs-launch
27205097246SAdrian Prantl // rather than lldb-launch, llgs-attach.  This differs from current lldb-
27305097246SAdrian Prantl // launch, debugserver-attach approach on MacOSX.
27413e8e1c3SJohnny Chen lldb::ProcessSP
275b9c1b51eSKate Stone PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
276b9c1b51eSKate Stone                             Target *target, // Can be NULL, if NULL create a new
277b9c1b51eSKate Stone                                             // target, else use existing one
27897206d57SZachary Turner                             Status &error) {
279db264a6dSTamas Berghammer   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
2800e92fbb5SPavel Labath   LLDB_LOG(log, "target {0}", target);
28128041352SGreg Clayton 
282348fb385STodd Fiala   // If we're a remote host, use standard behavior from parent class.
283348fb385STodd Fiala   if (!IsHost())
2848012cadbSGreg Clayton     return PlatformPOSIX::DebugProcess(launch_info, debugger, target, error);
285348fb385STodd Fiala 
286348fb385STodd Fiala   //
287b9c1b51eSKate Stone   // For local debugging, we'll insist on having ProcessGDBRemote create the
288b9c1b51eSKate Stone   // process.
289348fb385STodd Fiala   //
290348fb385STodd Fiala 
291348fb385STodd Fiala   ProcessSP process_sp;
292348fb385STodd Fiala 
293348fb385STodd Fiala   // Make sure we stop at the entry point
294348fb385STodd Fiala   launch_info.GetFlags().Set(eLaunchFlagDebug);
295348fb385STodd Fiala 
296348fb385STodd Fiala   // We always launch the process we are going to debug in a separate process
29705097246SAdrian Prantl   // group, since then we can handle ^C interrupts ourselves w/o having to
29805097246SAdrian Prantl   // worry about the target getting them as well.
299348fb385STodd Fiala   launch_info.SetLaunchInSeparateProcessGroup(true);
300348fb385STodd Fiala 
301348fb385STodd Fiala   // Ensure we have a target.
302b9c1b51eSKate Stone   if (target == nullptr) {
3030e92fbb5SPavel Labath     LLDB_LOG(log, "creating new target");
304348fb385STodd Fiala     TargetSP new_target_sp;
305*f9a07e9fSJonas Devlieghere     error = debugger.GetTargetList().CreateTarget(
306*f9a07e9fSJonas Devlieghere         debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
307b9c1b51eSKate Stone     if (error.Fail()) {
3080e92fbb5SPavel Labath       LLDB_LOG(log, "failed to create new target: {0}", error);
309348fb385STodd Fiala       return process_sp;
310348fb385STodd Fiala     }
311348fb385STodd Fiala 
31228041352SGreg Clayton     target = new_target_sp.get();
313b9c1b51eSKate Stone     if (!target) {
314348fb385STodd Fiala       error.SetErrorString("CreateTarget() returned nullptr");
3150e92fbb5SPavel Labath       LLDB_LOG(log, "error: {0}", error);
316348fb385STodd Fiala       return process_sp;
317348fb385STodd Fiala     }
318348fb385STodd Fiala   }
319348fb385STodd Fiala 
320348fb385STodd Fiala   // Mark target as currently selected target.
32128041352SGreg Clayton   debugger.GetTargetList().SetSelectedTarget(target);
32228041352SGreg Clayton 
323348fb385STodd Fiala   // Now create the gdb-remote process.
3240e92fbb5SPavel Labath   LLDB_LOG(log, "having target create process with gdb-remote plugin");
325b9c1b51eSKate Stone   process_sp = target->CreateProcess(
326b9c1b51eSKate Stone       launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr);
32728041352SGreg Clayton 
328b9c1b51eSKate Stone   if (!process_sp) {
329348fb385STodd Fiala     error.SetErrorString("CreateProcess() failed for gdb-remote process");
3300e92fbb5SPavel Labath     LLDB_LOG(log, "error: {0}", error);
331348fb385STodd Fiala     return process_sp;
332348fb385STodd Fiala   }
333348fb385STodd Fiala 
3340e92fbb5SPavel Labath   LLDB_LOG(log, "successfully created process");
335348fb385STodd Fiala   // Adjust launch for a hijacker.
336348fb385STodd Fiala   ListenerSP listener_sp;
337b9c1b51eSKate Stone   if (!launch_info.GetHijackListener()) {
3380e92fbb5SPavel Labath     LLDB_LOG(log, "setting up hijacker");
339b9c1b51eSKate Stone     listener_sp =
340b9c1b51eSKate Stone         Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack");
341348fb385STodd Fiala     launch_info.SetHijackListener(listener_sp);
342583bbb1dSJim Ingham     process_sp->HijackProcessEvents(listener_sp);
343348fb385STodd Fiala   }
344348fb385STodd Fiala 
345348fb385STodd Fiala   // Log file actions.
346b9c1b51eSKate Stone   if (log) {
3470e92fbb5SPavel Labath     LLDB_LOG(log, "launching process with the following file actions:");
348348fb385STodd Fiala     StreamString stream;
349348fb385STodd Fiala     size_t i = 0;
350348fb385STodd Fiala     const FileAction *file_action;
351b9c1b51eSKate Stone     while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) {
352348fb385STodd Fiala       file_action->Dump(stream);
3530e92fbb5SPavel Labath       LLDB_LOG(log, "{0}", stream.GetData());
354348fb385STodd Fiala       stream.Clear();
355348fb385STodd Fiala     }
356348fb385STodd Fiala   }
357348fb385STodd Fiala 
358348fb385STodd Fiala   // Do the launch.
359348fb385STodd Fiala   error = process_sp->Launch(launch_info);
360b9c1b51eSKate Stone   if (error.Success()) {
361348fb385STodd Fiala     // Handle the hijacking of process events.
362b9c1b51eSKate Stone     if (listener_sp) {
363b9c1b51eSKate Stone       const StateType state = process_sp->WaitForProcessToStop(
364e3e21cfcSPavel Labath           llvm::None, NULL, false, listener_sp);
365348fb385STodd Fiala 
3660e92fbb5SPavel Labath       LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state);
367348fb385STodd Fiala     }
368348fb385STodd Fiala 
369b9c1b51eSKate Stone     // Hook up process PTY if we have one (which we should for local debugging
370b9c1b51eSKate Stone     // with llgs).
371348fb385STodd Fiala     int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
37207d6f881SPavel Labath     if (pty_fd != PseudoTerminal::invalid_fd) {
373348fb385STodd Fiala       process_sp->SetSTDIOFileDescriptor(pty_fd);
3740e92fbb5SPavel Labath       LLDB_LOG(log, "hooked up STDIO pty to process");
3750e92fbb5SPavel Labath     } else
3760e92fbb5SPavel Labath       LLDB_LOG(log, "not using process STDIO pty");
377b9c1b51eSKate Stone   } else {
3780e92fbb5SPavel Labath     LLDB_LOG(log, "process launch failed: {0}", error);
379b9c1b51eSKate Stone     // FIXME figure out appropriate cleanup here.  Do we delete the target? Do
380b9c1b51eSKate Stone     // we delete the process?  Does our caller do that?
38128041352SGreg Clayton   }
382348fb385STodd Fiala 
38328041352SGreg Clayton   return process_sp;
38413e8e1c3SJohnny Chen }
3852094dbf4SJason Molenda 
386b9c1b51eSKate Stone void PlatformLinux::CalculateTrapHandlerSymbolNames() {
3872094dbf4SJason Molenda   m_trap_handlers.push_back(ConstString("_sigtramp"));
3882094dbf4SJason Molenda }
389af245d11STodd Fiala 
39037c40af7SEd Maste MmapArgList PlatformLinux::GetMmapArgumentList(const ArchSpec &arch,
39137c40af7SEd Maste                                                addr_t addr, addr_t length,
39237c40af7SEd Maste                                                unsigned prot, unsigned flags,
39337c40af7SEd Maste                                                addr_t fd, addr_t offset) {
39496ad3de5SRobert Flack   uint64_t flags_platform = 0;
395e0d8c422SMohit K. Bhakkad   uint64_t map_anon = MAP_ANON;
396e0d8c422SMohit K. Bhakkad 
397e0d8c422SMohit K. Bhakkad   // To get correct flags for MIPS Architecture
398b9c1b51eSKate Stone   if (arch.GetTriple().getArch() == llvm::Triple::mips64 ||
399b9c1b51eSKate Stone       arch.GetTriple().getArch() == llvm::Triple::mips64el ||
400b9c1b51eSKate Stone       arch.GetTriple().getArch() == llvm::Triple::mips ||
401b9c1b51eSKate Stone       arch.GetTriple().getArch() == llvm::Triple::mipsel)
402e0d8c422SMohit K. Bhakkad     map_anon = 0x800;
403e0d8c422SMohit K. Bhakkad 
40496ad3de5SRobert Flack   if (flags & eMmapFlagsPrivate)
40596ad3de5SRobert Flack     flags_platform |= MAP_PRIVATE;
40696ad3de5SRobert Flack   if (flags & eMmapFlagsAnon)
407e0d8c422SMohit K. Bhakkad     flags_platform |= map_anon;
40837c40af7SEd Maste 
40937c40af7SEd Maste   MmapArgList args({addr, length, prot, flags_platform, fd, offset});
41037c40af7SEd Maste   return args;
41196ad3de5SRobert Flack }
4126e25aeeaSEnrico Granata 
413