Make XThread create a kernel object for itself

This commit is contained in:
Dr. Chat
2015-06-12 19:02:17 -05:00
parent 864e257474
commit 4c9cab4346
3 changed files with 36 additions and 7 deletions

View File

@@ -143,6 +143,18 @@ uint8_t GetFakeCpuNumber(uint8_t proc_mask) {
}
X_STATUS XThread::Create() {
// Thread kernel object
// TODO: This is supposed to be preceded by X_OBJECT_HEADER, need to see if
// that's absolutely necessary.
thread_object_address_ = memory()->SystemHeapAlloc(sizeof(X_THREAD));
if (!thread_object_address_) {
XELOGW("Unable to allocate thread object");
return X_STATUS_NO_MEMORY;
}
// Set native info.
SetNativePointer(thread_object_address_, true);
// Allocate thread state block from heap.
// This is set as r13 for user code and some special inlined Win32 calls
// (like GetLastError/etc) will poke it directly.
@@ -162,9 +174,6 @@ X_STATUS XThread::Create() {
return X_STATUS_NO_MEMORY;
}
// Set native info.
SetNativePointer(thread_state_address_, true);
auto module = kernel_state()->GetExecutableModule();
// Allocate thread scratch.
@@ -276,8 +285,6 @@ X_STATUS XThread::Create() {
xe::store_and_swap<uint32_t>(p + 0x16C, creation_params_.creation_flags);
xe::store_and_swap<uint32_t>(p + 0x17C, 1);
SetNativePointer(thread_state_address_);
X_STATUS return_code = PlatformCreate();
if (XFAILED(return_code)) {
XELOGW("Unable to create platform thread (%.8X)", return_code);