On Mon Aug 28 22:58:19 2023 +0000, Jinoh Kang wrote:
Something like this should be more readable:
if (thread->context && !get_error()) { const unsigned int native_flags = contexts[CTX_NATIVE].flags & req->native_flags; const int is_pending = thread->context->status == STATUS_PENDING; const int selected_ctx = ctx_count == 2 && thread->context->regs[CTX_WOW].machine ? CTX_WOW : CTX_NATIVE; unsigned int i; for (i = 0; i < ctx_count; i++) { context_t *dest_context = &thread->context->regs[i]; unsigned int new_flags = 0; /* some regs are always set from the native context */ if (i == CTX_NATIVE) new_flags |= native_flags; /* 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. */ if (is_pending || i == selected_ctx) new_flags |= contexts[i].flags & ~native_flags; if (i == CTX_WOW && !dest_context->machine) { if (!is_pending) continue; /* If pending, lazily initialize machine */ dest_context->machine = thread->process->machine; } copy_context( dest_context, &contexts[i], new_flags ); dest_context->flags |= new_flags; } }
I pushed a version that reorders context copies, allowing tweaking `native_flags` in wow context branch. This should fix the check for native context copying and avoid extra `copy_context` calls.