LookupObject'ing code.

This commit is contained in:
Ben Vanik 2015-05-24 21:37:28 -07:00
parent 018e9a96e1
commit a2b66f9109
8 changed files with 164 additions and 221 deletions

View File

@ -328,18 +328,15 @@ void KernelState::CompleteOverlappedEx(uint32_t overlapped_ptr, X_RESULT result,
XOverlappedSetLength(ptr, length);
X_HANDLE event_handle = XOverlappedGetEvent(ptr);
if (event_handle) {
XEvent* ev = nullptr;
if (XSUCCEEDED(object_table()->GetObject(
event_handle, reinterpret_cast<XObject**>(&ev)))) {
auto ev = object_table()->LookupObject<XEvent>(event_handle);
if (ev) {
ev->Set(0, false);
ev->Release();
}
}
if (XOverlappedGetCompletionRoutine(ptr)) {
X_HANDLE thread_handle = XOverlappedGetContext(ptr);
XThread* thread = nullptr;
if (XSUCCEEDED(object_table()->GetObject(
thread_handle, reinterpret_cast<XObject**>(&thread)))) {
auto thread = object_table()->LookupObject<XThread>(thread_handle);
if (thread) {
uint32_t routine = XOverlappedGetCompletionRoutine(ptr);
uint64_t args[] = {
result, length, overlapped_ptr,
@ -350,8 +347,6 @@ void KernelState::CompleteOverlappedEx(uint32_t overlapped_ptr, X_RESULT result,
// THIS IS WRONG, for testing only:
processor()->Execute(XThread::GetCurrentThread()->thread_state(), routine,
args, xe::countof(args));
thread->Release();
}
}
}

View File

@ -169,8 +169,8 @@ SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("XamEnumerate(%.8X, %d, %.8X, %d, %.8X, %.8X)", handle, zero,
buffer_ptr, buffer_length, item_count_ptr, overlapped_ptr);
XEnumerator* e = nullptr;
if (XFAILED(state->object_table()->GetObject(handle, (XObject**)&e))) {
auto e = state->object_table()->LookupObject<XEnumerator>(handle);
if (!e) {
if (overlapped_ptr) {
state->CompleteOverlappedImmediateEx(overlapped_ptr, 0,
X_ERROR_INVALID_HANDLE, 0);
@ -198,8 +198,6 @@ SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) {
result = X_ERROR_INVALID_PARAMETER;
}
e->Release();
SHIM_SET_RETURN_64(result);
}

View File

@ -104,11 +104,9 @@ SHIM_CALL XMsgCancelIORequest_shim(PPCContext* ppc_state, KernelState* state) {
X_HANDLE event_handle = XOverlappedGetEvent(SHIM_MEM_ADDR(overlapped_ptr));
if (event_handle && wait) {
XEvent* ev = nullptr;
if (XSUCCEEDED(state->object_table()->GetObject(
event_handle, reinterpret_cast<XObject**>(&ev)))) {
auto ev = state->object_table()->LookupObject<XEvent>(event_handle);
if (ev) {
ev->Wait(0, 0, true, nullptr);
ev->Release();
}
}

View File

@ -51,8 +51,8 @@ SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_state, KernelState* state) {
}
// Grab listener.
XNotifyListener* listener = NULL;
if (XFAILED(state->object_table()->GetObject(handle, (XObject**)&listener))) {
auto listener = state->object_table()->LookupObject<XNotifyListener>(handle);
if (!listener) {
SHIM_SET_RETURN_64(0);
return;
}
@ -69,10 +69,6 @@ SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_state, KernelState* state) {
dequeued = listener->DequeueNotification(&id, &param);
}
if (listener) {
listener->Release();
}
if (dequeued) {
SHIM_SET_MEM_32(id_ptr, id);
SHIM_SET_MEM_32(param_ptr, param);

View File

@ -88,12 +88,12 @@ X_STATUS NtCreateFile(PPCContext* ppc_state, KernelState* state,
FileSystem* fs = state->file_system();
std::unique_ptr<Entry> entry;
XFile* root_file = NULL;
object_ref<XFile> root_file;
if (object_attrs->root_directory != 0xFFFFFFFD && // ObDosDevices
object_attrs->root_directory != 0) {
result = state->object_table()->GetObject(object_attrs->root_directory,
(XObject**)&root_file);
assert_true(XSUCCEEDED(result));
root_file = state->object_table()->LookupObject<XFile>(
object_attrs->root_directory);
assert_not_null(root_file);
assert_true(root_file->type() == XObject::Type::kTypeFile);
// Resolve the file using the device the root directory is part of.
@ -242,16 +242,18 @@ SHIM_CALL NtReadFile_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t info = 0;
// Grab event to signal.
XEvent* ev = NULL;
bool signal_event = false;
if (event_handle) {
result = state->object_table()->GetObject(event_handle, (XObject**)&ev);
auto ev = event_handle
? state->object_table()->LookupObject<XEvent>(event_handle)
: object_ref<XEvent>();
if (event_handle && !ev) {
result = X_STATUS_INVALID_HANDLE;
}
// Grab file.
XFile* file = NULL;
if (XSUCCEEDED(result)) {
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (!file) {
result = X_STATUS_INVALID_HANDLE;
}
// Execute read.
@ -300,11 +302,8 @@ SHIM_CALL NtReadFile_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (ev) {
if (signal_event) {
ev->Set(0, false);
}
ev->Release();
if (ev && signal_event) {
ev->Set(0, false);
}
SHIM_SET_RETURN_32(result);
@ -333,16 +332,18 @@ SHIM_CALL NtWriteFile_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t info = 0;
// Grab event to signal.
XEvent* ev = NULL;
bool signal_event = false;
if (event_handle) {
result = state->object_table()->GetObject(event_handle, (XObject**)&ev);
auto ev = event_handle
? state->object_table()->LookupObject<XEvent>(event_handle)
: object_ref<XEvent>();
if (event_handle && !ev) {
result = X_STATUS_INVALID_HANDLE;
}
// Grab file.
XFile* file = NULL;
if (XSUCCEEDED(result)) {
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (!ev) {
result = X_STATUS_INVALID_HANDLE;
}
// Execute write.
@ -383,14 +384,8 @@ SHIM_CALL NtWriteFile_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (file) {
file->Release();
}
if (ev) {
if (signal_event) {
ev->Set(0, false);
}
ev->Release();
if (ev && signal_event) {
ev->Set(0, false);
}
SHIM_SET_RETURN_32(result);
@ -410,11 +405,8 @@ SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_state, KernelState* state) {
uint32_t info = 0;
// Grab file.
XFile* file = NULL;
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
if (XSUCCEEDED(result)) {
result = X_STATUS_SUCCESS;
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (file) {
switch (file_info_class) {
case XFileDispositionInformation: {
// Used to set deletion flag. Which we don't support. Probably?
@ -444,20 +436,15 @@ SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_state, KernelState* state) {
info = 0;
break;
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
if (XFAILED(result)) {
info = 0;
}
if (io_status_block_ptr) {
SHIM_SET_MEM_32(io_status_block_ptr, result); // Status
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (file) {
file->Release();
}
SHIM_SET_RETURN_32(result);
}
@ -476,11 +463,8 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state,
uint32_t info = 0;
// Grab file.
XFile* file = NULL;
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
if (XSUCCEEDED(result)) {
result = X_STATUS_SUCCESS;
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (file) {
switch (file_info_class) {
case XFileInternalInformation:
// Internal unique file pointer. Not sure why anyone would want this.
@ -541,20 +525,15 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state,
info = 0;
break;
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
if (XFAILED(result)) {
info = 0;
}
if (io_status_block_ptr) {
SHIM_SET_MEM_32(io_status_block_ptr, result); // Status
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (file) {
file->Release();
}
SHIM_SET_RETURN_32(result);
}
@ -572,11 +551,11 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state,
X_STATUS result = X_STATUS_NO_SUCH_FILE;
XFile* root_file = NULL;
object_ref<XFile> root_file;
if (attrs.root_directory != 0xFFFFFFFD) { // ObDosDevices
result = state->object_table()->GetObject(attrs.root_directory,
(XObject**)&root_file);
assert_true(XSUCCEEDED(result));
root_file =
state->object_table()->LookupObject<XFile>(attrs.root_directory);
assert_not_null(root_file);
assert_true(root_file->type() == XObject::Type::kTypeFile);
assert_always();
}
@ -612,11 +591,8 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state,
uint32_t info = 0;
// Grab file.
XFile* file = NULL;
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
if (XSUCCEEDED(result)) {
result = X_STATUS_SUCCESS;
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (file) {
switch (fs_info_class) {
case 1: { // FileFsVolumeInformation
auto volume_info = (X_FILE_FS_VOLUME_INFORMATION*)calloc(length, 1);
@ -648,17 +624,19 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state,
free(fs_attribute_info);
break;
}
case 2: // FileFsLabelInformation
case 4: // FileFsDeviceInformation
case 6: // FileFsControlInformation
case 7: // FileFsFullSizeInformation
case 8: // FileFsObjectIdInformation
case 2: // FileFsLabelInformation
case 4: // FileFsDeviceInformation
case 6: // FileFsControlInformation
case 7: // FileFsFullSizeInformation
case 8: // FileFsObjectIdInformation
default:
// Unsupported, for now.
assert_always();
info = 0;
break;
}
} else {
result = X_STATUS_NO_SUCH_FILE;
}
if (XFAILED(result)) {
@ -669,10 +647,6 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state,
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (file) {
file->Release();
}
SHIM_SET_RETURN_32(result);
}
@ -710,9 +684,8 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_UNSUCCESSFUL;
uint32_t info = 0;
XFile* file = NULL;
result = state->object_table()->GetObject(file_handle, (XObject**)&file);
if (XSUCCEEDED(result)) {
auto file = state->object_table()->LookupObject<XFile>(file_handle);
if (file) {
X_FILE_DIRECTORY_INFORMATION* dir_info = (X_FILE_DIRECTORY_INFORMATION*)calloc(length, 1);
result =
file->QueryDirectory(dir_info, length, file_name, restart_scan != 0);
@ -721,6 +694,8 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
info = length;
}
free(dir_info);
} else {
result = X_STATUS_NO_SUCH_FILE;
}
if (XFAILED(result)) {
@ -731,10 +706,6 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
}
if (file) {
file->Release();
}
free(file_name);
SHIM_SET_RETURN_32(result);
}

View File

@ -183,10 +183,9 @@ SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("XexGetModuleSection(%.8X, %s, %.8X, %.8X)", handle, name, data_ptr,
size_ptr);
X_STATUS result = X_STATUS_INVALID_HANDLE;
X_STATUS result = X_STATUS_SUCCESS;
XModule* module = nullptr;
state->object_table()->GetObject(handle, (XObject**)&module);
auto module = state->object_table()->LookupObject<XModule>(handle);
if (module) {
uint32_t section_data = 0;
uint32_t section_size = 0;
@ -195,7 +194,8 @@ SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_state, KernelState* state) {
SHIM_SET_MEM_32(data_ptr, section_data);
SHIM_SET_MEM_32(size_ptr, section_size);
}
module->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -266,15 +266,13 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_state,
X_STATUS result = X_STATUS_INVALID_HANDLE;
XModule* module = NULL;
object_ref<XModule> module;
if (!module_handle) {
module = state->GetExecutableModule().get();
module = state->GetExecutableModule();
} else {
result =
state->object_table()->GetObject(module_handle, (XObject**)&module);
module = state->object_table()->LookupObject<XModule>(module_handle);
}
if (XSUCCEEDED(result)) {
if (module) {
uint32_t ptr;
if (is_string_name) {
ptr = module->GetProcAddressByName(string_name);
@ -291,10 +289,6 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_state,
}
}
if (module) {
module->Release();
}
SHIM_SET_RETURN_32(result);
}

View File

@ -56,11 +56,10 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state,
XELOGD("ObReferenceObjectByHandle(%.8X, %.8X, %.8X)", handle, object_type_ptr,
out_object_ptr);
X_STATUS result = X_STATUS_INVALID_HANDLE;
X_STATUS result = X_STATUS_SUCCESS;
XObject* object = NULL;
result = state->object_table()->GetObject(handle, &object);
if (XSUCCEEDED(result)) {
auto object = state->object_table()->LookupObject<XObject>(handle);
if (object) {
// TODO(benvanik): verify type with object_type_ptr
// TODO(benvanik): get native value, if supported.
@ -74,7 +73,7 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state,
XEvent* ev = (XEvent*)object;
} break;*/
case XObject::kTypeThread: {
XThread* thread = (XThread*)object;
auto thread = object.get<XThread>();
native_ptr = thread->thread_state_ptr();
} break;
default: {
@ -89,7 +88,7 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state,
native_ptr = 0xDEADF00D;
} break;
case 0xD01BBEEF: { // ExThreadObjectType
XThread* thread = (XThread*)object;
auto thread = object.get<XThread>();
native_ptr = thread->thread_state_ptr();
} break;
default: {
@ -98,9 +97,14 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state,
} break;
}
// Caller takes the reference.
// It's released in ObDereferenceObject.
object->Retain();
if (out_object_ptr) {
SHIM_SET_MEM_32(out_object_ptr, native_ptr);
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -142,22 +146,21 @@ SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) {
// So we just fake it and properly reference count but not actually make
// different handles.
X_STATUS result = X_STATUS_INVALID_HANDLE;
X_STATUS result = X_STATUS_SUCCESS;
XObject* obj = 0;
result = state->object_table()->GetObject(handle, &obj);
if (XSUCCEEDED(result)) {
obj->RetainHandle();
uint32_t new_handle = obj->handle();
auto object = state->object_table()->LookupObject<XObject>(handle);
if (object) {
object->RetainHandle();
uint32_t new_handle = object->handle();
if (new_handle_ptr) {
SHIM_SET_MEM_32(new_handle_ptr, new_handle);
}
if (options == 1 /* DUPLICATE_CLOSE_SOURCE */) {
// Always close the source object.
state->object_table()->RemoveHandle(handle);
}
obj->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);

View File

@ -153,18 +153,15 @@ SHIM_CALL NtResumeThread_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("NtResumeThread(%.8X, %.8X)", handle, suspend_count_ptr);
XThread* thread = NULL;
X_STATUS result =
state->object_table()->GetObject(handle, (XObject**)&thread);
uint32_t suspend_count;
if (XSUCCEEDED(result)) {
X_RESULT result = X_STATUS_INVALID_HANDLE;
uint32_t suspend_count = 0;
auto thread = state->object_table()->LookupObject<XThread>(handle);
if (thread) {
result = thread->Resume(&suspend_count);
thread->Release();
}
if (XSUCCEEDED(result)) {
if (suspend_count_ptr) {
SHIM_SET_MEM_32(suspend_count_ptr, suspend_count);
}
if (suspend_count_ptr) {
SHIM_SET_MEM_32(suspend_count_ptr, suspend_count);
}
SHIM_SET_RETURN_32(result);
@ -175,11 +172,13 @@ SHIM_CALL KeResumeThread_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("KeResumeThread(%.8X)", thread_ptr);
X_STATUS result;
X_STATUS result = X_STATUS_SUCCESS;
auto thread =
XObject::GetNativeObject<XThread>(state, SHIM_MEM_ADDR(thread_ptr));
if (thread) {
result = thread->Resume();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -191,19 +190,18 @@ SHIM_CALL NtSuspendThread_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("NtSuspendThread(%.8X, %.8X)", handle, suspend_count_ptr);
XThread* thread = NULL;
X_STATUS result =
state->object_table()->GetObject(handle, (XObject**)&thread);
uint32_t suspend_count;
if (XSUCCEEDED(result)) {
X_RESULT result = X_STATUS_SUCCESS;
uint32_t suspend_count = 0;
auto thread = state->object_table()->LookupObject<XThread>(handle);
if (thread) {
result = thread->Suspend(&suspend_count);
thread->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
if (XSUCCEEDED(result)) {
if (suspend_count_ptr) {
SHIM_SET_MEM_32(suspend_count_ptr, suspend_count);
}
if (suspend_count_ptr) {
SHIM_SET_MEM_32(suspend_count_ptr, suspend_count);
}
SHIM_SET_RETURN_32(result);
@ -250,22 +248,21 @@ SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_state,
int32_t prev_priority = 0;
XThread* thread = NULL;
object_ref<XThread> thread;
if (thread_ptr < 0x1000) {
// They passed in a handle (for some reason)
X_STATUS result =
state->object_table()->GetObject(thread_ptr, (XObject**)&thread);
thread = state->object_table()->LookupObject<XThread>(thread_ptr);
// Log it in case this is the source of any problems in the future
XELOGD("KeSetBasePriorityThread - Interpreting thread ptr as handle!");
} else {
thread = XObject::GetNativeObject<XThread>(state, SHIM_MEM_ADDR(thread_ptr)).release();
thread =
XObject::GetNativeObject<XThread>(state, SHIM_MEM_ADDR(thread_ptr));
}
if (thread) {
prev_priority = thread->QueryPriority();
thread->SetPriority(increment);
thread->Release();
}
SHIM_SET_RETURN_32(prev_priority);
@ -507,15 +504,14 @@ SHIM_CALL NtSetEvent_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XEvent* ev = NULL;
result = state->object_table()->GetObject(event_handle, (XObject**)&ev);
if (XSUCCEEDED(result)) {
auto ev = state->object_table()->LookupObject<XEvent>(event_handle);
if (ev) {
int32_t was_signalled = ev->Set(0, false);
if (previous_state_ptr) {
SHIM_SET_MEM_32(previous_state_ptr, was_signalled);
}
ev->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -547,15 +543,14 @@ SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XEvent* ev = NULL;
result = state->object_table()->GetObject(event_handle, (XObject**)&ev);
if (XSUCCEEDED(result)) {
auto ev = state->object_table()->LookupObject<XEvent>(event_handle);
if (ev) {
int32_t was_signalled = ev->Pulse(0, false);
if (previous_state_ptr) {
SHIM_SET_MEM_32(previous_state_ptr, was_signalled);
}
ev->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -584,11 +579,11 @@ SHIM_CALL NtClearEvent_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XEvent* ev = NULL;
result = state->object_table()->GetObject(event_handle, (XObject**)&ev);
if (XSUCCEEDED(result)) {
auto ev = state->object_table()->LookupObject<XEvent>(event_handle);
if (ev) {
ev->Reset();
ev->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -674,16 +669,16 @@ SHIM_CALL NtReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) {
previous_count_ptr);
X_STATUS result = X_STATUS_SUCCESS;
int32_t previous_count = 0;
XSemaphore* sem = NULL;
result = state->object_table()->GetObject(sem_handle, (XObject**)&sem);
if (XSUCCEEDED(result)) {
int32_t previous_count = sem->ReleaseSemaphore(release_count);
sem->Release();
if (previous_count_ptr) {
SHIM_SET_MEM_32(previous_count_ptr, previous_count);
}
auto sem = state->object_table()->LookupObject<XSemaphore>(sem_handle);
if (sem) {
previous_count = sem->ReleaseSemaphore(release_count);
} else {
result = X_STATUS_INVALID_HANDLE;
}
if (previous_count_ptr) {
SHIM_SET_MEM_32(previous_count_ptr, previous_count);
}
SHIM_SET_RETURN_32(result);
@ -736,11 +731,11 @@ SHIM_CALL NtReleaseMutant_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XMutant* mutant = NULL;
result = state->object_table()->GetObject(mutant_handle, (XObject**)&mutant);
if (XSUCCEEDED(result)) {
auto mutant = state->object_table()->LookupObject<XMutant>(mutant_handle);
if (mutant) {
result = mutant->ReleaseMutant(priority_increment, abandon, wait);
mutant->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -798,12 +793,12 @@ SHIM_CALL NtSetTimerEx_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XTimer* timer = NULL;
result = state->object_table()->GetObject(timer_handle, (XObject**)&timer);
if (XSUCCEEDED(result)) {
auto timer = state->object_table()->LookupObject<XTimer>(timer_handle);
if (timer) {
result = timer->SetTimer(due_time, period_ms, routine, routine_arg,
resume ? true : false);
timer->Release();
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -817,15 +812,14 @@ SHIM_CALL NtCancelTimer_shim(PPCContext* ppc_state, KernelState* state) {
X_STATUS result = X_STATUS_SUCCESS;
XTimer* timer = NULL;
result = state->object_table()->GetObject(timer_handle, (XObject**)&timer);
if (XSUCCEEDED(result)) {
auto timer = state->object_table()->LookupObject<XTimer>(timer_handle);
if (timer) {
result = timer->Cancel();
timer->Release();
if (current_state_ptr) {
SHIM_SET_MEM_32(current_state_ptr, 0);
}
} else {
result = X_STATUS_INVALID_HANDLE;
}
if (current_state_ptr) {
SHIM_SET_MEM_32(current_state_ptr, 0);
}
SHIM_SET_RETURN_32(result);
@ -869,13 +863,13 @@ SHIM_CALL NtWaitForSingleObjectEx_shim(PPCContext* ppc_state,
X_STATUS result = X_STATUS_SUCCESS;
XObject* object = NULL;
result = state->object_table()->GetObject(object_handle, &object);
if (XSUCCEEDED(result)) {
auto object = state->object_table()->LookupObject<XObject>(object_handle);
if (object) {
uint64_t timeout = timeout_ptr ? SHIM_MEM_64(timeout_ptr) : 0;
result =
object->Wait(3, wait_mode, alertable, timeout_ptr ? &timeout : NULL);
object->Release();
object->Wait(3, wait_mode, alertable, timeout_ptr ? &timeout : nullptr);
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);
@ -936,21 +930,21 @@ SHIM_CALL NtWaitForMultipleObjectsEx_shim(PPCContext* ppc_state,
X_STATUS result = X_STATUS_SUCCESS;
XObject** objects = (XObject**)alloca(sizeof(XObject*) * count);
std::vector<object_ref<XObject>> objects(count);
for (uint32_t n = 0; n < count; n++) {
uint32_t object_handle = SHIM_MEM_32(handles_ptr + n * 4);
XObject* object = NULL;
result = state->object_table()->GetObject(object_handle, &object);
if (XFAILED(result)) {
auto object = state->object_table()->LookupObject<XObject>(object_handle);
if (!object) {
SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER);
return;
}
objects[n] = object;
objects[n] = std::move(object);
}
uint64_t timeout = timeout_ptr ? SHIM_MEM_64(timeout_ptr) : 0;
result = XObject::WaitMultiple(count, objects, wait_type, 6, wait_mode,
alertable, timeout_ptr ? &timeout : NULL);
result = XObject::WaitMultiple(
count, reinterpret_cast<XObject**>(objects.data()), wait_type, 6,
wait_mode, alertable, timeout_ptr ? &timeout : nullptr);
SHIM_SET_RETURN_32(result);
}
@ -968,22 +962,16 @@ SHIM_CALL NtSignalAndWaitForSingleObjectEx_shim(PPCContext* ppc_state,
X_STATUS result = X_STATUS_SUCCESS;
XObject* signal_object = NULL;
XObject* wait_object = NULL;
result = state->object_table()->GetObject(signal_handle, &signal_object);
if (XSUCCEEDED(result)) {
result = state->object_table()->GetObject(wait_handle, &wait_object);
}
if (XSUCCEEDED(result)) {
auto signal_object =
state->object_table()->LookupObject<XObject>(signal_handle);
auto wait_object = state->object_table()->LookupObject<XObject>(wait_handle);
if (signal_object && wait_object) {
uint64_t timeout = timeout_ptr ? SHIM_MEM_64(timeout_ptr) : 0;
result = XObject::SignalAndWait(signal_object, wait_object, 3, 1, alertable,
timeout_ptr ? &timeout : NULL);
}
if (signal_object) {
signal_object->Release();
}
if (wait_object) {
wait_object->Release();
result =
XObject::SignalAndWait(signal_object.get(), wait_object.get(), 3, 1,
alertable, timeout_ptr ? &timeout : nullptr);
} else {
result = X_STATUS_INVALID_HANDLE;
}
SHIM_SET_RETURN_32(result);