sim-se: add a faux-filesystem

This change introduces the concept of a faux-filesystem.
The faux-filesystem creates a directory structure in m5out
(or whatever output dir the user specifies) where system calls
may be redirected.

This is useful to avoid non-determinism when reading files
with varying path names (e.g., variations from run-to-run if
the simulation is scheduled on a cluster where paths may change).

Also, this changeset allows circumventing host pseudofiles which
have information specific to the host processor (such as cache
hierarchy or processor information). Bypassing host pseudofiles
can be useful when executing runtimes in the absence of an
operating system kernel since runtimes may try to query standard
files (i.e. /proc or /sys) which are not relevant to an
application executing in syscall emulation mode.

Change-Id: I90821b3b403168b904a662fa98b85def1628621c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/12119
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
David Hashe
2018-04-18 16:36:55 -04:00
committed by Brandon Potter
parent e8d0b755ea
commit 54c77aa055
17 changed files with 755 additions and 94 deletions

View File

@@ -91,8 +91,6 @@ class Process : public SimObject
inline void setpgid(uint64_t pgid) { _pgid = pgid; }
const char *progName() const { return executable.c_str(); }
std::string fullPath(const std::string &filename);
std::string getcwd() const { return cwd; }
/**
* Find an emulated device driver.
@@ -186,9 +184,46 @@ class Process : public SimObject
ObjectFile *objFile;
std::vector<std::string> argv;
std::vector<std::string> envp;
std::string cwd;
std::string executable;
/**
* Return an absolute path given a relative path paired with the current
* working directory of the process running under simulation.
*
* @param path The relative path (generally a filename) that needs the
* current working directory prepended.
* @param host_fs A flag which determines whether to return a
* path for the host filesystem or the filesystem of the process running
* under simulation. Only matters if filesysem redirection is used to
* replace files (or directories) that would normally appear via the
* host filesystem.
* @return String containing an absolute path.
*/
std::string absolutePath(const std::string &path, bool host_fs);
/**
* Redirect file path if it matches any keys initialized by system object.
* @param filename An input parameter containing either a relative path
* or an absolute path. If given a relative path, the path will be
* prepended to the current working directory of the simulation with
* respect to the host filesystem.
* @return String containing an absolute path.
*/
std::string checkPathRedirect(const std::string &filename);
/**
* The cwd members are used to track changes to the current working
* directory for the purpose of executing system calls which depend on
* relative paths (i.e. open, chdir).
*
* The tgt member and host member may differ if the path for the current
* working directory is redirected to point to a different location
* (i.e. `cd /proc` should point to '$(gem5_repo)/m5out/fs/proc'
* instead of '/proc').
*/
std::string tgtCwd;
std::string hostCwd;
// Id of the owner of the process
uint64_t _uid;
uint64_t _euid;