Adds the ability to set a rootfs overlay path

This commit is contained in:
Ryan Houdek authored and Stefanos Kornilios Mitsis Poiitidis committed 2020-03-06 07:56:07 +02:00
1 parent 2000bf7baa
commit 6ee7d493f3
5 files changed
+62 -7

No files matched your search

+9
View File
@@ -31,6 +31,15 @@ namespace FEXCore::Config {
}
}
void SetConfig(FEXCore::Context::Context *CTX, ConfigOption Option, std::string const &Config) {
switch (Option) {
case CONFIG_ROOTFSPATH:
CTX->Config.RootFSPath = Config;
break;
default: LogMan::Msg::A("Unknown configuration option");
}
}
uint64_t GetConfig(FEXCore::Context::Context *CTX, ConfigOption Option) {
switch (Option) {
case FEXCore::Config::CONFIG_MULTIBLOCK:
+1
View File
@@ -46,6 +46,7 @@ namespace FEXCore::Context {
uint64_t VirtualMemSize {1ULL << 36};
FEXCore::Config::ConfigCore Core {FEXCore::Config::CONFIG_INTERPRETER};
bool GdbServer {false};
std::string RootFSPath;
// LLVM JIT options
bool LLVM_MemoryValidation {false};
+49 -7
View File
@@ -172,6 +172,14 @@ FileManager::~FileManager() {
}
}
std::string FileManager::GetEmulatedPath(const char *pathname) {
if (pathname[0] != '/' ||
CTX->Config.RootFSPath.empty())
return {};
return CTX->Config.RootFSPath + pathname;
}
uint64_t FileManager::Read(int fd, [[maybe_unused]] void *buf, [[maybe_unused]] size_t count) {
auto FD = FDMap.find(fd);
if (FD == FDMap.end()) {
@@ -211,6 +219,12 @@ uint64_t FileManager::Close(int fd) {
}
uint64_t FileManager::Stat(const char *pathname, void *buf) {
auto Path = GetEmulatedPath(pathname);
if (!Path.empty()) {
uint64_t Result = ::stat(Path.c_str(), reinterpret_cast<struct stat*>(buf));
if (Result != -1)
return Result;
}
return ::stat(pathname, reinterpret_cast<struct stat*>(buf));
}
@@ -241,15 +255,22 @@ uint64_t FileManager::Fstat(int fd, void *buf) {
}
uint64_t FileManager::Lstat(const char *path, void *buf) {
return lstat(path, reinterpret_cast<struct stat*>(buf));
auto Path = GetEmulatedPath(path);
if (!Path.empty()) {
uint64_t Result = ::lstat(Path.c_str(), reinterpret_cast<struct stat*>(buf));
if (Result != -1)
return Result;
}
return ::lstat(path, reinterpret_cast<struct stat*>(buf));
}
uint64_t FileManager::Lseek(int fd, uint64_t offset, int whence) {
auto fdPtr = FDMap.find(fd);
if (fdPtr == FDMap.end()) {
LogMan::Msg::E("XXX: Trying to lseek unknown fd: %d", fd);
return -1LL;
}
return -1LL;
}
return fdPtr->second->lseek(fd, offset, whence);
}
@@ -264,7 +285,14 @@ uint64_t FileManager::Writev(int fd, void *iov, int iovcnt) {
}
uint64_t FileManager::Access(const char *pathname, [[maybe_unused]] int mode) {
return access(pathname, mode);
auto Path = GetEmulatedPath(pathname);
if (!Path.empty()) {
uint64_t Result = ::access(Path.c_str(), mode);
if (Result != -1)
return Result;
}
return ::access(pathname, mode);
}
uint64_t FileManager::Pipe(int pipefd[2]) {
@@ -310,14 +338,20 @@ uint64_t FileManager::Pipe2(int pipefd[2], int flags) {
return Result;
}
uint64_t FileManager::Readlink(const char *pathname, char *buf, size_t bufsiz) {
if (strcmp(pathname, "/proc/self/exe") == 0) {
strncpy(buf, Filename.c_str(), bufsiz);
return std::min(bufsiz, Filename.size());
}
return readlink(pathname, buf, bufsiz);
auto Path = GetEmulatedPath(pathname);
if (!Path.empty()) {
uint64_t Result = ::readlink(Path.c_str(), buf, bufsiz);
if (Result != -1)
return Result;
}
return ::readlink(pathname, buf, bufsiz);
}
uint64_t FileManager::Openat([[maybe_unused]] int dirfs, const char *pathname, int flags, uint32_t mode) {
@@ -329,7 +363,15 @@ uint64_t FileManager::Openat([[maybe_unused]] int dirfs, const char *pathname, i
auto fdPtr = new FD{CTX, fd, pathname, flags, mode};
auto Result = fdPtr->openat(dirfs, pathname, flags, mode);
uint64_t Result = -1;
auto Path = GetEmulatedPath(pathname);
if (!Path.empty()) {
Result = fdPtr->openat(dirfs, Path.c_str(), flags, mode);
}
if (Result == -1)
Result = fdPtr->openat(dirfs, pathname, flags, mode);
if (Result == -1) {
delete fdPtr;
return -1;
+1
View File
@@ -102,5 +102,6 @@ private:
std::unordered_map<int32_t, FD*> FDMap;
std::string Filename;
std::string GetEmulatedPath(const char *pathname);
};
}
+2
View File
@@ -12,6 +12,7 @@ namespace FEXCore::Config {
CONFIG_SINGLESTEP,
CONFIG_GDBSERVER,
CONFIG_ACCURATESTDOUT,
CONFIG_ROOTFSPATH,
};
enum ConfigCore {
@@ -22,5 +23,6 @@ namespace FEXCore::Config {
};
void SetConfig(FEXCore::Context::Context *CTX, ConfigOption Option, uint64_t Config);
void SetConfig(FEXCore::Context::Context *CTX, ConfigOption Option, std::string const &Config);
uint64_t GetConfig(FEXCore::Context::Context *CTX, ConfigOption Option);
}