Module: wine Branch: master Commit: 25e0a2580758282d679dafa557b2c1771410e970 URL: https://gitlab.winehq.org/wine/wine/-/commit/25e0a2580758282d679dafa557b2c17...
Author: Paul Gofman pgofman@codeweavers.com Date: Mon Mar 18 15:00:06 2024 -0600
ntdll: Factor out xstate_from_server() function.
---
dlls/ntdll/unix/thread.c | 82 +++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 56 deletions(-)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 60c833b0320..0d98473f01b 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -613,6 +613,28 @@ static NTSTATUS context_to_server( context_t *to, USHORT to_machine, const void }
+/*********************************************************************** + * xstate_from_server + * + * Copy xstate from the server format. + */ +static void xstate_from_server( CONTEXT_EX *xctx, const context_t *from ) +{ + XSTATE *xs = (XSTATE *)((char *)xctx + xctx->XState.Offset); + unsigned int i; + + xs->Mask &= ~4; + if (xs->CompactionMask) xs->CompactionMask = 0x8000000000000004; + for (i = 0; i < ARRAY_SIZE( from->ymm.regs.ymm_high); i++) + { + if (!from->ymm.regs.ymm_high[i].low && !from->ymm.regs.ymm_high[i].high) continue; + memcpy( &xs->YmmContext, &from->ymm.regs, sizeof(xs->YmmContext) ); + xs->Mask |= 4; + break; + } +} + + /*********************************************************************** * context_from_server * @@ -686,20 +708,7 @@ static NTSTATUS context_from_server( void *dst, const context_t *from, USHORT ma memcpy( to->ExtendedRegisters, from->ext.i386_regs, sizeof(to->ExtendedRegisters) ); } if ((from->flags & SERVER_CTX_YMM_REGISTERS) && (to_flags & CONTEXT_I386_XSTATE)) - { - CONTEXT_EX *xctx = (CONTEXT_EX *)(to + 1); - XSTATE *xs = (XSTATE *)((char *)xctx + xctx->XState.Offset); - - xs->Mask &= ~4; - if (xs->CompactionMask) xs->CompactionMask = 0x8000000000000004; - for (i = 0; i < ARRAY_SIZE( from->ymm.regs.ymm_high); i++) - { - if (!from->ymm.regs.ymm_high[i].low && !from->ymm.regs.ymm_high[i].high) continue; - memcpy( &xs->YmmContext, &from->ymm.regs, sizeof(xs->YmmContext) ); - xs->Mask |= 4; - break; - } - } + xstate_from_server( (CONTEXT_EX *)(to + 1), from ); return STATUS_SUCCESS; }
@@ -760,20 +769,7 @@ static NTSTATUS context_from_server( void *dst, const context_t *from, USHORT ma to->Dr7 = from->debug.x86_64_regs.dr7; } if ((from->flags & SERVER_CTX_YMM_REGISTERS) && (to_flags & CONTEXT_I386_XSTATE)) - { - CONTEXT_EX *xctx = (CONTEXT_EX *)(to + 1); - XSTATE *xs = (XSTATE *)((char *)xctx + xctx->XState.Offset); - - xs->Mask &= ~4; - if (xs->CompactionMask) xs->CompactionMask = 0x8000000000000004; - for (i = 0; i < ARRAY_SIZE( from->ymm.regs.ymm_high); i++) - { - if (!from->ymm.regs.ymm_high[i].low && !from->ymm.regs.ymm_high[i].high) continue; - memcpy( &xs->YmmContext, &from->ymm.regs, sizeof(xs->YmmContext) ); - xs->Mask |= 4; - break; - } - } + xstate_from_server( (CONTEXT_EX *)(to + 1), from ); return STATUS_SUCCESS; }
@@ -835,20 +831,7 @@ static NTSTATUS context_from_server( void *dst, const context_t *from, USHORT ma to->Dr7 = from->debug.x86_64_regs.dr7; } if ((from->flags & SERVER_CTX_YMM_REGISTERS) && (to_flags & CONTEXT_AMD64_XSTATE)) - { - CONTEXT_EX *xctx = (CONTEXT_EX *)(to + 1); - XSTATE *xs = (XSTATE *)((char *)xctx + xctx->XState.Offset); - - xs->Mask &= ~4; - if (xs->CompactionMask) xs->CompactionMask = 0x8000000000000004; - for (i = 0; i < ARRAY_SIZE( from->ymm.regs.ymm_high); i++) - { - if (!from->ymm.regs.ymm_high[i].low && !from->ymm.regs.ymm_high[i].high) continue; - memcpy( &xs->YmmContext, &from->ymm.regs, sizeof(xs->YmmContext) ); - xs->Mask |= 4; - break; - } - } + xstate_from_server( (CONTEXT_EX *)(to + 1), from ); return STATUS_SUCCESS; }
@@ -917,20 +900,7 @@ static NTSTATUS context_from_server( void *dst, const context_t *from, USHORT ma to->Dr7 = from->debug.i386_regs.dr7; } if ((from->flags & SERVER_CTX_YMM_REGISTERS) && (to_flags & CONTEXT_AMD64_XSTATE)) - { - CONTEXT_EX *xctx = (CONTEXT_EX *)(to + 1); - XSTATE *xs = (XSTATE *)((char *)xctx + xctx->XState.Offset); - - xs->Mask &= ~4; - if (xs->CompactionMask) xs->CompactionMask = 0x8000000000000004; - for (i = 0; i < ARRAY_SIZE( from->ymm.regs.ymm_high); i++) - { - if (!from->ymm.regs.ymm_high[i].low && !from->ymm.regs.ymm_high[i].high) continue; - memcpy( &xs->YmmContext, &from->ymm.regs, sizeof(xs->YmmContext) ); - xs->Mask |= 4; - break; - } - } + xstate_from_server( (CONTEXT_EX *)(to + 1), from ); return STATUS_SUCCESS; }