[Kernel] Scope object type enum.

This commit is contained in:
gibbed 2020-11-22 20:21:05 -06:00 committed by Rick Gibbed
parent bdeae25353
commit 164aa8e8ca
33 changed files with 87 additions and 82 deletions

View File

@ -1454,7 +1454,7 @@ void DebugWindow::UpdateCache() {
// Fetch module listing.
// We hold refs so that none are unloaded.
cache_.modules =
object_table->GetObjectsByType<XModule>(XObject::Type::kTypeModule);
object_table->GetObjectsByType<XModule>(XObject::Type::Module);
cache_.thread_debug_infos = processor_->QueryThreadDebugInfos();

View File

@ -358,7 +358,7 @@ void Emulator::Pause() {
auto lock = global_critical_region::AcquireDirect();
auto threads =
kernel_state()->object_table()->GetObjectsByType<kernel::XThread>(
kernel::XObject::kTypeThread);
kernel::XObject::Type::Thread);
auto current_thread = kernel::XThread::IsInThread()
? kernel::XThread::GetCurrentThread()
: nullptr;
@ -388,7 +388,7 @@ void Emulator::Resume() {
auto threads =
kernel_state()->object_table()->GetObjectsByType<kernel::XThread>(
kernel::XObject::kTypeThread);
kernel::XObject::Type::Thread);
for (auto thread : threads) {
if (!thread->can_debugger_suspend()) {
// Don't pause host threads.

View File

@ -763,13 +763,13 @@ bool KernelState::Save(ByteStream* stream) {
for (auto object : objects) {
auto prev_offset = stream->offset();
if (object->is_host_object() || object->type() == XObject::kTypeThread) {
if (object->is_host_object() || object->type() == XObject::Type::Thread) {
// Don't save host objects or save XThreads again
num_objects--;
continue;
}
stream->Write<uint32_t>(object->type());
stream->Write<uint32_t>(static_cast<uint32_t>(object->type()));
if (!object->Save(stream)) {
XELOGD("Did not save object of type {}", object->type());
assert_always();
@ -804,7 +804,7 @@ bool KernelState::Restore(ByteStream* stream) {
uint32_t num_threads = stream->Read<uint32_t>();
XELOGD("Loading {} threads...", num_threads);
for (uint32_t i = 0; i < num_threads; i++) {
auto thread = XObject::Restore(this, XObject::kTypeThread, stream);
auto thread = XObject::Restore(this, XObject::Type::Thread, stream);
if (!thread) {
// Can't continue the restore or we risk misalignment.
assert_always();

View File

@ -51,7 +51,7 @@ class ObjectTable {
object_ref<T> LookupObject(X_HANDLE handle) {
auto object = LookupObject(handle, false);
if (object) {
assert_true(object->type() == T::kType);
assert_true(object->type() == T::kObjectType);
}
auto result = object_ref<T>(reinterpret_cast<T*>(object));
return result;
@ -72,7 +72,7 @@ class ObjectTable {
std::vector<object_ref<T>> GetObjectsByType() {
std::vector<object_ref<T>> results;
GetObjectsByType(
T::kType,
T::kObjectType,
reinterpret_cast<std::vector<object_ref<XObject>>*>(&results));
return results;
}

View File

@ -131,7 +131,7 @@ dword_result_t NtCreateFile(lpdword_t handle_out, dword_t desired_access,
auto root_file = kernel_state()->object_table()->LookupObject<XFile>(
object_attrs->root_directory);
assert_not_null(root_file);
assert_true(root_file->type() == XObject::Type::kTypeFile);
assert_true(root_file->type() == XObject::Type::File);
root_entry = root_file->entry();
}
@ -399,7 +399,7 @@ dword_result_t NtQueryFullAttributesFile(
root_file = kernel_state()->object_table()->LookupObject<XFile>(
obj_attribs->root_directory);
assert_not_null(root_file);
assert_true(root_file->type() == XObject::Type::kTypeFile);
assert_true(root_file->type() == XObject::Type::File);
assert_always();
}

View File

@ -78,22 +78,21 @@ DECLARE_XBOXKRNL_EXPORT1(ObLookupThreadByThreadId, kNone, kImplemented);
dword_result_t ObReferenceObjectByHandle(dword_t handle,
dword_t object_type_ptr,
lpdword_t out_object_ptr) {
const static std::unordered_map<XObject::Type, uint32_t> obj_type_match = {
{XObject::kTypeEvent, 0xD00EBEEF},
{XObject::kTypeSemaphore, 0xD017BEEF},
{XObject::kTypeThread, 0xD01BBEEF}};
// These values come from how Xenia handles uninitialized kernel data exports.
// D###BEEF where ### is the ordinal.
const static std::unordered_map<XObject::Type, uint32_t> object_types = {
{XObject::Type::Event, 0xD00EBEEF},
{XObject::Type::Semaphore, 0xD017BEEF},
{XObject::Type::Thread, 0xD01BBEEF}};
auto object = kernel_state()->object_table()->LookupObject<XObject>(handle);
if (!object) {
return X_STATUS_INVALID_HANDLE;
}
uint32_t native_ptr = object->guest_object();
auto obj_type = obj_type_match.find(object->type());
if (obj_type != obj_type_match.end()) {
if (object_type_ptr && object_type_ptr != obj_type->second) {
auto object_type = object_types.find(object->type());
if (object_type != object_types.end()) {
if (object_type_ptr && object_type_ptr != object_type->second) {
return X_STATUS_OBJECT_TYPE_MISMATCH;
}
} else {

View File

@ -432,7 +432,7 @@ dword_result_t NtCreateEvent(lpdword_t handle_ptr,
auto existing_object =
LookupNamedObject<XEvent>(kernel_state(), obj_attributes_ptr);
if (existing_object) {
if (existing_object->type() == XObject::kTypeEvent) {
if (existing_object->type() == XObject::Type::Event) {
if (handle_ptr) {
existing_object->RetainHandle();
*handle_ptr = existing_object->handle();
@ -559,7 +559,7 @@ dword_result_t NtCreateSemaphore(lpdword_t handle_ptr,
auto existing_object =
LookupNamedObject<XSemaphore>(kernel_state(), obj_attributes_ptr);
if (existing_object) {
if (existing_object->type() == XObject::kTypeSemaphore) {
if (existing_object->type() == XObject::Type::Semaphore) {
if (handle_ptr) {
existing_object->RetainHandle();
*handle_ptr = existing_object->handle();
@ -613,7 +613,7 @@ dword_result_t NtCreateMutant(lpdword_t handle_out,
auto existing_object = LookupNamedObject<XMutant>(
kernel_state(), obj_attributes.guest_address());
if (existing_object) {
if (existing_object->type() == XObject::kTypeMutant) {
if (existing_object->type() == XObject::Type::Mutant) {
if (handle_out) {
existing_object->RetainHandle();
*handle_out = existing_object->handle();
@ -674,7 +674,7 @@ dword_result_t NtCreateTimer(lpdword_t handle_ptr, lpvoid_t obj_attributes_ptr,
auto existing_object =
LookupNamedObject<XTimer>(kernel_state(), obj_attributes_ptr);
if (existing_object) {
if (existing_object->type() == XObject::kTypeTimer) {
if (existing_object->type() == XObject::Type::Timer) {
if (handle_ptr) {
existing_object->RetainHandle();
*handle_ptr = existing_object->handle();

View File

@ -14,7 +14,7 @@ namespace kernel {
XEnumerator::XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size)
: XObject(kernel_state, kType),
: XObject(kernel_state, kObjectType),
items_per_enumerate_(items_per_enumerate),
item_size_(item_size) {}

View File

@ -21,7 +21,7 @@ namespace kernel {
class XEnumerator : public XObject {
public:
static const Type kType = kTypeEnumerator;
static const XObject::Type kObjectType = XObject::Type::Enumerator;
XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size);

View File

@ -15,7 +15,8 @@
namespace xe {
namespace kernel {
XEvent::XEvent(KernelState* kernel_state) : XObject(kernel_state, kType) {}
XEvent::XEvent(KernelState* kernel_state)
: XObject(kernel_state, kObjectType) {}
XEvent::~XEvent() = default;

View File

@ -25,7 +25,7 @@ static_assert_size(X_KEVENT, 0x10);
class XEvent : public XObject {
public:
static const Type kType = kTypeEvent;
static const XObject::Type kObjectType = XObject::Type::Event;
explicit XEvent(KernelState* kernel_state);
~XEvent() override;

View File

@ -22,11 +22,13 @@ namespace xe {
namespace kernel {
XFile::XFile(KernelState* kernel_state, vfs::File* file, bool synchronous)
: XObject(kernel_state, kType), file_(file), is_synchronous_(synchronous) {
: XObject(kernel_state, kObjectType),
file_(file),
is_synchronous_(synchronous) {
async_event_ = threading::Event::CreateAutoResetEvent(false);
}
XFile::XFile() : XObject(kType) {
XFile::XFile() : XObject(kObjectType) {
async_event_ = threading::Event::CreateAutoResetEvent(false);
}

View File

@ -75,7 +75,7 @@ class X_FILE_DIRECTORY_INFORMATION {
class XFile : public XObject {
public:
static const Type kType = kTypeFile;
static const XObject::Type kObjectType = XObject::Type::File;
XFile(KernelState* kernel_state, vfs::File* file, bool synchronous);
~XFile() override;

View File

@ -13,7 +13,7 @@ namespace xe {
namespace kernel {
XIOCompletion::XIOCompletion(KernelState* kernel_state)
: XObject(kernel_state, kType) {
: XObject(kernel_state, kObjectType) {
notification_semaphore_ = threading::Semaphore::Create(0, kMaxNotifications);
}

View File

@ -21,7 +21,7 @@ namespace kernel {
class XIOCompletion : public XObject {
public:
static const Type kType = kTypeIOCompletion;
static const XObject::Type kObjectType = XObject::Type::IOCompletion;
explicit XIOCompletion(KernelState* kernel_state);
~XIOCompletion() override;

View File

@ -19,7 +19,7 @@ namespace xe {
namespace kernel {
XModule::XModule(KernelState* kernel_state, ModuleType module_type)
: XObject(kernel_state, kType),
: XObject(kernel_state, kObjectType),
module_type_(module_type),
processor_module_(nullptr),
hmodule_ptr_(0) {

View File

@ -57,7 +57,7 @@ class XModule : public XObject {
kUserModule = 1,
};
static const Type kType = kTypeModule;
static const XObject::Type kObjectType = XObject::Type::Module;
XModule(KernelState* kernel_state, ModuleType module_type);
virtual ~XModule();

View File

@ -17,9 +17,10 @@
namespace xe {
namespace kernel {
XMutant::XMutant() : XObject(kType) {}
XMutant::XMutant(KernelState* kernel_state)
: XObject(kernel_state, kObjectType) {}
XMutant::XMutant(KernelState* kernel_state) : XObject(kernel_state, kType) {}
XMutant::XMutant() : XObject(kObjectType) {}
XMutant::~XMutant() = default;

View File

@ -20,7 +20,7 @@ class XThread;
class XMutant : public XObject {
public:
static const Type kType = kTypeMutant;
static const XObject::Type kObjectType = XObject::Type::Mutant;
explicit XMutant(KernelState* kernel_state);
~XMutant() override;

View File

@ -16,7 +16,7 @@ namespace xe {
namespace kernel {
XNotifyListener::XNotifyListener(KernelState* kernel_state)
: XObject(kernel_state, kType) {}
: XObject(kernel_state, kObjectType) {}
XNotifyListener::~XNotifyListener() {}

View File

@ -23,7 +23,7 @@ namespace kernel {
class XNotifyListener : public XObject {
public:
static const Type kType = kTypeNotifyListener;
static const XObject::Type kObjectType = XObject::Type::NotifyListener;
explicit XNotifyListener(KernelState* kernel_state);
~XNotifyListener() override;

View File

@ -129,33 +129,33 @@ bool XObject::RestoreObject(ByteStream* stream) {
object_ref<XObject> XObject::Restore(KernelState* kernel_state, Type type,
ByteStream* stream) {
switch (type) {
case kTypeEnumerator:
case Type::Enumerator:
break;
case kTypeEvent:
case Type::Event:
return XEvent::Restore(kernel_state, stream);
case kTypeFile:
case Type::File:
return XFile::Restore(kernel_state, stream);
case kTypeIOCompletion:
case Type::IOCompletion:
break;
case kTypeModule:
case Type::Module:
return XModule::Restore(kernel_state, stream);
case kTypeMutant:
case Type::Mutant:
return XMutant::Restore(kernel_state, stream);
case kTypeNotifyListener:
case Type::NotifyListener:
return XNotifyListener::Restore(kernel_state, stream);
case kTypeSemaphore:
case Type::Semaphore:
return XSemaphore::Restore(kernel_state, stream);
case kTypeSession:
case Type::Session:
break;
case kTypeSocket:
case Type::Socket:
break;
case kTypeSymbolicLink:
case Type::SymbolicLink:
return XSymbolicLink::Restore(kernel_state, stream);
case kTypeThread:
case Type::Thread:
return XThread::Restore(kernel_state, stream);
case kTypeTimer:
case Type::Timer:
break;
case kTypeUndefined:
case Type::Undefined:
break;
}

View File

@ -116,21 +116,21 @@ class XObject {
// one with 0x8A... which causes crash
static constexpr uint32_t kHandleBase = 0xF8000000;
enum Type {
kTypeUndefined,
kTypeEnumerator,
kTypeEvent,
kTypeFile,
kTypeIOCompletion,
kTypeModule,
kTypeMutant,
kTypeNotifyListener,
kTypeSemaphore,
kTypeSession,
kTypeSocket,
kTypeSymbolicLink,
kTypeThread,
kTypeTimer,
enum class Type : uint32_t {
Undefined,
Enumerator,
Event,
File,
IOCompletion,
Module,
Mutant,
NotifyListener,
Semaphore,
Session,
Socket,
SymbolicLink,
Thread,
Timer,
};
XObject(Type type);

View File

@ -16,7 +16,7 @@ namespace xe {
namespace kernel {
XSemaphore::XSemaphore(KernelState* kernel_state)
: XObject(kernel_state, kTypeSemaphore) {}
: XObject(kernel_state, kObjectType) {}
XSemaphore::~XSemaphore() = default;

View File

@ -25,7 +25,7 @@ static_assert_size(X_KSEMAPHORE, 0x14);
class XSemaphore : public XObject {
public:
static const Type kType = kTypeSemaphore;
static const XObject::Type kObjectType = XObject::Type::Semaphore;
explicit XSemaphore(KernelState* kernel_state);
~XSemaphore() override;

View File

@ -31,10 +31,11 @@
namespace xe {
namespace kernel {
XSocket::XSocket(KernelState* kernel_state) : XObject(kernel_state, kType) {}
XSocket::XSocket(KernelState* kernel_state)
: XObject(kernel_state, kObjectType) {}
XSocket::XSocket(KernelState* kernel_state, uint64_t native_handle)
: XObject(kernel_state, kType), native_handle_(native_handle) {}
: XObject(kernel_state, kObjectType), native_handle_(native_handle) {}
XSocket::~XSocket() { Close(); }

View File

@ -66,7 +66,7 @@ struct N_XSOCKADDR_IN {
class XSocket : public XObject {
public:
static const Type kType = kTypeSocket;
static const XObject::Type kObjectType = XObject::Type::Socket;
enum AddressFamily {
AF_INET = 2,

View File

@ -16,9 +16,9 @@ namespace xe {
namespace kernel {
XSymbolicLink::XSymbolicLink(KernelState* kernel_state)
: XObject(kernel_state, kType), path_(), target_() {}
: XObject(kernel_state, kObjectType), path_(), target_() {}
XSymbolicLink::XSymbolicLink() : XObject(kType), path_(), target_() {}
XSymbolicLink::XSymbolicLink() : XObject(kObjectType), path_(), target_() {}
XSymbolicLink::~XSymbolicLink() {}

View File

@ -23,7 +23,7 @@ namespace kernel {
class XSymbolicLink : public XObject {
public:
static const Type kType = kTypeSymbolicLink;
static const XObject::Type kObjectType = XObject::Type::SymbolicLink;
explicit XSymbolicLink(KernelState* kernel_state);
~XSymbolicLink() override;

View File

@ -48,13 +48,13 @@ using xe::cpu::ppc::PPCOpcode;
uint32_t next_xthread_id_ = 0;
XThread::XThread(KernelState* kernel_state)
: XObject(kernel_state, kType), guest_thread_(true) {}
: XObject(kernel_state, kObjectType), guest_thread_(true) {}
XThread::XThread(KernelState* kernel_state, uint32_t stack_size,
uint32_t xapi_thread_startup, uint32_t start_address,
uint32_t start_context, uint32_t creation_flags,
bool guest_thread, bool main_thread)
: XObject(kernel_state, kType),
: XObject(kernel_state, kObjectType),
thread_id_(++next_xthread_id_),
guest_thread_(guest_thread),
main_thread_(main_thread),

View File

@ -106,7 +106,7 @@ static_assert_size(X_KTHREAD, 0xAB0);
class XThread : public XObject, public cpu::Thread {
public:
static const Type kType = kTypeThread;
static const XObject::Type kObjectType = XObject::Type::Thread;
struct CreationParams {
uint32_t stack_size;

View File

@ -17,7 +17,8 @@
namespace xe {
namespace kernel {
XTimer::XTimer(KernelState* kernel_state) : XObject(kernel_state, kType) {}
XTimer::XTimer(KernelState* kernel_state)
: XObject(kernel_state, kObjectType) {}
XTimer::~XTimer() = default;

View File

@ -21,7 +21,7 @@ class XThread;
class XTimer : public XObject {
public:
static const Type kType = kTypeTimer;
static const XObject::Type kObjectType = XObject::Type::Timer;
explicit XTimer(KernelState* kernel_state);
~XTimer() override;