Merge remote-tracking branch 'CookiePLMonster/thread-refcounts' into canary

PR 1506
This commit is contained in:
illusion98 2019-11-16 00:51:16 -05:00
parent b90a00b7e9
commit 53915fd34b
4 changed files with 5 additions and 4 deletions

View File

@ -194,6 +194,7 @@ X_STATUS ObjectTable::RemoveHandle(X_HANDLE handle) {
if (entry->object) { if (entry->object) {
auto object = entry->object; auto object = entry->object;
entry->object = nullptr; entry->object = nullptr;
assert_zero(entry->handle_ref_count);
entry->handle_ref_count = 0; entry->handle_ref_count = 0;
// Walk the object's handles and remove this one. // Walk the object's handles and remove this one.

View File

@ -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;

View File

@ -141,7 +141,6 @@ dword_result_t ExCreateThread(lpdword_t handle_ptr, dword_t stack_size,
// TODO(Gliniak): Temporary solution, requires more research // && !stack_size // TODO(Gliniak): Temporary solution, requires more research // && !stack_size
*handle_ptr = thread->handle(); *handle_ptr = thread->handle();
} else { } else {
thread->RetainHandle();
*handle_ptr = thread->handle(); *handle_ptr = thread->handle();
} }
} }

View File

@ -49,6 +49,7 @@ XObject::XObject(KernelState* kernel_state, Type type)
} }
XObject::~XObject() { XObject::~XObject() {
assert_true(handles_.empty());
assert_zero(pointer_ref_count_); assert_zero(pointer_ref_count_);
if (allocated_guest_object_) { if (allocated_guest_object_) {