process.cc (13883:f44e21d3aaa7) | process.cc (13906:005b70666608) |
---|---|
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{ | 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. Note, 460 // the return value for this method should always return an absolute 461 // path on the host filesystem. The return value will be used to 462 // open and manipulate the path specified by the input parameter. Since 463 // all filesystem handling in syscall mode is passed through to the host, 464 // we deal only with host paths. 465 auto host_fs_abs_path = absolutePath(filename, true); | 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); |
466 467 for (auto path : system->redirectPaths) { 468 // Search through the redirect paths to see if a starting substring of 469 // our path falls into any buckets which need to redirected. | 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. |
470 if (startswith(host_fs_abs_path, path->appPath())) { 471 std::string tail = host_fs_abs_path.substr(path->appPath().size()); | 467 if (startswith(abs_path, path->appPath())) { 468 std::string tail = abs_path.substr(path->appPath().size()); |
472 473 // If this path needs to be redirected, search through a list 474 // of targets to see if we can match a valid file (or directory). 475 for (auto host_path : path->hostPaths()) { 476 if (access((host_path + tail).c_str(), R_OK) == 0) { 477 // Return the valid match. 478 return host_path + tail; 479 } 480 } 481 // The path needs to be redirected, but the file or directory 482 // does not exist on the host filesystem. Return the first 483 // host path as a default. 484 return path->hostPaths()[0] + tail; 485 } 486 } 487 488 // The path does not need to be redirected. | 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. |
489 return host_fs_abs_path; | 486 return abs_path; |
490} 491 492void 493Process::updateBias() 494{ 495 ObjectFile *interp = objFile->getInterpreter(); 496 497 if (!interp || !interp->relocatable()) --- 40 unchanged lines hidden (view full) --- 538} 539 540std::string 541Process::absolutePath(const std::string &filename, bool host_filesystem) 542{ 543 if (filename.empty() || startswith(filename, "/")) 544 return filename; 545 | 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 |
546 // Verify that the current working directories are initialized properly. 547 // These members should be set initially via params from 'Process.py', 548 // although they may change over time depending on what the application 549 // does during simulation. 550 assert(!tgtCwd.empty()); 551 assert(!hostCwd.empty()); 552 | |
553 // Construct the absolute path given the current working directory for 554 // either the host filesystem or target filesystem. The distinction only 555 // matters if filesystem redirection is utilized in the simulation. | 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. |
556 auto path_base = host_filesystem ? hostCwd : tgtCwd; | 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 } |
557 558 // Add a trailing '/' if the current working directory did not have one. 559 normalize(path_base); 560 561 // Append the filename onto the current working path. 562 auto absolute_path = path_base + filename; 563 564 return absolute_path; --- 162 unchanged lines hidden --- | 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 --- |