Add basic support for threading functions in rexcrt#291
Draft
Minositu wants to merge 37 commits intorexglue:developmentfrom
Draft
Add basic support for threading functions in rexcrt#291Minositu wants to merge 37 commits intorexglue:developmentfrom
Minositu wants to merge 37 commits intorexglue:developmentfrom
Conversation
…tion
Adds an API to install STFS content packages (CON/PIRS/LIVE) from arbitrary host paths. Mounts the package via StfsContainerDevice, extracts all files breadth-first into the standard content directory (0000000000000000/{title_id}/00000002/{filename}/), and writes a .header file with license mask for XAM enumeration.
Also extends WriteContentHeaderFile to write an optional license mask after the XCONTENT_AGGREGATE_DATA struct.
* feat(krnl): Add stubs for xbdm This also resolves the ordinals relating to the xbdm functions. Closes rexglue#191
XGISessionDelete, XSessionStart, XSessionEnd, XSessionSearch, XSessionModify, XSessionSearchEx, XSessionGetDetails, XSessionMigrateHost, XSessionGetInvitationData, XSessionArbitrationRegister, XSessionSearchByID, XSessionModifySkill, XUserResetStatsView, "XUserReadStats, XSessionWriteStats, XSessionFlushStats, XInvalidateGamerTileCache, & XUserGetANID are now documented
tomcl7
reviewed
Apr 18, 2026
| if (!dwStackSize) | ||
| dwStackSize = REX_KERNEL_STATE()->GetExecutableModule()->stack_size(); | ||
| dwStackSize = std::max((uint32_t)0x4000, ((dwStackSize + 0xFFF) & 0xFFFFF000)); | ||
| dwCreationFlags = ((dwCreationFlags >> 2) & 1); |
Member
There was a problem hiding this comment.
Suggested change
| dwCreationFlags = ((dwCreationFlags >> 2) & 1); | |
| u32 x_flags = (dwCreationFlags & 0x4) ? X_CREATE_SUSPENDED : 0; |
Win32 CREATE_SUSPENDED (0x4) -> Xbox X_CREATE_SUSPENDED (0x1).
tomcl7
reviewed
Apr 18, 2026
|
|
||
| auto thread = rex::system::object_ref<rex::system::XThread>( | ||
| new rex::system::XThread(REX_KERNEL_STATE(), dwStackSize, 0, lpStartAddress.guest_address(), | ||
| lpParameter.guest_address(), dwCreationFlags, true, false, |
Member
There was a problem hiding this comment.
Suggested change
| lpParameter.guest_address(), dwCreationFlags, true, false, | |
| lpParameter.guest_address(), x_flags, true, false, |
tomcl7
reviewed
Apr 18, 2026
Comment on lines
+352
to
+353
| if (dwCreationFlags & 0x80) | ||
| return thread->guest_object(); |
Member
There was a problem hiding this comment.
Suggested change
| if (dwCreationFlags & 0x80) | |
| return thread->guest_object(); |
Win32 CreateThread always returns a HANDLE.
tomcl7
reviewed
Apr 18, 2026
|
|
||
| // Helper function in xam to format timeouts. | ||
| uint64_t* XapiFormatTimeOut(uint64_t* TimeOut, uint32_t Millis) { | ||
| if (Millis == -1) |
Member
There was a problem hiding this comment.
Suggested change
| if (Millis == -1) | |
| if (Millis == static_cast<uint32_t>(-1)) |
tomcl7
reviewed
Apr 18, 2026
| rex::system::XThread::GetCurrentThread()->Exit(exitCode); | ||
| } | ||
|
|
||
| // Helper function in xam to format timeouts. |
Member
There was a problem hiding this comment.
Suggested change
| // Helper function in xam to format timeouts. | |
| // Converts a Win32 millisecond timeout to a relative Xbox NT timeout (100 ns units). |
tomcl7
reviewed
Apr 18, 2026
| uint64_t* XapiFormatTimeOut(uint64_t* TimeOut, uint32_t Millis) { | ||
| if (Millis == -1) | ||
| return nullptr; | ||
| *TimeOut = static_cast<uint64_t>(-1) * Millis; |
Member
There was a problem hiding this comment.
Suggested change
| *TimeOut = static_cast<uint64_t>(-1) * Millis; | |
| *TimeOut = static_cast<uint64_t>(-10000LL * static_cast<int64_t>(Millis)); |
Add the missing 10000× factor so timeouts are 100 ns units, not microseconds
tomcl7
reviewed
Apr 18, 2026
| uint64_t timeout_val; | ||
| uint64_t* timeout = XapiFormatTimeOut(&timeout_val, dwMilliseconds); | ||
|
|
||
| uint32_t result = 0; |
Member
There was a problem hiding this comment.
Suggested change
| uint32_t result = 0; | |
| uint32_t result = obj->Wait(3, 1, bAlertable, timeout);; |
tomcl7
reviewed
Apr 18, 2026
Comment on lines
+382
to
+395
| while (!(result & 0x80000000)) { | ||
| result = obj->Wait(3, 1, bAlertable, timeout); | ||
|
|
||
| if (bAlertable && result == X_STATUS_USER_APC) { | ||
| rex::system::XThread::GetCurrentThread()->DeliverAPCs(); | ||
| continue; | ||
| } | ||
|
|
||
| if (!bAlertable || result != X_STATUS_TIMEOUT) { | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| return -1; |
Member
There was a problem hiding this comment.
Suggested change
| while (!(result & 0x80000000)) { | |
| result = obj->Wait(3, 1, bAlertable, timeout); | |
| if (bAlertable && result == X_STATUS_USER_APC) { | |
| rex::system::XThread::GetCurrentThread()->DeliverAPCs(); | |
| continue; | |
| } | |
| if (!bAlertable || result != X_STATUS_TIMEOUT) { | |
| return result; | |
| } | |
| } | |
| return -1; | |
| if (bAlertable && result == X_STATUS_USER_APC) { | |
| rex::system::XThread::GetCurrentThread()->DeliverAPCs(); | |
| } | |
| return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds basic support for the basic thread functions in rexcrt.