@@ -1493,7 +1493,7 @@ void Machine::setup_linux_system_calls()
14931493 // Check if the path is writable (path can be modified)
14941494 if (cpu.machine ().fds ().is_writable_path (path))
14951495 {
1496- int dirfd = AT_FDCWD ;
1496+ int dirfd = cpu. machine (). fds (). current_working_directory_fd () ;
14971497 if (vdirfd != AT_FDCWD)
14981498 {
14991499 dirfd = cpu.machine ().fds ().translate_writable_vfd (vdirfd);
@@ -1715,7 +1715,7 @@ void Machine::setup_linux_system_calls()
17151715 if (!write_flags)
17161716 {
17171717 try {
1718- int pfd = AT_FDCWD ;
1718+ int pfd = cpu. machine (). fds (). current_working_directory_fd () ;
17191719 if (vfd != AT_FDCWD) {
17201720 pfd = cpu.machine ().fds ().translate (vfd);
17211721 }
@@ -1744,7 +1744,7 @@ void Machine::setup_linux_system_calls()
17441744 if (write_flags || regs.rax == (__u64)-1 )
17451745 {
17461746 try {
1747- int pfd = AT_FDCWD ;
1747+ int pfd = cpu. machine (). fds (). current_working_directory_fd () ;
17481748 if (vfd != AT_FDCWD) {
17491749 pfd = cpu.machine ().fds ().translate (vfd);
17501750 }
@@ -1776,25 +1776,23 @@ void Machine::setup_linux_system_calls()
17761776 const auto vpath = regs.rsi ;
17771777 const auto buffer = regs.rdx ;
17781778 int flags = AT_SYMLINK_NOFOLLOW; // regs.r10;
1779- int fd = AT_FDCWD;
1779+ const int vfd = regs.rdi ;
1780+ int fd = cpu.machine ().fds ().current_working_directory_fd ();
17801781 std::string path;
17811782
17821783 try {
17831784 path = cpu.machine ().memcstring (vpath, PATH_MAX);
17841785
1785- if (int (regs. rdi ) >= 0 ) {
1786+ if (vfd != AT_FDCWD ) {
17861787 // Use existing vfd
17871788 fd = cpu.machine ().fds ().translate (int (regs.rdi ));
1788- } else {
1789- // Use AT_FDCWD
1790- fd = AT_FDCWD;
17911789 }
17921790
17931791 if (!cpu.machine ().fds ().is_readable_path (path) && !path.empty ()) {
17941792 regs.rax = -EPERM;
17951793 } else {
17961794 // If path is empty, use AT_EMPTY_PATH to operate on the fd
1797- flags = (path.empty () && fd != AT_FDCWD) ? AT_EMPTY_PATH : 0 ;
1795+ flags = (path.empty () && vfd != AT_FDCWD) ? AT_EMPTY_PATH : 0 ;
17981796
17991797 struct stat64 vstat;
18001798 // Path is in allow-list
@@ -2103,7 +2101,7 @@ void Machine::setup_linux_system_calls()
21032101 const auto mask = regs.r10 ;
21042102 const auto buffer = regs.r8 ;
21052103 std::string path;
2106- int fd = AT_FDCWD ;
2104+ int fd = cpu. machine (). fds (). current_working_directory_fd () ;
21072105
21082106 try {
21092107 path = cpu.machine ().memcstring (vpath, PATH_MAX);
@@ -2139,14 +2137,13 @@ void Machine::setup_linux_system_calls()
21392137 const int vfd = regs.rdi ;
21402138 const auto vpath = regs.rsi ;
21412139 const auto g_buffer = regs.rdx ;
2142- // const int flags = regs.r8;
21432140 std::string path;
21442141 try {
21452142 path = cpu.machine ().memcstring (vpath, PATH_MAX);
21462143 if (!cpu.machine ().fds ().is_readable_path (path)) {
21472144 regs.rax = -EPERM;
21482145 } else {
2149- int fd = vfd ;
2146+ int fd = cpu. machine (). fds (). current_working_directory_fd () ;
21502147 // Translate from vfd when fd != AT_FDCWD
21512148 if (vfd != AT_FDCWD)
21522149 fd = cpu.machine ().fds ().translate (vfd);
@@ -2187,7 +2184,7 @@ void Machine::setup_linux_system_calls()
21872184 times[1 ].tv_nsec = UTIME_NOW;
21882185 }
21892186 // Translate from vfd when fd != AT_FDCWD
2190- int fd = vfd ;
2187+ int fd = cpu. machine (). fds (). current_working_directory_fd () ;
21912188 if (vfd != AT_FDCWD)
21922189 fd = cpu.machine ().fds ().translate_writable_vfd (vfd);
21932190 // Path is in allow-list
0 commit comments