[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:
parent
05ef022fd7
commit
728531eff7
|
@ -69,7 +69,7 @@ dword_result_t ObLookupThreadByThreadId(dword_t thread_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retain the object. Will be released in ObDereferenceObject.
|
// Retain the object. Will be released in ObDereferenceObject.
|
||||||
thread->Retain();
|
thread->RetainHandle();
|
||||||
*out_object_ptr = thread->guest_object();
|
*out_object_ptr = thread->guest_object();
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ dword_result_t ObReferenceObjectByHandle(dword_t handle,
|
||||||
|
|
||||||
// Caller takes the reference.
|
// Caller takes the reference.
|
||||||
// It's released in ObDereferenceObject.
|
// It's released in ObDereferenceObject.
|
||||||
object->Retain();
|
object->RetainHandle();
|
||||||
if (out_object_ptr.guest_address()) {
|
if (out_object_ptr.guest_address()) {
|
||||||
*out_object_ptr = native_ptr;
|
*out_object_ptr = native_ptr;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ dword_result_t ObDereferenceObject(dword_t native_ptr) {
|
||||||
auto object = XObject::GetNativeObject<XObject>(
|
auto object = XObject::GetNativeObject<XObject>(
|
||||||
kernel_state(), kernel_memory()->TranslateVirtual(native_ptr));
|
kernel_state(), kernel_memory()->TranslateVirtual(native_ptr));
|
||||||
if (object) {
|
if (object) {
|
||||||
object->Release();
|
object->ReleaseHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue