syscall_emul: clean up open() code a bit.
This commit is contained in:
parent
b647b48bf4
commit
e232152db6
3 changed files with 14 additions and 7 deletions
|
@ -38,7 +38,8 @@
|
||||||
#include "sim/system.hh"
|
#include "sim/system.hh"
|
||||||
|
|
||||||
int
|
int
|
||||||
Linux::openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc)
|
Linux::openSpecialFile(std::string path, LiveProcess *process,
|
||||||
|
ThreadContext *tc)
|
||||||
{
|
{
|
||||||
DPRINTF(SyscallVerbose, "Opening special file: %s\n", path.c_str());
|
DPRINTF(SyscallVerbose, "Opening special file: %s\n", path.c_str());
|
||||||
if (path.compare(0, 13, "/proc/meminfo") == 0) {
|
if (path.compare(0, 13, "/proc/meminfo") == 0) {
|
||||||
|
@ -51,7 +52,7 @@ Linux::openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
warn("Attempting to open special file: %s. Ignorning. Simulation may"
|
warn("Attempting to open special file: %s. Ignoring. Simulation may"
|
||||||
" take un-expected code path or be non-deterministic until proper"
|
" take un-expected code path or be non-deterministic until proper"
|
||||||
" handling is implemented.\n", path.c_str());
|
" handling is implemented.\n", path.c_str());
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -33,9 +33,10 @@
|
||||||
#include "kern/operatingsystem.hh"
|
#include "kern/operatingsystem.hh"
|
||||||
|
|
||||||
int
|
int
|
||||||
OperatingSystem::openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc)
|
OperatingSystem::openSpecialFile(std::string path, LiveProcess *process,
|
||||||
|
ThreadContext *tc)
|
||||||
{
|
{
|
||||||
warn("Attempting to open special file: %s. Ignorning. Simulation may"
|
warn("Attempting to open special file: %s. Ignoring. Simulation may"
|
||||||
" take un-expected code path or be non-deterministic until proper"
|
" take un-expected code path or be non-deterministic until proper"
|
||||||
" handling is implemented.\n", path.c_str());
|
" handling is implemented.\n", path.c_str());
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -640,17 +640,22 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
||||||
DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
|
DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
|
int local_errno;
|
||||||
if (startswith(path, "/proc/") || startswith(path, "/system/") ||
|
if (startswith(path, "/proc/") || startswith(path, "/system/") ||
|
||||||
startswith(path, "/platform/") || startswith(path, "/sys/")) {
|
startswith(path, "/platform/") || startswith(path, "/sys/")) {
|
||||||
// It's a proc/sys entery and requires special handling
|
// It's a proc/sys entry and requires special handling
|
||||||
fd = OS::openSpecialFile(path, process, tc);
|
fd = OS::openSpecialFile(path, process, tc);
|
||||||
return (fd == -1) ? -1 : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false);
|
local_errno = ENOENT;
|
||||||
} else {
|
} else {
|
||||||
// open the file
|
// open the file
|
||||||
fd = open(path.c_str(), hostFlags, mode);
|
fd = open(path.c_str(), hostFlags, mode);
|
||||||
return (fd == -1) ? -errno : process->alloc_fd(fd,path.c_str(),hostFlags,mode, false);
|
local_errno = errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
return -local_errno;
|
||||||
|
|
||||||
|
return process->alloc_fd(fd, path.c_str(), hostFlags, mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Target sysinfo() handler.
|
/// Target sysinfo() handler.
|
||||||
|
|
Loading…
Reference in a new issue