Repository navigation
Conversation
simonlindholm
left a comment
Contributor
There was a problem hiding this comment.
Code looks good to me modulo minor comments, but I recall @encounter having some opinions along the lines of preferring fast paths to be written in (32-bit, Windows-targetting, similar to MSVCRT DLLs) C, because asm isn't very maintainable and more fast paths are bound to get added. Is that something that would be viable?
| // RTL_CRITICAL_SECTION | ||
| #define CS_LOCK_COUNT 0x4 | ||
| #define CS_RECURSION_COUNT 0x8 | ||
| #define CS_OWNING_THREAD 0xc |
Contributor
There was a problem hiding this comment.
Don't put right this in the middle of TEB offset macros, and give them some names that indicate that they are struct offsets
| static_assert(offsetof(TEB, Peb) == 0x30, "PEB pointer offset mismatch"); | ||
| static_assert(offsetof(TEB, LastErrorValue) == 0x34, "LastErrorValue offset mismatch"); | ||
| static_assert(offsetof(TEB, LastErrorValue) == TEB_LAST_ERROR, "LastErrorValue offset mismatch"); | ||
| static_assert(offsetof(TEB, ClientId) + sizeof(HANDLE) == TEB_CLIENT_ID_THREAD, |
Contributor
There was a problem hiding this comment.
does
Suggested change
| static_assert(offsetof(TEB, ClientId) + sizeof(HANDLE) == TEB_CLIENT_ID_THREAD, | |
| static_assert(offsetof(TEB, ClientId.UniqueThread) == TEB_CLIENT_ID_THREAD, |
work?
| if (!tibPtr) { | ||
| return false; | ||
| } | ||
| // Guest code reads these straight out of the TEB. |
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.
Runs
GetCurrentThreadId,GetLastError,SetLastError, and the uncontended and recursive paths ofEnterCriticalSectionandLeaveCriticalSectionin guest mode, without going through the host thunk.The generated thunks swap FS and GS and switch stacks to reach the C++ implementation. For calls that only touch the TEB, that costs far more than the work itself. The stubs live in
src/fast_thunks.S. A contended critical section, or a release that has to wake a waiter, falls through to the existing host implementation.installTibForCurrentThreadnow fillsClientIdin the TEB, because theGetCurrentThreadIdstub reads the thread id from there.Does not depend on #157 or #158.
Testing: the repo CI workflow, run on this branch in my fork, passes everything except
test_namedpipe, see below.test_namedpipefails in the Ubuntu 32-bit CI jobs on currentmainas well (test_namedpipe.c:64, seen in a fork CI run of d394386), so that failure is not from this PR.🤖 Generated with Claude Code