syscall_emul: Bandage readlink /proc/self/exe
Review Request #3106 - Created Sept. 12, 2015 and submitted
| Information | |
|---|---|
| Joel Hestness | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
Changeset 11092:3f4435aa225e --------------------------- syscall_emul: Bandage readlink /proc/self/exe The recent changeset to readlink() to handle reading the /proc/self/exe link introduces a number of problems. This patch fixes two: 1) Because readlink() called on /proc/self/exe now uses LiveProcess::progName() to find the binary path, it will only get the zeroth parameter of the simulated system command line. However, if a config script also specifies the process' executable, the executable parameter is used to create the LiveProcess rather than the zeroth command line parameter. Thus, the zeroth command line parameter is not necessarily the correct path to the binary executing in the simulated system. To fix this, add a LiveProcess data member, 'executable', which is correctly set during instantiation and returned from progName(). 2) If a config script allows a user to pass a relative path as the zeroth simulated system command line parameter or process executable, readlink() will incorrecly return a relative path when called on '/proc/self/exe'. /proc/self/exe is always set to a full path, so running benchmarks can fail if a relative path is returned. To fix this, clean up the handling of LiveProcess::progName() within readlink() to get the full binary path. NOTE: This patch still leaves the potential problem that host full path to the binary bleeds into the simulated system, potentially causing apparent non-deterministic simulated system execution.
I've had the same problem with the absolute vs. relative path thing, and had just been working around it by specifying an absolute path on the command line. Nice to have a real fix for this, but I'm not convinced by it :).
-
src/sim/process.cc (Diff revision 1) -
why not just reassign params->executable here? then we could get rid of the redundant test in the constructor above
-
src/sim/syscall_emul.cc (Diff revision 1) -
don't you really want to get an absolute path here though? the comment makes it sound like this isn't a complete solution. should we be calling realpath() on the return value from fullPath()? Do we even want to call fullPath(), since we're not using the stored cwd when we open the binary in LiveProcess::create()?
Change Summary:
Addressed Steve's notes.
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 2 (+42 -19) |
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 3 (+43 -19) |
-
src/sim/syscall_emul.cc (Diff revision 3) -
should just be 'readlink() should return the path of the executable'... the stuff about argv[0] is not relevant here
-
src/sim/syscall_emul.cc (Diff revision 3) -
say 'absolute' rather than 'full'
-
src/sim/syscall_emul.cc (Diff revision 3) -
trailing slash on /proc/self/exe/ brings up an interesting point: the test above only compares with the version w/o the trailing slash. at the very least the error message should be consistent...
-
src/sim/syscall_emul.cc (Diff revision 3) -
should be free() rather than delete? might be safer just to allocate a local array of PATH_MAX on the stack
Change Summary:
Addressed Steve's comments
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 4 (+40 -19) |
Ship It!
-
src/sim/syscall_emul.cc (Diff revision 4) -
This comment is inaccurate, and therefore may lead to some confusion. There is no non-determinism, apparent or otherwise. I think 2) is sufficient to describe the problem.
If you do want to add a TODO it should probably simply say that this code should be revisited once an FS redirection scheme is in place, the lack of which is causing the real problem.
