VERY experimental Nintendo Switch 2 emulator
C++
Core: Alter the kernel string functions to use std::string instead of const char*.
Lioncash98fa3f7cba22
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cppindex bdf76e0c22..174d4cd6e4 100644--- a/src/core/hle/kernel/address_arbiter.cpp+++ b/src/core/hle/kernel/address_arbiter.cpp@@ -17,8 +17,8 @@ namespace Kernel {class AddressArbiter : public Object {public:- const char* GetTypeName() const { return "Arbiter"; }- const char* GetName() const { return name.c_str(); }+ std::string GetTypeName() const { return "Arbiter"; }+ std::string GetName() const { return name; }static Kernel::HandleType GetStaticHandleType() { return HandleType::AddressArbiter; }Kernel::HandleType GetHandleType() const { return HandleType::AddressArbiter; }diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cppindex 76b2520dad..5079fcb84a 100644--- a/src/core/hle/kernel/archive.cpp+++ b/src/core/hle/kernel/archive.cpp@@ -31,8 +31,8 @@ enum class FileCommand : u32 {class Archive : public Object {public:- const char* GetTypeName() const { return "Archive"; }- const char* GetName() const { return name.c_str(); }+ std::string GetTypeName() const { return "Archive"; }+ std::string GetName() const { return name; }static Kernel::HandleType GetStaticHandleType() { return HandleType::Archive; }Kernel::HandleType GetHandleType() const { return HandleType::Archive; }@@ -110,7 +110,7 @@ Result MountArchive(Archive* archive) {return -1;}g_archive_map[id_code] = archive->GetHandle();- INFO_LOG(KERNEL, "Mounted archive %s", archive->GetName());+ INFO_LOG(KERNEL, "Mounted archive %s", archive->GetName().c_str());return 0;}diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cppindex 1e417e09c3..64f6a96499 100644--- a/src/core/hle/kernel/event.cpp+++ b/src/core/hle/kernel/event.cpp@@ -16,8 +16,8 @@ namespace Kernel {class Event : public Object {public:- const char* GetTypeName() const { return "Event"; }- const char* GetName() const { return name.c_str(); }+ std::string GetTypeName() const { return "Event"; }+ std::string GetName() const { return name; }static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Event; }Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Event; }diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 7d9bd261ec..96bc63a53a 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -71,8 +71,8 @@ void ObjectPool::List() {for (int i = 0; i < MAX_COUNT; i++) {if (occupied[i]) {if (pool[i]) {- INFO_LOG(KERNEL, "KO %i: %s \"%s\"", i + HANDLE_OFFSET, pool[i]->GetTypeName(),- pool[i]->GetName());+ INFO_LOG(KERNEL, "KO %i: %s \"%s\"", i + HANDLE_OFFSET, pool[i]->GetTypeName().c_str(),+ pool[i]->GetName().c_str());}}}diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex d9afcdd252..6a2e395ed6 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -4,6 +4,7 @@#pragma once+#include <string>#include "common/common.h"typedef u32 Handle;@@ -33,7 +34,6 @@ enum class HandleType : u32 {};enum {- MAX_NAME_LENGTH = 0x100,DEFAULT_STACK_SIZE = 0x4000,};@@ -45,8 +45,8 @@ class Object : NonCopyable {public:virtual ~Object() {}Handle GetHandle() const { return handle; }- virtual const char* GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; }- virtual const char* GetName() const { return "[UNKNOWN KERNEL OBJECT]"; }+ virtual std::string GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; }+ virtual std::string GetName() const { return "[UNKNOWN KERNEL OBJECT]"; }virtual Kernel::HandleType GetHandleType() const = 0;/**diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cppindex 055f503f98..5d7d65dd95 100644--- a/src/core/hle/kernel/mutex.cpp+++ b/src/core/hle/kernel/mutex.cpp@@ -15,8 +15,8 @@ namespace Kernel {class Mutex : public Object {public:- const char* GetTypeName() const { return "Mutex"; }- const char* GetName() const { return name.c_str(); }+ std::string GetTypeName() const { return "Mutex"; }+ std::string GetName() const { return name; }static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Mutex; }Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Mutex; }diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cppindex 52823048f7..2a6a483a10 100644--- a/src/core/hle/kernel/shared_memory.cpp+++ b/src/core/hle/kernel/shared_memory.cpp@@ -11,7 +11,7 @@ namespace Kernel {class SharedMemory : public Object {public:- const char* GetTypeName() const { return "SharedMemory"; }+ std::string GetTypeName() const { return "SharedMemory"; }static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::SharedMemory; }Kernel::HandleType GetHandleType() const { return Kernel::HandleType::SharedMemory; }diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 1d7ded6f6b..554ec97565 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -2,13 +2,12 @@// Licensed under GPLv2// Refer to the license.txt file included.-#include <stdio.h>--#include <list>#include <algorithm>-#include <vector>+#include <cstdio>+#include <list>#include <map>#include <string>+#include <vector>#include "common/common.h"#include "common/thread_queue_list.h"@@ -25,8 +24,8 @@ namespace Kernel {class Thread : public Kernel::Object {public:- const char* GetName() const { return name; }- const char* GetTypeName() const { return "Thread"; }+ std::string GetName() const { return name; }+ std::string GetTypeName() const { return "Thread"; }static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Thread; }Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Thread; }@@ -71,7 +70,7 @@ public:std::vector<Handle> waiting_threads;- char name[Kernel::MAX_NAME_LENGTH + 1];+ std::string name;};// Lists all thread ids that aren't deleted/etc.@@ -336,9 +335,7 @@ Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 priothread->processor_id = processor_id;thread->wait_type = WAITTYPE_NONE;thread->wait_handle = 0;-- strncpy(thread->name, name, Kernel::MAX_NAME_LENGTH);- thread->name[Kernel::MAX_NAME_LENGTH] = '\0';+ thread->name = name;return thread;}diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.hindex dca3097edb..4c7dd07e7b 100644--- a/src/core/hle/service/apt.h+++ b/src/core/hle/service/apt.h@@ -29,7 +29,7 @@ public:* Gets the string port name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "APT:U";}};diff --git a/src/core/hle/service/fs.h b/src/core/hle/service/fs.hindex fabf5ac7ee..36f3697d3f 100644--- a/src/core/hle/service/fs.h+++ b/src/core/hle/service/fs.h@@ -23,7 +23,7 @@ public:* Gets the string port name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "fs:USER";}};diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.hindex fccebef7e5..b25dbb7bcb 100644--- a/src/core/hle/service/gsp.h+++ b/src/core/hle/service/gsp.h@@ -137,7 +137,7 @@ public:* Gets the string port name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "gsp::Gpu";}diff --git a/src/core/hle/service/hid.h b/src/core/hle/service/hid.hindex 81c29eb2eb..b17fcfa865 100644--- a/src/core/hle/service/hid.h+++ b/src/core/hle/service/hid.h@@ -25,7 +25,7 @@ public:* Gets the string port name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "hid:USER";}diff --git a/src/core/hle/service/ndm.h b/src/core/hle/service/ndm.hindex fbe88fb8f7..d5ec28f5ba 100644--- a/src/core/hle/service/ndm.h+++ b/src/core/hle/service/ndm.h@@ -24,7 +24,7 @@ public:* Gets the string port name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "ndm:u";}diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.hindex dcd5257271..cb1ecde319 100644--- a/src/core/hle/service/service.h+++ b/src/core/hle/service/service.h@@ -39,8 +39,8 @@ class Interface : public Kernel::Object {friend class Manager;public:- const char *GetName() const { return GetPortName(); }- const char *GetTypeName() const { return GetPortName(); }+ std::string GetName() const { return GetPortName(); }+ std::string GetTypeName() const { return GetPortName(); }static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Service; }Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Service; }@@ -57,7 +57,7 @@ public:* Gets the string name used by CTROS for a service* @return Port name of service*/- virtual const char *GetPortName() const {+ virtual std::string GetPortName() const {return "[UNKNOWN SERVICE PORT]";}@@ -86,7 +86,7 @@ public:if (itr == m_functions.end()) {ERROR_LOG(OSHLE, "unknown/unimplemented function: port=%s, command=0x%08X",- GetPortName(), cmd_buff[0]);+ GetPortName().c_str(), cmd_buff[0]);// TODO(bunnei): Hack - ignore erroru32* cmd_buff = Service::GetCommandBuffer();@@ -95,7 +95,7 @@ public:}if (itr->second.func == nullptr) {ERROR_LOG(OSHLE, "unimplemented function: port=%s, name=%s",- GetPortName(), itr->second.name.c_str());+ GetPortName().c_str(), itr->second.name.c_str());// TODO(bunnei): Hack - ignore erroru32* cmd_buff = Service::GetCommandBuffer();diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.hindex 81109a2a84..9451472de8 100644--- a/src/core/hle/service/srv.h+++ b/src/core/hle/service/srv.h@@ -22,7 +22,7 @@ public:* Gets the string name used by CTROS for the service* @return Port name of service*/- const char *GetPortName() const {+ std::string GetPortName() const {return "srv:";}diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cppindex 8720bed31d..28f2844eb7 100644--- a/src/core/hle/svc.cpp+++ b/src/core/hle/svc.cpp@@ -92,7 +92,7 @@ Result SendSyncRequest(Handle handle) {Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);_assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");- DEBUG_LOG(SVC, "called handle=0x%08X(%s)", handle, object->GetTypeName());+ DEBUG_LOG(SVC, "called handle=0x%08X(%s)", handle, object->GetTypeName().c_str());bool wait = false;Result res = object->SyncRequest(&wait);@@ -118,8 +118,8 @@ Result WaitSynchronization1(Handle handle, s64 nano_seconds) {Kernel::Object* object = Kernel::g_object_pool.GetFast<Kernel::Object>(handle);- DEBUG_LOG(SVC, "called handle=0x%08X(%s:%s), nanoseconds=%d", handle, object->GetTypeName(),- object->GetName(), nano_seconds);+ DEBUG_LOG(SVC, "called handle=0x%08X(%s:%s), nanoseconds=%d", handle, object->GetTypeName().c_str(),+ object->GetName().c_str(), nano_seconds);_assert_msg_(KERNEL, (object != nullptr), "called, but kernel object is nullptr!");@@ -152,8 +152,8 @@ Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wa_assert_msg_(KERNEL, (object != nullptr), "called handle=0x%08X, but kernel object ""is nullptr!", handles[i]);- DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName(),- object->GetName());+ DEBUG_LOG(SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(),+ object->GetName().c_str());Result res = object->WaitSynchronization(&wait);