113883Sdavid.hashe@amd.com/*
213883Sdavid.hashe@amd.com * Copyright (c) 2015 Advanced Micro Devices, Inc.
313883Sdavid.hashe@amd.com * All rights reserved.
413883Sdavid.hashe@amd.com *
513883Sdavid.hashe@amd.com * Redistribution and use in source and binary forms, with or without
613883Sdavid.hashe@amd.com * modification, are permitted provided that the following conditions are
713883Sdavid.hashe@amd.com * met: redistributions of source code must retain the above copyright
813883Sdavid.hashe@amd.com * notice, this list of conditions and the following disclaimer;
913883Sdavid.hashe@amd.com * redistributions in binary form must reproduce the above copyright
1013883Sdavid.hashe@amd.com * notice, this list of conditions and the following disclaimer in the
1113883Sdavid.hashe@amd.com * documentation and/or other materials provided with the distribution;
1213883Sdavid.hashe@amd.com * neither the name of the copyright holders nor the names of its
1313883Sdavid.hashe@amd.com * contributors may be used to endorse or promote products derived from
1413883Sdavid.hashe@amd.com * this software without specific prior written permission.
1513883Sdavid.hashe@amd.com *
1613883Sdavid.hashe@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713883Sdavid.hashe@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813883Sdavid.hashe@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913883Sdavid.hashe@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013883Sdavid.hashe@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113883Sdavid.hashe@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213883Sdavid.hashe@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313883Sdavid.hashe@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413883Sdavid.hashe@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513883Sdavid.hashe@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613883Sdavid.hashe@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713883Sdavid.hashe@amd.com *
2813883Sdavid.hashe@amd.com * Authors: David Hashe
2913883Sdavid.hashe@amd.com */
3013883Sdavid.hashe@amd.com
3113883Sdavid.hashe@amd.com#include "sim/redirect_path.hh"
3213883Sdavid.hashe@amd.com
3313883Sdavid.hashe@amd.com#include <unistd.h>
3413883Sdavid.hashe@amd.com
3513883Sdavid.hashe@amd.comstatic std::string
3613883Sdavid.hashe@amd.comnormalizePath(std::string path)
3713883Sdavid.hashe@amd.com{
3813883Sdavid.hashe@amd.com    char buf[PATH_MAX];
3913883Sdavid.hashe@amd.com    std::string gem5_cwd = getcwd(buf, PATH_MAX);
4013883Sdavid.hashe@amd.com
4113883Sdavid.hashe@amd.com    if (!startswith(path, "/")) {
4213883Sdavid.hashe@amd.com        path = realpath((gem5_cwd + "/" + path).c_str(), buf);
4313883Sdavid.hashe@amd.com    }
4413883Sdavid.hashe@amd.com    if (path[path.length()-1] != '/') path.push_back('/');
4513883Sdavid.hashe@amd.com
4613883Sdavid.hashe@amd.com    return path;
4713883Sdavid.hashe@amd.com}
4813883Sdavid.hashe@amd.com
4913883Sdavid.hashe@amd.comRedirectPath::RedirectPath(const RedirectPathParams *p)
5013883Sdavid.hashe@amd.com    : SimObject(p)
5113883Sdavid.hashe@amd.com{
5213883Sdavid.hashe@amd.com    _appPath = normalizePath(p->app_path);
5313883Sdavid.hashe@amd.com
5413883Sdavid.hashe@amd.com    for (auto hp : p->host_paths) {
5513883Sdavid.hashe@amd.com        _hostPaths.push_back(normalizePath(hp));
5613883Sdavid.hashe@amd.com    }
5713883Sdavid.hashe@amd.com}
5813883Sdavid.hashe@amd.com
5913883Sdavid.hashe@amd.comRedirectPath*
6013883Sdavid.hashe@amd.comRedirectPathParams::create()
6113883Sdavid.hashe@amd.com{
6213883Sdavid.hashe@amd.com    return new RedirectPath(this);
6313883Sdavid.hashe@amd.com}
64