[Kernel] Operate on handle refcounts in Ob funcs

Although this seems counter-intuitive, operating on handle
reference counters in
- ObLookupThreadByThreadId
- ObReferenceObjectByHandle
- ObDereferenceObject
allows to cleanly clean up handles for resources created elsewhere
and destructed by ObDereferenceObject (for example, threads with 0x80
creation flag). Operating on pointer reference counters alone
would leave a stray handle in the slots list.
This commit is contained in:
Silent 2019-11-15 23:08:37 +01:00 committed by Rick Gibbed
parent 05ef022fd7
commit 728531eff7
1 changed files with 3 additions and 3 deletions

View File

@ -69,7 +69,7 @@ dword_result_t ObLookupThreadByThreadId(dword_t thread_id,
}
// Retain the object. Will be released in ObDereferenceObject.
thread->Retain();
thread->RetainHandle();
*out_object_ptr = thread->guest_object();
return X_STATUS_SUCCESS;
}
@ -133,7 +133,7 @@ dword_result_t ObReferenceObjectByHandle(dword_t handle,
// Caller takes the reference.
// It's released in ObDereferenceObject.
object->Retain();
object->RetainHandle();
if (out_object_ptr.guest_address()) {
*out_object_ptr = native_ptr;
}
@ -169,7 +169,7 @@ dword_result_t ObDereferenceObject(dword_t native_ptr) {
auto object = XObject::GetNativeObject<XObject>(
kernel_state(), kernel_memory()->TranslateVirtual(native_ptr));
if (object) {
object->Release();
object->ReleaseHandle();
}
return 0;