ntdll: Add a helper function to retrieve the CPU area context on the Unix side.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-07-01 11:16:27 +02:00
parent 8794879335
commit bedfb31d7c
4 changed files with 32 additions and 10 deletions

View File

@ -921,11 +921,7 @@ void DECLSPEC_HIDDEN call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, B
context.Sp = (DWORD)teb->Tib.StackBase;
context.Pc = (DWORD)pRtlUserThreadStart;
if (context.Pc & 1) context.Cpsr |= 0x20; /* thumb mode */
if (NtCurrentTeb64())
{
WOW64_CPURESERVED *cpu = ULongToPtr( NtCurrentTeb64()->TlsSlots[WOW64_TLS_CPURESERVED] );
memcpy( cpu + 1, &context, sizeof(context) );
}
if ((ctx = get_cpu_area( IMAGE_FILE_MACHINE_ARMNT ))) *ctx = context;
if (suspend) wait_suspend( &context );

View File

@ -2337,11 +2337,7 @@ void DECLSPEC_HIDDEN call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, B
context.FloatSave.ControlWord = 0x27f;
((XSAVE_FORMAT *)context.ExtendedRegisters)->ControlWord = 0x27f;
((XSAVE_FORMAT *)context.ExtendedRegisters)->MxCsr = 0x1f80;
if (NtCurrentTeb64())
{
WOW64_CPURESERVED *cpu = ULongToPtr( NtCurrentTeb64()->TlsSlots[WOW64_TLS_CPURESERVED] );
memcpy( cpu + 1, &context, sizeof(context) );
}
if ((ctx = get_cpu_area( IMAGE_FILE_MACHINE_I386 ))) *ctx = context;
if (suspend) wait_suspend( &context );

View File

@ -1097,6 +1097,35 @@ static SIZE_T get_machine_context_size( USHORT machine )
}
/***********************************************************************
* get_cpu_area
*
* cf. RtlWow64GetCurrentCpuArea
*/
void *get_cpu_area( USHORT machine )
{
WOW64_CPURESERVED *cpu;
ULONG align;
if (!NtCurrentTeb()->WowTebOffset) return NULL;
#ifdef _WIN64
cpu = NtCurrentTeb()->TlsSlots[WOW64_TLS_CPURESERVED];
#else
cpu = ULongToPtr( NtCurrentTeb64()->TlsSlots[WOW64_TLS_CPURESERVED] );
#endif
if (cpu->Machine != machine) return NULL;
switch (cpu->Machine)
{
case IMAGE_FILE_MACHINE_I386: align = TYPE_ALIGNMENT(I386_CONTEXT); break;
case IMAGE_FILE_MACHINE_AMD64: align = TYPE_ALIGNMENT(ARM_CONTEXT); break;
case IMAGE_FILE_MACHINE_ARMNT: align = TYPE_ALIGNMENT(AMD64_CONTEXT); break;
case IMAGE_FILE_MACHINE_ARM64: align = TYPE_ALIGNMENT(ARM64_NT_CONTEXT); break;
default: return NULL;
}
return (void *)(((ULONG_PTR)(cpu + 1) + align - 1) & ~(align - 1));
}
/***********************************************************************
* set_thread_id
*/

View File

@ -181,6 +181,7 @@ extern int server_pipe( int fd[2] ) DECLSPEC_HIDDEN;
extern void fpux_to_fpu( I386_FLOATING_SAVE_AREA *fpu, const XSAVE_FORMAT *fpux ) DECLSPEC_HIDDEN;
extern void fpu_to_fpux( XSAVE_FORMAT *fpux, const I386_FLOATING_SAVE_AREA *fpu ) DECLSPEC_HIDDEN;
extern void *get_cpu_area( USHORT machine ) DECLSPEC_HIDDEN;
extern void set_thread_id( TEB *teb, DWORD pid, DWORD tid ) DECLSPEC_HIDDEN;
extern NTSTATUS init_thread_stack( TEB *teb, ULONG_PTR zero_bits, SIZE_T reserve_size, SIZE_T commit_size ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;