1/* 2 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 3 * Copyright (c) 2012 ARM Limited 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 442 unchanged lines hidden (view full) --- 451 } 452 453 return nullptr; 454} 455 456std::string 457Process::checkPathRedirect(const std::string &filename) 458{ |
459 // If the input parameter contains a relative path, convert it. 460 // The target version of the current working directory is fine since 461 // we immediately convert it using redirect paths into a host version. 462 auto abs_path = absolutePath(filename, false); |
463 464 for (auto path : system->redirectPaths) { 465 // Search through the redirect paths to see if a starting substring of 466 // our path falls into any buckets which need to redirected. |
467 if (startswith(abs_path, path->appPath())) { 468 std::string tail = abs_path.substr(path->appPath().size()); |
469 470 // If this path needs to be redirected, search through a list 471 // of targets to see if we can match a valid file (or directory). 472 for (auto host_path : path->hostPaths()) { 473 if (access((host_path + tail).c_str(), R_OK) == 0) { 474 // Return the valid match. 475 return host_path + tail; 476 } 477 } 478 // The path needs to be redirected, but the file or directory 479 // does not exist on the host filesystem. Return the first 480 // host path as a default. 481 return path->hostPaths()[0] + tail; 482 } 483 } 484 485 // The path does not need to be redirected. |
486 return abs_path; |
487} 488 489void 490Process::updateBias() 491{ 492 ObjectFile *interp = objFile->getInterpreter(); 493 494 if (!interp || !interp->relocatable()) --- 40 unchanged lines hidden (view full) --- 535} 536 537std::string 538Process::absolutePath(const std::string &filename, bool host_filesystem) 539{ 540 if (filename.empty() || startswith(filename, "/")) 541 return filename; 542 |
543 // Construct the absolute path given the current working directory for 544 // either the host filesystem or target filesystem. The distinction only 545 // matters if filesystem redirection is utilized in the simulation. |
546 auto path_base = std::string(); 547 if (host_filesystem) { 548 path_base = hostCwd; 549 assert(!hostCwd.empty()); 550 } else { 551 path_base = tgtCwd; 552 assert(!tgtCwd.empty()); 553 } |
554 555 // Add a trailing '/' if the current working directory did not have one. 556 normalize(path_base); 557 558 // Append the filename onto the current working path. 559 auto absolute_path = path_base + filename; 560 561 return absolute_path; --- 162 unchanged lines hidden --- |