summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp45
-rw-r--r--src/core/hle/service/set/set.cpp2
-rw-r--r--src/core/hle/service/vi/vi.cpp33
3 files changed, 53 insertions, 27 deletions
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index dbfe06cbc..fdd2fda18 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -24,7 +24,8 @@ namespace Service::FileSystem {
constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000;
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
- std::string_view dir_name) {
+ std::string_view dir_name_) {
+ std::string dir_name(FileUtil::SanitizePath(dir_name_));
if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
return base;
@@ -38,7 +39,8 @@ std::string VfsDirectoryServiceWrapper::GetName() const {
return backing->GetName();
}
-ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 size) const {
+ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
auto file = dir->CreateFile(FileUtil::GetFilename(path));
if (file == nullptr) {
@@ -52,7 +54,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 s
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const {
+ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (path == "/" || path == "\\") {
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
@@ -60,14 +63,15 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const
}
if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr)
return FileSys::ERROR_PATH_NOT_FOUND;
- if (!backing->DeleteFile(FileUtil::GetFilename(path))) {
+ if (!dir->DeleteFile(FileUtil::GetFilename(path))) {
// TODO(DarkLordZach): Find a better error code for this
return ResultCode(-1);
}
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) const {
+ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty())
dir = backing;
@@ -79,7 +83,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path)
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) const {
+ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) {
// TODO(DarkLordZach): Find a better error code for this
@@ -88,7 +93,8 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path)
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path) const {
+ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) {
// TODO(DarkLordZach): Find a better error code for this
@@ -97,8 +103,10 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path,
- const std::string& dest_path) const {
+ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
+ const std::string& dest_path_) const {
+ std::string src_path(FileUtil::SanitizePath(src_path_));
+ std::string dest_path(FileUtil::SanitizePath(dest_path_));
auto src = backing->GetFileRelative(src_path);
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
// Use more-optimized vfs implementation rename.
@@ -130,8 +138,10 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path,
return RESULT_SUCCESS;
}
-ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path,
- const std::string& dest_path) const {
+ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_,
+ const std::string& dest_path_) const {
+ std::string src_path(FileUtil::SanitizePath(src_path_));
+ std::string dest_path(FileUtil::SanitizePath(dest_path_));
auto src = GetDirectoryRelativeWrapped(backing, src_path);
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
// Use more-optimized vfs implementation rename.
@@ -154,8 +164,9 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
return ResultCode(-1);
}
-ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path,
+ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
FileSys::Mode mode) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto npath = path;
while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\'))
npath = npath.substr(1);
@@ -171,7 +182,8 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::
return MakeResult<FileSys::VirtualFile>(file);
}
-ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path) {
+ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, path);
if (dir == nullptr) {
// TODO(DarkLordZach): Find a better error code for this
@@ -188,7 +200,8 @@ u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const {
}
ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
- const std::string& path) const {
+ const std::string& path_) const {
+ std::string path(FileUtil::SanitizePath(path_));
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (dir == nullptr)
return FileSys::ERROR_PATH_NOT_FOUND;
@@ -272,9 +285,9 @@ void RegisterFileSystems() {
sdmc_factory = nullptr;
auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>(
- FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::Write);
+ FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::ReadWrite);
auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>(
- FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::Write);
+ FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::ReadWrite);
auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory));
save_data_factory = std::move(savedata);
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp
index 4195c9067..1651f6122 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -45,6 +45,8 @@ void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.Push(static_cast<u32>(available_language_codes.size()));
+
+ LOG_DEBUG(Service_SET, "called");
}
SET::SET() : ServiceFramework("set") {
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 3a69b85f9..993f1e65a 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -5,6 +5,8 @@
#include <algorithm>
#include <array>
#include <memory>
+#include <type_traits>
+#include <utility>
#include <boost/optional.hpp>
#include "common/alignment.h"
#include "common/math_util.h"
@@ -43,7 +45,9 @@ public:
template <typename T>
T Read() {
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
ASSERT(read_index + sizeof(T) <= buffer.size());
+
T val;
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
read_index += sizeof(T);
@@ -53,7 +57,9 @@ public:
template <typename T>
T ReadUnaligned() {
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
ASSERT(read_index + sizeof(T) <= buffer.size());
+
T val;
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
read_index += sizeof(T);
@@ -87,8 +93,12 @@ public:
template <typename T>
void Write(const T& val) {
- if (buffer.size() < write_index + sizeof(T))
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
+
+ if (buffer.size() < write_index + sizeof(T)) {
buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize);
+ }
+
std::memcpy(buffer.data() + write_index, &val, sizeof(T));
write_index += sizeof(T);
write_index = Common::AlignUp(write_index, 4);
@@ -96,7 +106,9 @@ public:
template <typename T>
void WriteObject(const T& val) {
- u32_le size = static_cast<u32>(sizeof(val));
+ static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
+
+ const u32_le size = static_cast<u32>(sizeof(val));
Write(size);
// TODO(Subv): Support file descriptors.
Write<u32_le>(0); // Fd count.
@@ -176,7 +188,7 @@ private:
class IGBPConnectRequestParcel : public Parcel {
public:
- explicit IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
+ explicit IGBPConnectRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPConnectRequestParcel() override = default;
@@ -223,8 +235,8 @@ private:
class IGBPSetPreallocatedBufferRequestParcel : public Parcel {
public:
- explicit IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer)
- : Parcel(buffer) {
+ explicit IGBPSetPreallocatedBufferRequestParcel(std::vector<u8> buffer)
+ : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPSetPreallocatedBufferRequestParcel() override = default;
@@ -256,7 +268,7 @@ protected:
class IGBPDequeueBufferRequestParcel : public Parcel {
public:
- explicit IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
+ explicit IGBPDequeueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPDequeueBufferRequestParcel() override = default;
@@ -307,7 +319,7 @@ protected:
class IGBPRequestBufferRequestParcel : public Parcel {
public:
- explicit IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
+ explicit IGBPRequestBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPRequestBufferRequestParcel() override = default;
@@ -322,8 +334,7 @@ public:
class IGBPRequestBufferResponseParcel : public Parcel {
public:
- explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer)
- : Parcel(), buffer(buffer) {}
+ explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer) : buffer(buffer) {}
~IGBPRequestBufferResponseParcel() override = default;
protected:
@@ -340,7 +351,7 @@ protected:
class IGBPQueueBufferRequestParcel : public Parcel {
public:
- explicit IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
+ explicit IGBPQueueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPQueueBufferRequestParcel() override = default;
@@ -409,7 +420,7 @@ private:
class IGBPQueryRequestParcel : public Parcel {
public:
- explicit IGBPQueryRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
+ explicit IGBPQueryRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
Deserialize();
}
~IGBPQueryRequestParcel() override = default;