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" 23015d818bSTodd Fiala #include "lldb/Core/Log.h" 24ecc11474SStephen Wilson #include "lldb/Core/PluginManager.h" 25348fb385STodd Fiala #include "lldb/Core/State.h" 26e996fd30SGreg Clayton #include "lldb/Host/FileSpec.h" 2713b18261SZachary Turner #include "lldb/Host/HostInfo.h" 28e996fd30SGreg Clayton #include "lldb/Target/Process.h" 29b9c1b51eSKate Stone #include "lldb/Target/Target.h" 30bf9a7730SZachary Turner #include "lldb/Utility/Error.h" 31bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 32e996fd30SGreg Clayton 33a868c13cSBruce Mitchener // Define these constants from Linux mman.h for use when targeting 3496ad3de5SRobert Flack // remote linux 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)); 48*0e92fbb5SPavel Labath LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, 49*0e92fbb5SPavel Labath arch ? arch->GetArchitectureName() : "<null>", 50*0e92fbb5SPavel 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__) 61dbc6c0bbSGreg Clayton // Only accept "unknown" for the OS if the host is linux and 626a7f3338SBruce Mitchener // it "unknown" wasn't specified (it was just returned because it 63dbc6c0bbSGreg Clayton // was NOT specified) 64015d818bSTodd Fiala case llvm::Triple::OSType::UnknownOS: 6570512317SGreg Clayton create = !arch->TripleOSWasSpecified(); 6670512317SGreg Clayton break; 67dbc6c0bbSGreg Clayton #endif 6870512317SGreg Clayton default: 6970512317SGreg Clayton break; 7070512317SGreg Clayton } 7170512317SGreg Clayton } 72015d818bSTodd Fiala 73*0e92fbb5SPavel Labath LLDB_LOG(log, "create = {0}", create); 74b9c1b51eSKate Stone if (create) { 75615eb7e6SGreg Clayton return PlatformSP(new PlatformLinux(false)); 76015d818bSTodd Fiala } 77615eb7e6SGreg Clayton return PlatformSP(); 78ecc11474SStephen Wilson } 79ecc11474SStephen Wilson 80b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginNameStatic(bool is_host) { 81b9c1b51eSKate Stone if (is_host) { 8257abc5d6SGreg Clayton static ConstString g_host_name(Platform::GetHostPlatformName()); 8357abc5d6SGreg Clayton return g_host_name; 84b9c1b51eSKate Stone } else { 8557abc5d6SGreg Clayton static ConstString g_remote_name("remote-linux"); 8657abc5d6SGreg Clayton return g_remote_name; 8757abc5d6SGreg Clayton } 8828041352SGreg Clayton } 8928041352SGreg Clayton 90b9c1b51eSKate Stone const char *PlatformLinux::GetPluginDescriptionStatic(bool is_host) { 9128041352SGreg Clayton if (is_host) 9228041352SGreg Clayton return "Local Linux user platform plug-in."; 9328041352SGreg Clayton else 9428041352SGreg Clayton return "Remote Linux user platform plug-in."; 95ecc11474SStephen Wilson } 96ecc11474SStephen Wilson 97b9c1b51eSKate Stone ConstString PlatformLinux::GetPluginName() { 9857abc5d6SGreg Clayton return GetPluginNameStatic(IsHost()); 9957abc5d6SGreg Clayton } 10057abc5d6SGreg Clayton 101b9c1b51eSKate Stone void PlatformLinux::Initialize() { 1023c4f89d7STamas Berghammer PlatformPOSIX::Initialize(); 1033c4f89d7STamas Berghammer 104b9c1b51eSKate Stone if (g_initialize_count++ == 0) { 1051c6a1ea9STamas Berghammer #if defined(__linux__) && !defined(__ANDROID__) 10628041352SGreg Clayton PlatformSP default_platform_sp(new PlatformLinux(true)); 10713b18261SZachary Turner default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); 108615eb7e6SGreg Clayton Platform::SetHostPlatform(default_platform_sp); 10928041352SGreg Clayton #endif 110b9c1b51eSKate Stone PluginManager::RegisterPlugin( 111b9c1b51eSKate Stone PlatformLinux::GetPluginNameStatic(false), 11228041352SGreg Clayton PlatformLinux::GetPluginDescriptionStatic(false), 113d65ac229SPavel Labath PlatformLinux::CreateInstance, nullptr); 114ecc11474SStephen Wilson } 115e996fd30SGreg Clayton } 116e996fd30SGreg Clayton 117b9c1b51eSKate Stone void PlatformLinux::Terminate() { 118b9c1b51eSKate Stone if (g_initialize_count > 0) { 119b9c1b51eSKate Stone if (--g_initialize_count == 0) { 12028041352SGreg Clayton PluginManager::UnregisterPlugin(PlatformLinux::CreateInstance); 121e996fd30SGreg Clayton } 12228041352SGreg Clayton } 1233c4f89d7STamas Berghammer 1243c4f89d7STamas Berghammer PlatformPOSIX::Terminate(); 12528041352SGreg Clayton } 126e996fd30SGreg Clayton 127e996fd30SGreg Clayton //------------------------------------------------------------------ 128e996fd30SGreg Clayton /// Default Constructor 129e996fd30SGreg Clayton //------------------------------------------------------------------ 130b9c1b51eSKate Stone PlatformLinux::PlatformLinux(bool is_host) 131b9c1b51eSKate Stone : PlatformPOSIX(is_host) // This is the local host platform 132b9c1b51eSKate Stone {} 133e996fd30SGreg Clayton 134222b937cSEugene Zelenko PlatformLinux::~PlatformLinux() = default; 135e996fd30SGreg Clayton 136b9c1b51eSKate Stone bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx, 137b9c1b51eSKate Stone ArchSpec &arch) { 138b9c1b51eSKate Stone if (IsHost()) { 139e49b8e06SRobert Flack ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); 140b9c1b51eSKate Stone if (hostArch.GetTriple().isOSLinux()) { 141b9c1b51eSKate Stone if (idx == 0) { 142e49b8e06SRobert Flack arch = hostArch; 143e49b8e06SRobert Flack return arch.IsValid(); 144b9c1b51eSKate Stone } else if (idx == 1) { 145e49b8e06SRobert Flack // If the default host architecture is 64-bit, look for a 32-bit 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 195b9c1b51eSKate Stone // vendor by 196b9c1b51eSKate Stone // calling triple.SetVendorName("unknown") so that it is a "unspecified 197b9c1b51eSKate Stone // unknown". 198b9c1b51eSKate Stone // This means when someone calls triple.GetVendorName() it will return an 199b9c1b51eSKate Stone // empty string 200b9c1b51eSKate Stone // which indicates that the vendor can be set when two architectures are 201b9c1b51eSKate Stone // merged 202bb1e283cSTed Woodward 203bb1e283cSTed Woodward // Now set the triple into "arch" and return true 204bb1e283cSTed Woodward arch.SetTriple(triple); 205bb1e283cSTed Woodward return true; 206e49b8e06SRobert Flack } 207e996fd30SGreg Clayton return false; 208e996fd30SGreg Clayton } 209ecc11474SStephen Wilson 210b9c1b51eSKate Stone void PlatformLinux::GetStatus(Stream &strm) { 2113be69dacSDaniel Malea Platform::GetStatus(strm); 212ecc11474SStephen Wilson 213b2f1fb29SVirgile Bello #ifndef LLDB_DISABLE_POSIX 214b743a803SStephane Sezer // Display local kernel information only when we are running in host mode. 215b743a803SStephane Sezer // Otherwise, we would end up printing non-Linux information (when running 21617b45390SJason Molenda // on Mac OS for example). 217b9c1b51eSKate Stone if (IsHost()) { 218b2f1fb29SVirgile Bello struct utsname un; 219b2f1fb29SVirgile Bello 2203be69dacSDaniel Malea if (uname(&un)) 2213be69dacSDaniel Malea return; 2223be69dacSDaniel Malea 2233be69dacSDaniel Malea strm.Printf(" Kernel: %s\n", un.sysname); 2243be69dacSDaniel Malea strm.Printf(" Release: %s\n", un.release); 2253be69dacSDaniel Malea strm.Printf(" Version: %s\n", un.version); 226b743a803SStephane Sezer } 227b2f1fb29SVirgile Bello #endif 228ecc11474SStephen Wilson } 229ecc11474SStephen Wilson 230348fb385STodd Fiala int32_t 231b9c1b51eSKate Stone PlatformLinux::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) { 232348fb385STodd Fiala int32_t resume_count = 0; 23328041352SGreg Clayton 234348fb385STodd Fiala // Always resume past the initial stop when we use eLaunchFlagDebug 235b9c1b51eSKate Stone if (launch_info.GetFlags().Test(eLaunchFlagDebug)) { 236348fb385STodd Fiala // Resume past the stop for the final exec into the true inferior. 237348fb385STodd Fiala ++resume_count; 238348fb385STodd Fiala } 239015d818bSTodd Fiala 240348fb385STodd Fiala // If we're not launching a shell, we're done. 24110687b0eSZachary Turner const FileSpec &shell = launch_info.GetShell(); 24210687b0eSZachary Turner if (!shell) 243348fb385STodd Fiala return resume_count; 244348fb385STodd Fiala 24510687b0eSZachary Turner std::string shell_string = shell.GetPath(); 246348fb385STodd Fiala // We're in a shell, so for sure we have to resume past the shell exec. 247348fb385STodd Fiala ++resume_count; 248348fb385STodd Fiala 249348fb385STodd Fiala // Figure out what shell we're planning on using. 25010687b0eSZachary Turner const char *shell_name = strrchr(shell_string.c_str(), '/'); 251348fb385STodd Fiala if (shell_name == NULL) 25210687b0eSZachary Turner shell_name = shell_string.c_str(); 25328041352SGreg Clayton else 254348fb385STodd Fiala shell_name++; 255348fb385STodd Fiala 256b9c1b51eSKate Stone if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 || 257b9c1b51eSKate Stone strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) { 258348fb385STodd Fiala // These shells seem to re-exec themselves. Add another resume. 259348fb385STodd Fiala ++resume_count; 260ecc11474SStephen Wilson } 26113e8e1c3SJohnny Chen 262348fb385STodd Fiala return resume_count; 263348fb385STodd Fiala } 264348fb385STodd Fiala 265b9c1b51eSKate Stone bool PlatformLinux::CanDebugProcess() { 266b9c1b51eSKate Stone if (IsHost()) { 267b36f9178SPavel Labath return true; 268b9c1b51eSKate Stone } else { 269015d818bSTodd Fiala // If we're connected, we can debug. 270015d818bSTodd Fiala return IsConnected(); 271015d818bSTodd Fiala } 272348fb385STodd Fiala } 273015d818bSTodd Fiala 274b9c1b51eSKate Stone // For local debugging, Linux will override the debug logic to use llgs-launch 275*0e92fbb5SPavel Labath // rather than lldb-launch, llgs-attach. This differs from current lldb-launch, 276*0e92fbb5SPavel Labath // debugserver-attach approach on MacOSX. 27713e8e1c3SJohnny Chen lldb::ProcessSP 278b9c1b51eSKate Stone PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, 279b9c1b51eSKate Stone Target *target, // Can be NULL, if NULL create a new 280b9c1b51eSKate Stone // target, else use existing one 281b9c1b51eSKate Stone Error &error) { 282db264a6dSTamas Berghammer Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 283*0e92fbb5SPavel Labath LLDB_LOG(log, "target {0}", target); 28428041352SGreg Clayton 285348fb385STodd Fiala // If we're a remote host, use standard behavior from parent class. 286348fb385STodd Fiala if (!IsHost()) 2878012cadbSGreg Clayton return PlatformPOSIX::DebugProcess(launch_info, debugger, target, error); 288348fb385STodd Fiala 289348fb385STodd Fiala // 290b9c1b51eSKate Stone // For local debugging, we'll insist on having ProcessGDBRemote create the 291b9c1b51eSKate Stone // process. 292348fb385STodd Fiala // 293348fb385STodd Fiala 294348fb385STodd Fiala ProcessSP process_sp; 295348fb385STodd Fiala 296348fb385STodd Fiala // Make sure we stop at the entry point 297348fb385STodd Fiala launch_info.GetFlags().Set(eLaunchFlagDebug); 298348fb385STodd Fiala 299348fb385STodd Fiala // We always launch the process we are going to debug in a separate process 300348fb385STodd Fiala // group, since then we can handle ^C interrupts ourselves w/o having to worry 301348fb385STodd Fiala // about the target getting them as well. 302348fb385STodd Fiala launch_info.SetLaunchInSeparateProcessGroup(true); 303348fb385STodd Fiala 304348fb385STodd Fiala // Ensure we have a target. 305b9c1b51eSKate Stone if (target == nullptr) { 306*0e92fbb5SPavel Labath LLDB_LOG(log, "creating new target"); 307348fb385STodd Fiala TargetSP new_target_sp; 308a47464b2SZachary Turner error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, 309a47464b2SZachary Turner nullptr, new_target_sp); 310b9c1b51eSKate Stone if (error.Fail()) { 311*0e92fbb5SPavel Labath LLDB_LOG(log, "failed to create new target: {0}", error); 312348fb385STodd Fiala return process_sp; 313348fb385STodd Fiala } 314348fb385STodd Fiala 31528041352SGreg Clayton target = new_target_sp.get(); 316b9c1b51eSKate Stone if (!target) { 317348fb385STodd Fiala error.SetErrorString("CreateTarget() returned nullptr"); 318*0e92fbb5SPavel Labath LLDB_LOG(log, "error: {0}", error); 319348fb385STodd Fiala return process_sp; 320348fb385STodd Fiala } 321348fb385STodd Fiala } 322348fb385STodd Fiala 323348fb385STodd Fiala // Mark target as currently selected target. 32428041352SGreg Clayton debugger.GetTargetList().SetSelectedTarget(target); 32528041352SGreg Clayton 326348fb385STodd Fiala // Now create the gdb-remote process. 327*0e92fbb5SPavel Labath LLDB_LOG(log, "having target create process with gdb-remote plugin"); 328b9c1b51eSKate Stone process_sp = target->CreateProcess( 329b9c1b51eSKate Stone launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); 33028041352SGreg Clayton 331b9c1b51eSKate Stone if (!process_sp) { 332348fb385STodd Fiala error.SetErrorString("CreateProcess() failed for gdb-remote process"); 333*0e92fbb5SPavel Labath LLDB_LOG(log, "error: {0}", error); 334348fb385STodd Fiala return process_sp; 335348fb385STodd Fiala } 336348fb385STodd Fiala 337*0e92fbb5SPavel Labath LLDB_LOG(log, "successfully created process"); 338348fb385STodd Fiala // Adjust launch for a hijacker. 339348fb385STodd Fiala ListenerSP listener_sp; 340b9c1b51eSKate Stone if (!launch_info.GetHijackListener()) { 341*0e92fbb5SPavel Labath LLDB_LOG(log, "setting up hijacker"); 342b9c1b51eSKate Stone listener_sp = 343b9c1b51eSKate Stone Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack"); 344348fb385STodd Fiala launch_info.SetHijackListener(listener_sp); 345583bbb1dSJim Ingham process_sp->HijackProcessEvents(listener_sp); 346348fb385STodd Fiala } 347348fb385STodd Fiala 348348fb385STodd Fiala // Log file actions. 349b9c1b51eSKate Stone if (log) { 350*0e92fbb5SPavel Labath LLDB_LOG(log, "launching process with the following file actions:"); 351348fb385STodd Fiala StreamString stream; 352348fb385STodd Fiala size_t i = 0; 353348fb385STodd Fiala const FileAction *file_action; 354b9c1b51eSKate Stone while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) { 355348fb385STodd Fiala file_action->Dump(stream); 356*0e92fbb5SPavel Labath LLDB_LOG(log, "{0}", stream.GetData()); 357348fb385STodd Fiala stream.Clear(); 358348fb385STodd Fiala } 359348fb385STodd Fiala } 360348fb385STodd Fiala 361348fb385STodd Fiala // Do the launch. 362348fb385STodd Fiala error = process_sp->Launch(launch_info); 363b9c1b51eSKate Stone if (error.Success()) { 364348fb385STodd Fiala // Handle the hijacking of process events. 365b9c1b51eSKate Stone if (listener_sp) { 366b9c1b51eSKate Stone const StateType state = process_sp->WaitForProcessToStop( 367e3e21cfcSPavel Labath llvm::None, NULL, false, listener_sp); 368348fb385STodd Fiala 369*0e92fbb5SPavel Labath LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state); 370348fb385STodd Fiala } 371348fb385STodd Fiala 372b9c1b51eSKate Stone // Hook up process PTY if we have one (which we should for local debugging 373b9c1b51eSKate Stone // with llgs). 374348fb385STodd Fiala int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); 375b9c1b51eSKate Stone if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) { 376348fb385STodd Fiala process_sp->SetSTDIOFileDescriptor(pty_fd); 377*0e92fbb5SPavel Labath LLDB_LOG(log, "hooked up STDIO pty to process"); 378*0e92fbb5SPavel Labath } else 379*0e92fbb5SPavel Labath LLDB_LOG(log, "not using process STDIO pty"); 380b9c1b51eSKate Stone } else { 381*0e92fbb5SPavel Labath LLDB_LOG(log, "process launch failed: {0}", error); 382b9c1b51eSKate Stone // FIXME figure out appropriate cleanup here. Do we delete the target? Do 383b9c1b51eSKate Stone // we delete the process? Does our caller do that? 38428041352SGreg Clayton } 385348fb385STodd Fiala 38628041352SGreg Clayton return process_sp; 38713e8e1c3SJohnny Chen } 3882094dbf4SJason Molenda 389b9c1b51eSKate Stone void PlatformLinux::CalculateTrapHandlerSymbolNames() { 3902094dbf4SJason Molenda m_trap_handlers.push_back(ConstString("_sigtramp")); 3912094dbf4SJason Molenda } 392af245d11STodd Fiala 393b9c1b51eSKate Stone uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch, 394b9c1b51eSKate Stone unsigned flags) { 39596ad3de5SRobert Flack uint64_t flags_platform = 0; 396e0d8c422SMohit K. Bhakkad uint64_t map_anon = MAP_ANON; 397e0d8c422SMohit K. Bhakkad 398e0d8c422SMohit K. Bhakkad // To get correct flags for MIPS Architecture 399b9c1b51eSKate Stone if (arch.GetTriple().getArch() == llvm::Triple::mips64 || 400b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mips64el || 401b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mips || 402b9c1b51eSKate Stone arch.GetTriple().getArch() == llvm::Triple::mipsel) 403e0d8c422SMohit K. Bhakkad map_anon = 0x800; 404e0d8c422SMohit K. Bhakkad 40596ad3de5SRobert Flack if (flags & eMmapFlagsPrivate) 40696ad3de5SRobert Flack flags_platform |= MAP_PRIVATE; 40796ad3de5SRobert Flack if (flags & eMmapFlagsAnon) 408e0d8c422SMohit K. Bhakkad flags_platform |= map_anon; 40996ad3de5SRobert Flack return flags_platform; 41096ad3de5SRobert Flack } 4116e25aeeaSEnrico Granata 412