diff --git a/src/libs/libAmpr.cpp b/src/libs/libAmpr.cpp index 3c2fc585..57a693d3 100644 --- a/src/libs/libAmpr.cpp +++ b/src/libs/libAmpr.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ struct ResolvedPathInfo { uint32_t file_id = 0xffffffffu; uint64_t file_size = 0; bool is_dir = false; - std::string host_path; + std::filesystem::path host_path; }; static std::mutex g_mutex; @@ -56,7 +57,7 @@ static uint32_t g_next_submission_id = static uint32_t g_next_file_id = 1; static std::unordered_map g_submissions; static std::condition_variable g_submission_cv; -static std::unordered_map g_files; +static std::unordered_map g_files; static std::unordered_map g_file_sizes; static std::unordered_map g_resolved_paths; @@ -113,7 +114,7 @@ static int ReadGuestCString(uint64_t addr, char* out, size_t out_size) { return LibKernel::KERNEL_ERROR_ENAMETOOLONG; } -static bool TryGetHostPath(uint32_t file_id, std::string* out) { +static bool TryGetHostPath(uint32_t file_id, std::filesystem::path* out) { std::scoped_lock lock(g_mutex); const auto it = g_files.find(file_id); if (it == g_files.end()) { @@ -133,7 +134,7 @@ static bool TryGetHostFileSize(uint32_t file_id, uint64_t* out) { return true; } -static int GetHostPathStat(const std::string& host_path, LibKernel::FileSystem::FileStat* st) { +static int GetHostPathStat(const std::filesystem::path& host_path, LibKernel::FileSystem::FileStat* st) { if (st == nullptr) { return LibKernel::KERNEL_ERROR_EINVAL; } @@ -194,7 +195,7 @@ static int ResolveOnePath(const char* guest_path, uint32_t* id, uint64_t* size) if (!found) { const auto real_path = LibKernel::FileSystem::GetRealFilename(path); - info.host_path = Common::PathToString(real_path); + info.host_path = real_path; if (Common::File::IsDirectoryExisting(real_path)) { info.is_dir = true; @@ -225,7 +226,7 @@ static int ResolveOnePath(const char* guest_path, uint32_t* id, uint64_t* size) } } if (log_missing) { - LOGF("\tAPR resolve missing path: %s -> %s\n", guest_path, info.host_path.c_str()); + LOGF("\tAPR resolve missing path: %s -> %s\n", guest_path, Common::PathToString(info.host_path).c_str()); } } @@ -408,7 +409,7 @@ static int KYTY_SYSV_ABI GetFileStat(uint32_t file_id, LibKernel::FileSystem::Fi return KernelSyscallResult(LibKernel::KERNEL_ERROR_EINVAL); } - std::string host_path; + std::filesystem::path host_path; if (!AprShared::TryGetHostPath(file_id, &host_path)) { LOGF("\tAPR stat failed for unknown file id: 0x%08" PRIx32 "\n", file_id); return KernelSyscallResult(LibKernel::KERNEL_ERROR_ENOENT); @@ -430,7 +431,7 @@ static int KYTY_SYSV_ABI GetFileSize(uint32_t file_id, uint64_t* size) { return KernelSyscallResult(LibKernel::KERNEL_ERROR_EFAULT); } - std::string host_path; + std::filesystem::path host_path; if (!AprShared::TryGetHostPath(file_id, &host_path)) { LOGF("\tAPR size failed for unknown file id: 0x%08" PRIx32 "\n", file_id); return KernelSyscallResult(LibKernel::KERNEL_ERROR_ENOENT); @@ -1161,13 +1162,13 @@ static bool AppendCommandRecord(uint64_t command_buffer, CommandBufferState::Com return CommitCommandBufferRecord(command_buffer, &state, record_size); } -static int ReadHostFileToGuest(const std::string& host_path, uint64_t file_offset, +static int ReadHostFileToGuest(const std::filesystem::path& host_path, uint64_t file_offset, uint64_t destination, uint64_t size, uint64_t* bytes_read); static int ExecuteCommand(const CommandBufferState::Command& entry) { if (const auto* payload = std::get_if(&entry.data)) { const auto& command = *payload; - std::string host_path; + std::filesystem::path host_path; if (!AprShared::TryGetHostPath(command.file_id, &host_path)) { LOGF("\tAPR submit failed for unknown file id: 0x%08" PRIx32 "\n", command.file_id); return LibKernel::KERNEL_ERROR_ENOENT; @@ -1178,7 +1179,7 @@ static int ExecuteCommand(const CommandBufferState::Command& entry) { command.size, &bytes_read); if (result != OK) { LOGF("\tAPR submit read failed: id=0x%08" PRIx32 ", result=0x%08" PRIx32 ", path=%s\n", - command.file_id, static_cast(result), host_path.c_str()); + command.file_id, static_cast(result), Common::PathToString(host_path).c_str()); return result; } } else if (const auto* payload = @@ -1380,7 +1381,7 @@ static bool AdvanceCommandBuffer(uint64_t command_buffer, uint64_t record_size) return CommitCommandBufferRecord(command_buffer, &state, record_size); } -static int ReadHostFileToGuest(const std::string& host_path, uint64_t file_offset, +static int ReadHostFileToGuest(const std::filesystem::path& host_path, uint64_t file_offset, uint64_t destination, uint64_t size, uint64_t* bytes_read) { if (bytes_read == nullptr) { return LibKernel::KERNEL_ERROR_EINVAL; @@ -1396,7 +1397,7 @@ static int ReadHostFileToGuest(const std::string& host_path, uint64_t file_offse Common::File file; if (!file.Open(host_path, Common::File::Mode::Read)) { - LOGF("\tAPR read missing host file: %s\n", host_path.c_str()); + LOGF("\tAPR read missing host file: %s\n", Common::PathToString(host_path).c_str()); return LibKernel::KERNEL_ERROR_ENOENT; } const auto file_size = file.Size();