Jinoh Kang (@iamahuman) commented about server/thread.c:
if (thread->context->status != STATUS_PENDING)
/* If context is in a pending state, we don't know if we will use WoW or native
* context, so store both and discard irrevelant one in select request. */
const int is_pending = thread->context->status == STATUS_PENDING;
unsigned int native_flags = contexts[CTX_NATIVE].flags & req->native_flags;
if (native_flags) /* some regs are always set from the native context */ {
ctx = thread->context->regs[CTX_WOW].machine ? CTX_WOW : CTX_NATIVE;
context = &contexts[ctx];
context_t *ctx = &thread->context->regs[CTX_NATIVE];
copy_context( ctx, &contexts[CTX_NATIVE], native_flags );
ctx->flags |= native_flags; }
else ctx = CTX_PENDING;
if (is_pending || !thread->context->regs[CTX_WOW].machine)
If `ctx_count == 1`, we shall still fully set the native context.
```suggestion:-0+0 if (ctx_count == 1 || is_pending || !thread->context->regs[CTX_WOW].machine) ```
But the code complexity is getting out of hand.
We're needlessly writing `regs[CTX_NATIVE]` twice even as we got rid of `CTX_PENDING` (which made it necessary in the first place). These two native context writes can be merged by tweaking the `native_flags` computation so that it takes both if condition into account.
Since the copied native context flags and wow context flags are mutually exclusive, the wow context flags computation can stay as-is.