C++17ification.

C++17ification!

- Filesystem interaction now uses std::filesystem::path.
- Usage of const char*, std::string have been changed to
  std::string_view where appropriate.
- Usage of printf-style functions changed to use fmt.
This commit is contained in:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -91,8 +91,7 @@ dword_result_t NtCreateFile(lpdword_t handle_out, dword_t desired_access,
kernel_memory()->TranslateVirtual<X_ANSI_STRING*>(object_attrs->name_ptr);
// Compute path, possibly attrs relative.
std::string target_path =
util::TranslateAnsiString(kernel_memory(), object_name);
auto target_path = util::TranslateAnsiString(kernel_memory(), object_name);
if (object_attrs->root_directory != 0xFFFFFFFD && // ObDosDevices
object_attrs->root_directory != 0) {
auto root_file = kernel_state()->object_table()->LookupObject<XFile>(
@@ -102,8 +101,8 @@ dword_result_t NtCreateFile(lpdword_t handle_out, dword_t desired_access,
// Resolve the file using the device the root directory is part of.
auto device = root_file->device();
target_path = xe::join_paths(
device->mount_path(), xe::join_paths(root_file->path(), target_path));
target_path = xe::utf8::join_guest_paths(
{device->mount_path(), root_file->path(), target_path});
}
// Attempt open (or create).
@@ -686,9 +685,8 @@ dword_result_t NtQueryDirectoryFile(
auto name = util::TranslateAnsiString(kernel_memory(), file_name);
if (file) {
X_FILE_DIRECTORY_INFORMATION dir_info = {0};
result = file->QueryDirectory(file_info_ptr, length,
!name.empty() ? name.c_str() : nullptr,
restart_scan != 0);
result =
file->QueryDirectory(file_info_ptr, length, name, restart_scan != 0);
if (XSUCCEEDED(result)) {
info = length;
}
@@ -741,8 +739,7 @@ dword_result_t NtOpenSymbolicLinkObject(
assert_always();
}
auto pos = target_path.find("\\??\\");
if (pos != target_path.npos && pos == 0) {
if (utf8::starts_with(target_path, "\\??\\")) {
target_path = target_path.substr(4); // Strip the full qualifier
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -11,6 +11,7 @@
#include <vector>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/clock.h"
#include "xenia/base/debugging.h"
#include "xenia/base/logging.h"
@@ -47,15 +48,18 @@ bool XboxkrnlModule::SendPIXCommand(const char* cmd) {
return false;
}
auto scratch = memory_->SystemHeapAlloc(260 + 260);
uint32_t scratch_size = 260 + 260;
auto scratch_ptr = memory_->SystemHeapAlloc(scratch_size);
auto scratch = memory_->TranslateVirtual(scratch_ptr);
std::memset(scratch, 0, scratch_size);
auto response = memory_->TranslateVirtual<const char*>(scratch + 0);
auto command = memory_->TranslateVirtual<char*>(scratch + 260);
auto response = reinterpret_cast<char*>(scratch + 0);
auto command = reinterpret_cast<char*>(scratch + 260);
std::snprintf(command, 260, "PIX!m!%s", cmd);
fmt::format_to_n(command, 259, "PIX!m!{}", cmd);
global_lock.unlock();
uint64_t args[] = {scratch + 260, scratch, 260};
uint64_t args[] = {scratch_ptr + 260, scratch_ptr, 260};
auto result = kernel_state_->processor()->Execute(
XThread::GetCurrentThread()->thread_state(), pix_function_, args,
xe::countof(args));
@@ -64,7 +68,7 @@ bool XboxkrnlModule::SendPIXCommand(const char* cmd) {
XELOGD("PIX(command): %s", cmd);
XELOGD("PIX(response): %s", response);
memory_->SystemHeapFree(scratch);
memory_->SystemHeapFree(scratch_ptr);
if (XSUCCEEDED(result)) {
return true;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -46,7 +46,7 @@ dword_result_t XexGetModuleHandle(lpstring_t module_name,
if (!module_name) {
module = kernel_state()->GetExecutableModule();
} else {
module = kernel_state()->GetModule(module_name);
module = kernel_state()->GetModule(module_name.value());
}
if (!module) {
@@ -69,7 +69,7 @@ dword_result_t XexGetModuleSection(lpvoid_t hmodule, lpstring_t name,
if (module) {
uint32_t section_data = 0;
uint32_t section_size = 0;
result = module->GetSection(name, &section_data, &section_size);
result = module->GetSection(name.value(), &section_data, &section_size);
if (XSUCCEEDED(result)) {
*data_ptr = section_data;
*size_ptr = section_size;
@@ -87,14 +87,14 @@ dword_result_t XexLoadImage(lpstring_t module_name, dword_t module_flags,
X_STATUS result = X_STATUS_NO_SUCH_FILE;
uint32_t hmodule = 0;
auto module = kernel_state()->GetModule(module_name);
auto module = kernel_state()->GetModule(module_name.value());
if (module) {
// Existing module found.
hmodule = module->hmodule_ptr();
result = X_STATUS_SUCCESS;
} else {
// Not found; attempt to load as a user module.
auto user_module = kernel_state()->LoadUserModule(module_name);
auto user_module = kernel_state()->LoadUserModule(module_name.value());
if (user_module) {
// Give up object ownership, this reference will be released by the last
// XexUnloadImage call

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -141,20 +141,18 @@ dword_result_t ObDereferenceObject(dword_t native_ptr) {
}
DECLARE_XBOXKRNL_EXPORT1(ObDereferenceObject, kNone, kImplemented);
dword_result_t ObCreateSymbolicLink(pointer_t<X_ANSI_STRING> path,
pointer_t<X_ANSI_STRING> target) {
auto path_str = util::TranslateAnsiString(kernel_memory(), path);
auto target_str = util::TranslateAnsiString(kernel_memory(), target);
path_str = filesystem::CanonicalizePath(path_str);
target_str = filesystem::CanonicalizePath(target_str);
dword_result_t ObCreateSymbolicLink(pointer_t<X_ANSI_STRING> path_ptr,
pointer_t<X_ANSI_STRING> target_ptr) {
auto path = util::TranslateAnsiString(kernel_memory(), path_ptr);
auto target = util::TranslateAnsiString(kernel_memory(), target_ptr);
path = xe::utf8::canonicalize_guest_path(path);
target = xe::utf8::canonicalize_guest_path(target);
auto pos = path_str.find("\\??\\");
if (pos != path_str.npos && pos == 0) {
path_str = path_str.substr(4); // Strip the full qualifier
if (xe::utf8::starts_with(path, u8"\\??\\")) {
path = path.substr(4); // Strip the full qualifier
}
if (!kernel_state()->file_system()->RegisterSymbolicLink(path_str,
target_str)) {
if (!kernel_state()->file_system()->RegisterSymbolicLink(path, target)) {
return X_STATUS_UNSUCCESSFUL;
}
@@ -162,9 +160,9 @@ dword_result_t ObCreateSymbolicLink(pointer_t<X_ANSI_STRING> path,
}
DECLARE_XBOXKRNL_EXPORT1(ObCreateSymbolicLink, kNone, kImplemented);
dword_result_t ObDeleteSymbolicLink(pointer_t<X_ANSI_STRING> path) {
auto path_str = util::TranslateAnsiString(kernel_memory(), path);
if (!kernel_state()->file_system()->UnregisterSymbolicLink(path_str)) {
dword_result_t ObDeleteSymbolicLink(pointer_t<X_ANSI_STRING> path_ptr) {
auto path = util::TranslateAnsiString(kernel_memory(), path_ptr);
if (!kernel_state()->file_system()->UnregisterSymbolicLink(path)) {
return X_STATUS_UNSUCCESSFUL;
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -165,7 +165,7 @@ DECLARE_XBOXKRNL_EXPORT1(RtlFreeAnsiString, kNone, kImplemented);
// https://msdn.microsoft.com/en-us/library/ff561934
void RtlInitUnicodeString(pointer_t<X_UNICODE_STRING> destination,
lpwstring_t source) {
lpu16string_t source) {
if (source) {
destination->length = (uint16_t)source.value().size() * 2;
destination->maximum_length = (uint16_t)(source.value().size() + 1) * 2;
@@ -229,9 +229,9 @@ dword_result_t RtlUnicodeStringToAnsiString(
// _In_ PCUNICODE_STRING SourceString,
// _In_ BOOLEAN AllocateDestinationString
std::wstring unicode_str =
std::u16string unicode_str =
util::TranslateUnicodeString(kernel_memory(), source_ptr);
std::string ansi_str = xe::to_string(unicode_str);
std::string ansi_str = xe::to_utf8(unicode_str);
if (ansi_str.size() > 0xFFFF - 1) {
return X_STATUS_INVALID_PARAMETER_2;
}

View File

@@ -117,8 +117,8 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
const bool wide) {
int32_t count = 0;
char work[512];
wchar_t wwork[4];
char work8[512];
char16_t work16[4];
struct {
const void* buffer;
@@ -339,13 +339,13 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
auto value = args.get32();
if (!is_wide) {
work[0] = (uint8_t)value;
text.buffer = &work[0];
work8[0] = (uint8_t)value;
text.buffer = &work8[0];
text.length = 1;
text.is_wide = false;
} else {
wwork[0] = (uint16_t)value;
text.buffer = &wwork[0];
work16[0] = (uint16_t)value;
text.buffer = &work16[0];
text.length = 1;
text.is_wide = true;
text.swap_wide = false;
@@ -378,7 +378,7 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
}
if (precision >= 0) {
precision = std::min(precision, (int32_t)xe::countof(work));
precision = std::min(precision, (int32_t)xe::countof(work8));
} else {
precision = 1;
}
@@ -396,7 +396,7 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
prefix.length = 0;
}
char* end = &work[xe::countof(work) - 1];
char* end = &work8[xe::countof(work8) - 1];
char* start = end;
start[0] = '\0';
@@ -471,9 +471,9 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
auto s = format_double(value, precision, c, flags);
auto length = (int32_t)s.size();
assert_true(length < xe::countof(work));
assert_true(length < xe::countof(work8));
auto start = &work[0];
auto start = &work8[0];
auto end = &start[length];
std::memcpy(start, s.c_str(), length);
@@ -637,7 +637,7 @@ int32_t format_core(PPCContext* ppc_context, FormatData& data, ArgList& args,
}
}
} else {
// it's a const wchar_t*
// it's a const char16_t*
auto b = (const uint16_t*)text.buffer;
if (text.swap_wide) {
while (remaining-- > 0) {
@@ -768,15 +768,15 @@ class WideStringFormatData : public FormatData {
}
bool put(uint16_t c) {
output_ << (wchar_t)c;
output_ << (char16_t)c;
return true;
}
std::wstring wstr() const { return output_.str(); }
std::u16string wstr() const { return output_.str(); }
private:
const uint16_t* input_;
std::wostringstream output_;
std::basic_stringstream<char16_t> output_;
};
class WideCountFormatData : public FormatData {

View File

@@ -294,7 +294,7 @@ struct BufferScaling {
};
void AppendParam(StringBuffer* string_buffer, pointer_t<BufferScaling> param) {
string_buffer->AppendFormat(
"%.8X(scale %dx%d -> %dx%d))", param.guest_address(),
"{:08X}(scale {}x{} -> {}x{}))", param.guest_address(),
uint16_t(param->bb_width), uint16_t(param->bb_height),
uint16_t(param->fb_width), uint16_t(param->fb_height));
}