Skip to content

Commit 52d1b1e

Browse files
committed
Use virtual CWD when faking lstat
1 parent a4522d1 commit 52d1b1e

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

lib/tinykvm/linux/system_calls.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ void Machine::setup_linux_system_calls(bool unsafe_syscalls)
183183
if (UNLIKELY(!cpu.machine().fds().is_readable_path(path))) {
184184
regs.rax = -EACCES;
185185
cpu.set_registers(regs);
186-
SYSPRINT("STAT to path=%s, data=0x%llX = %lld\n",
186+
SYSPRINT("STAT to path=%s, data=0x%llX = %lld (not readable)\n",
187187
path.c_str(), regs.rsi, regs.rax);
188188
return;
189189
}
190190

191191
struct stat vstat;
192-
const int result = stat(path.c_str(), &vstat);
192+
const int result = syscall(SYS_stat, path.c_str(), &vstat);
193193
regs.rax = (result == 0) ? 0 : -errno;
194194
if (result == 0) {
195195
cpu.machine().copy_to_guest(regs.rsi, &vstat, sizeof(vstat));
@@ -227,14 +227,7 @@ void Machine::setup_linux_system_calls(bool unsafe_syscalls)
227227
if (UNLIKELY(!cpu.machine().fds().is_readable_path(path))) {
228228
// Some paths are extremely annoyingly "required" by some guests
229229
// in order to proceed with things *unrelated* to the path.
230-
std::string cwd(PATH_MAX, '\0');
231-
if (UNLIKELY(getcwd(cwd.data(), cwd.size()) == nullptr)) {
232-
regs.rax = -errno;
233-
cpu.set_registers(regs);
234-
SYSPRINT("lstat(path=%s, data=0x%llX) = %lld\n",
235-
path.c_str(), regs.rsi, regs.rax);
236-
return;
237-
}
230+
const std::string& cwd = cpu.machine().fds().current_working_directory();
238231
const size_t prefixed = cwd.find(path);
239232
if (prefixed != std::string::npos) {
240233
// Make up a fake stat structure
@@ -254,7 +247,7 @@ void Machine::setup_linux_system_calls(bool unsafe_syscalls)
254247
}
255248
} else {
256249
struct stat vstat;
257-
const int result = lstat(path.c_str(), &vstat);
250+
const int result = syscall(SYS_lstat, path.c_str(), &vstat);
258251
if (result == 0) {
259252
cpu.machine().copy_to_guest(regs.rsi, &vstat, sizeof(vstat));
260253
regs.rax = 0;

0 commit comments

Comments
 (0)