2020-06-01 12:52:05 +02:00
|
|
|
/*
|
|
|
|
* ARM64 signal handling routines
|
|
|
|
*
|
|
|
|
* Copyright 2010-2013 André Hentschel
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __aarch64__
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYSCALL_H
|
|
|
|
# include <syscall.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_SYS_SYSCALL_H
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SIGNAL_H
|
|
|
|
# include <sys/signal.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_UCONTEXT_H
|
|
|
|
# include <sys/ucontext.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBUNWIND
|
|
|
|
# define UNW_LOCAL_ONLY
|
|
|
|
# include <libunwind.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/asm.h"
|
|
|
|
#include "unix_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* signal context platform-specific definitions
|
|
|
|
*/
|
|
|
|
#ifdef linux
|
|
|
|
|
|
|
|
/* All Registers access - only for local access */
|
|
|
|
# define REG_sig(reg_name, context) ((context)->uc_mcontext.reg_name)
|
|
|
|
# define REGn_sig(reg_num, context) ((context)->uc_mcontext.regs[reg_num])
|
|
|
|
|
|
|
|
/* Special Registers access */
|
|
|
|
# define SP_sig(context) REG_sig(sp, context) /* Stack pointer */
|
|
|
|
# define PC_sig(context) REG_sig(pc, context) /* Program counter */
|
|
|
|
# define PSTATE_sig(context) REG_sig(pstate, context) /* Current State Register */
|
|
|
|
# define FP_sig(context) REGn_sig(29, context) /* Frame pointer */
|
|
|
|
# define LR_sig(context) REGn_sig(30, context) /* Link Register */
|
|
|
|
|
|
|
|
static struct _aarch64_ctx *get_extended_sigcontext( ucontext_t *sigcontext, unsigned int magic )
|
|
|
|
{
|
|
|
|
struct _aarch64_ctx *ctx = (struct _aarch64_ctx *)sigcontext->uc_mcontext.__reserved;
|
|
|
|
while ((char *)ctx < (char *)(&sigcontext->uc_mcontext + 1) && ctx->magic && ctx->size)
|
|
|
|
{
|
|
|
|
if (ctx->magic == magic) return ctx;
|
|
|
|
ctx = (struct _aarch64_ctx *)((char *)ctx + ctx->size);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fpsimd_context *get_fpsimd_context( ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
return (struct fpsimd_context *)get_extended_sigcontext( sigcontext, FPSIMD_MAGIC );
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD64 get_fault_esr( ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
struct esr_context *esr = (struct esr_context *)get_extended_sigcontext( sigcontext, ESR_MAGIC );
|
|
|
|
if (esr) return esr->esr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-14 20:56:45 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
|
|
|
/* All Registers access - only for local access */
|
|
|
|
# define REG_sig(reg_name, context) ((context)->uc_mcontext->__ss.__ ## reg_name)
|
|
|
|
# define REGn_sig(reg_num, context) ((context)->uc_mcontext->__ss.__x[reg_num])
|
|
|
|
|
|
|
|
/* Special Registers access */
|
|
|
|
# define SP_sig(context) REG_sig(sp, context) /* Stack pointer */
|
|
|
|
# define PC_sig(context) REG_sig(pc, context) /* Program counter */
|
|
|
|
# define PSTATE_sig(context) REG_sig(cpsr, context) /* Current State Register */
|
|
|
|
# define FP_sig(context) REG_sig(fp, context) /* Frame pointer */
|
|
|
|
# define LR_sig(context) REG_sig(lr, context) /* Link Register */
|
|
|
|
|
|
|
|
static DWORD64 get_fault_esr( ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
return sigcontext->uc_mcontext->__es.__esr;
|
|
|
|
}
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
#endif /* linux */
|
|
|
|
|
2020-06-01 12:52:05 +02:00
|
|
|
static pthread_key_t teb_key;
|
|
|
|
|
2020-07-28 13:03:00 +02:00
|
|
|
struct syscall_frame
|
|
|
|
{
|
2021-06-11 11:17:36 +02:00
|
|
|
ULONG64 x[29]; /* 000 */
|
|
|
|
ULONG64 fp; /* 0e8 */
|
|
|
|
ULONG64 lr; /* 0f0 */
|
|
|
|
ULONG64 sp; /* 0f8 */
|
|
|
|
ULONG64 pc; /* 100 */
|
|
|
|
ULONG64 cpsr; /* 108 */
|
|
|
|
ULONG64 restore_flags; /* 110 */
|
|
|
|
ULONG fpcr; /* 118 */
|
|
|
|
ULONG fpsr; /* 11c */
|
|
|
|
NEON128 v[32]; /* 120 */
|
2020-07-28 13:03:00 +02:00
|
|
|
};
|
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
C_ASSERT( sizeof( struct syscall_frame ) == 0x320 );
|
|
|
|
|
2020-06-02 13:11:54 +02:00
|
|
|
struct arm64_thread_data
|
|
|
|
{
|
2020-07-28 13:03:00 +02:00
|
|
|
void *exit_frame; /* 02f0 exit frame pointer */
|
|
|
|
struct syscall_frame *syscall_frame; /* 02f8 frame pointer on syscall entry */
|
2020-06-02 13:11:54 +02:00
|
|
|
};
|
|
|
|
|
2020-07-23 20:35:00 +02:00
|
|
|
C_ASSERT( sizeof(struct arm64_thread_data) <= sizeof(((struct ntdll_thread_data *)0)->cpu_data) );
|
|
|
|
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct arm64_thread_data, exit_frame ) == 0x2f0 );
|
2020-07-28 13:03:00 +02:00
|
|
|
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct arm64_thread_data, syscall_frame ) == 0x2f8 );
|
2020-06-02 13:11:54 +02:00
|
|
|
|
|
|
|
static inline struct arm64_thread_data *arm64_thread_data(void)
|
|
|
|
{
|
2020-07-28 13:03:00 +02:00
|
|
|
return (struct arm64_thread_data *)ntdll_get_thread_data()->cpu_data;
|
2020-06-02 13:11:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
static BOOL is_inside_syscall( ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
return ((char *)SP_sig(sigcontext) >= (char *)ntdll_get_thread_data()->kernel_stack &&
|
|
|
|
(char *)SP_sig(sigcontext) <= (char *)arm64_thread_data()->syscall_frame);
|
|
|
|
}
|
|
|
|
|
2020-10-05 11:16:40 +02:00
|
|
|
extern void raise_func_trampoline( EXCEPTION_RECORD *rec, CONTEXT *context, void *dispatcher );
|
2020-06-02 13:11:54 +02:00
|
|
|
|
2020-06-25 10:32:47 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* unwind_builtin_dll
|
|
|
|
*
|
|
|
|
* Equivalent of RtlVirtualUnwind for builtin modules.
|
|
|
|
*/
|
|
|
|
NTSTATUS CDECL unwind_builtin_dll( ULONG type, DISPATCHER_CONTEXT *dispatch, CONTEXT *context )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBUNWIND
|
2020-06-30 16:37:12 +02:00
|
|
|
ULONG_PTR ip = context->Pc;
|
2020-06-25 10:32:47 +02:00
|
|
|
unw_context_t unw_context;
|
|
|
|
unw_cursor_t cursor;
|
|
|
|
unw_proc_info_t info;
|
|
|
|
int rc;
|
|
|
|
|
2020-08-14 13:54:16 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
rc = unw_getcontext( &unw_context );
|
|
|
|
if (rc == UNW_ESUCCESS)
|
|
|
|
rc = unw_init_local( &cursor, &unw_context );
|
|
|
|
if (rc == UNW_ESUCCESS)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i <= 28; i++)
|
|
|
|
unw_set_reg( &cursor, UNW_ARM64_X0 + i, context->u.X[i] );
|
|
|
|
unw_set_reg( &cursor, UNW_ARM64_FP, context->u.s.Fp );
|
|
|
|
unw_set_reg( &cursor, UNW_ARM64_LR, context->u.s.Lr );
|
|
|
|
unw_set_reg( &cursor, UNW_ARM64_SP, context->Sp );
|
|
|
|
unw_set_reg( &cursor, UNW_REG_IP, context->Pc );
|
|
|
|
}
|
|
|
|
#else
|
2020-06-25 10:32:47 +02:00
|
|
|
memcpy( unw_context.uc_mcontext.regs, context->u.X, sizeof(context->u.X) );
|
|
|
|
unw_context.uc_mcontext.sp = context->Sp;
|
|
|
|
unw_context.uc_mcontext.pc = context->Pc;
|
|
|
|
|
|
|
|
rc = unw_init_local( &cursor, &unw_context );
|
2020-08-14 13:54:16 +02:00
|
|
|
#endif
|
2020-06-25 10:32:47 +02:00
|
|
|
if (rc != UNW_ESUCCESS)
|
|
|
|
{
|
|
|
|
WARN( "setup failed: %d\n", rc );
|
|
|
|
return STATUS_INVALID_DISPOSITION;
|
|
|
|
}
|
|
|
|
rc = unw_get_proc_info( &cursor, &info );
|
|
|
|
if (rc != UNW_ESUCCESS && rc != -UNW_ENOINFO)
|
|
|
|
{
|
|
|
|
WARN( "failed to get info: %d\n", rc );
|
|
|
|
return STATUS_INVALID_DISPOSITION;
|
|
|
|
}
|
|
|
|
if (rc == -UNW_ENOINFO || ip < info.start_ip || ip > info.end_ip)
|
|
|
|
{
|
|
|
|
TRACE( "no info found for %lx ip %lx-%lx, assuming leaf function\n",
|
|
|
|
ip, info.start_ip, info.end_ip );
|
|
|
|
dispatch->LanguageHandler = NULL;
|
|
|
|
dispatch->EstablisherFrame = context->Sp;
|
|
|
|
context->Pc = context->u.s.Lr;
|
|
|
|
context->Sp = context->Sp + sizeof(ULONG64);
|
|
|
|
context->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "ip %#lx function %#lx-%#lx personality %#lx lsda %#lx fde %#lx\n",
|
|
|
|
ip, (unsigned long)info.start_ip, (unsigned long)info.end_ip, (unsigned long)info.handler,
|
|
|
|
(unsigned long)info.lsda, (unsigned long)info.unwind_info );
|
|
|
|
|
|
|
|
rc = unw_step( &cursor );
|
|
|
|
if (rc < 0)
|
|
|
|
{
|
|
|
|
WARN( "failed to unwind: %d %d\n", rc, UNW_ENOINFO );
|
|
|
|
return STATUS_INVALID_DISPOSITION;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch->LanguageHandler = (void *)info.handler;
|
|
|
|
dispatch->HandlerData = (void *)info.lsda;
|
|
|
|
dispatch->EstablisherFrame = context->Sp;
|
2020-08-14 13:54:16 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i <= 28; i++)
|
|
|
|
unw_get_reg( &cursor, UNW_ARM64_X0 + i, (unw_word_t *)&context->u.X[i] );
|
|
|
|
}
|
|
|
|
unw_get_reg( &cursor, UNW_ARM64_FP, (unw_word_t *)&context->u.s.Fp );
|
|
|
|
unw_get_reg( &cursor, UNW_ARM64_X30, (unw_word_t *)&context->u.s.Lr );
|
|
|
|
unw_get_reg( &cursor, UNW_ARM64_SP, (unw_word_t *)&context->Sp );
|
|
|
|
#else
|
2020-06-25 10:32:47 +02:00
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X0, (unw_word_t *)&context->u.s.X0 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X1, (unw_word_t *)&context->u.s.X1 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X2, (unw_word_t *)&context->u.s.X2 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X3, (unw_word_t *)&context->u.s.X3 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X4, (unw_word_t *)&context->u.s.X4 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X5, (unw_word_t *)&context->u.s.X5 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X6, (unw_word_t *)&context->u.s.X6 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X7, (unw_word_t *)&context->u.s.X7 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X8, (unw_word_t *)&context->u.s.X8 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X9, (unw_word_t *)&context->u.s.X9 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X10, (unw_word_t *)&context->u.s.X10 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X11, (unw_word_t *)&context->u.s.X11 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X12, (unw_word_t *)&context->u.s.X12 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X13, (unw_word_t *)&context->u.s.X13 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X14, (unw_word_t *)&context->u.s.X14 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X15, (unw_word_t *)&context->u.s.X15 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X16, (unw_word_t *)&context->u.s.X16 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X17, (unw_word_t *)&context->u.s.X17 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X18, (unw_word_t *)&context->u.s.X18 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X19, (unw_word_t *)&context->u.s.X19 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X20, (unw_word_t *)&context->u.s.X20 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X21, (unw_word_t *)&context->u.s.X21 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X22, (unw_word_t *)&context->u.s.X22 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X23, (unw_word_t *)&context->u.s.X23 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X24, (unw_word_t *)&context->u.s.X24 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X25, (unw_word_t *)&context->u.s.X25 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X26, (unw_word_t *)&context->u.s.X26 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X27, (unw_word_t *)&context->u.s.X27 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X28, (unw_word_t *)&context->u.s.X28 );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X29, (unw_word_t *)&context->u.s.Fp );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_X30, (unw_word_t *)&context->u.s.Lr );
|
|
|
|
unw_get_reg( &cursor, UNW_AARCH64_SP, (unw_word_t *)&context->Sp );
|
2020-08-14 13:54:16 +02:00
|
|
|
#endif
|
2020-08-14 13:54:15 +02:00
|
|
|
unw_get_reg( &cursor, UNW_REG_IP, (unw_word_t *)&context->Pc );
|
2020-06-25 10:32:47 +02:00
|
|
|
context->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
|
|
|
|
|
2020-10-05 11:16:40 +02:00
|
|
|
if (info.start_ip == (unw_word_t)raise_func_trampoline) {
|
|
|
|
/* raise_func_trampoline has a full CONTEXT stored on the stack;
|
|
|
|
* restore the original Lr value from there. The function we unwind
|
|
|
|
* to might be a leaf function that hasn't backed up its own original
|
|
|
|
* Lr value on the stack.
|
|
|
|
* We could also just restore the full context here without doing
|
|
|
|
* unw_step at all. */
|
|
|
|
const CONTEXT *next_ctx = (const CONTEXT *) dispatch->EstablisherFrame;
|
|
|
|
context->u.s.Lr = next_ctx->u.s.Lr;
|
|
|
|
}
|
|
|
|
|
2020-06-25 10:32:47 +02:00
|
|
|
TRACE( "next function pc=%016lx%s\n", context->Pc, rc ? "" : " (last frame)" );
|
|
|
|
TRACE(" x0=%016lx x1=%016lx x2=%016lx x3=%016lx\n",
|
|
|
|
context->u.s.X0, context->u.s.X1, context->u.s.X2, context->u.s.X3 );
|
|
|
|
TRACE(" x4=%016lx x5=%016lx x6=%016lx x7=%016lx\n",
|
|
|
|
context->u.s.X4, context->u.s.X5, context->u.s.X6, context->u.s.X7 );
|
|
|
|
TRACE(" x8=%016lx x9=%016lx x10=%016lx x11=%016lx\n",
|
|
|
|
context->u.s.X8, context->u.s.X9, context->u.s.X10, context->u.s.X11 );
|
|
|
|
TRACE(" x12=%016lx x13=%016lx x14=%016lx x15=%016lx\n",
|
|
|
|
context->u.s.X12, context->u.s.X13, context->u.s.X14, context->u.s.X15 );
|
|
|
|
TRACE(" x16=%016lx x17=%016lx x18=%016lx x19=%016lx\n",
|
|
|
|
context->u.s.X16, context->u.s.X17, context->u.s.X18, context->u.s.X19 );
|
|
|
|
TRACE(" x20=%016lx x21=%016lx x22=%016lx x23=%016lx\n",
|
|
|
|
context->u.s.X20, context->u.s.X21, context->u.s.X22, context->u.s.X23 );
|
|
|
|
TRACE(" x24=%016lx x25=%016lx x26=%016lx x27=%016lx\n",
|
|
|
|
context->u.s.X24, context->u.s.X25, context->u.s.X26, context->u.s.X27 );
|
|
|
|
TRACE(" x28=%016lx fp=%016lx lr=%016lx sp=%016lx\n",
|
|
|
|
context->u.s.X28, context->u.s.Fp, context->u.s.Lr, context->Sp );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#else
|
|
|
|
return STATUS_INVALID_DISPOSITION;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* save_context
|
|
|
|
*
|
|
|
|
* Set the register values from a sigcontext.
|
|
|
|
*/
|
|
|
|
static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
2020-08-21 14:02:03 +02:00
|
|
|
context->ContextFlags = (CONTEXT_FULL & ~CONTEXT_FLOATING_POINT) |
|
|
|
|
CONTEXT_ARM64;
|
2020-06-09 12:32:41 +02:00
|
|
|
context->u.s.Fp = FP_sig(sigcontext); /* Frame pointer */
|
|
|
|
context->u.s.Lr = LR_sig(sigcontext); /* Link register */
|
|
|
|
context->Sp = SP_sig(sigcontext); /* Stack pointer */
|
|
|
|
context->Pc = PC_sig(sigcontext); /* Program Counter */
|
|
|
|
context->Cpsr = PSTATE_sig(sigcontext); /* Current State Register */
|
|
|
|
for (i = 0; i <= 28; i++) context->u.X[i] = REGn_sig( i, sigcontext );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_context
|
|
|
|
*
|
|
|
|
* Build a sigcontext from the register values.
|
|
|
|
*/
|
|
|
|
static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
FP_sig(sigcontext) = context->u.s.Fp; /* Frame pointer */
|
|
|
|
LR_sig(sigcontext) = context->u.s.Lr; /* Link register */
|
|
|
|
SP_sig(sigcontext) = context->Sp; /* Stack pointer */
|
|
|
|
PC_sig(sigcontext) = context->Pc; /* Program Counter */
|
|
|
|
PSTATE_sig(sigcontext) = context->Cpsr; /* Current State Register */
|
|
|
|
for (i = 0; i <= 28; i++) REGn_sig( i, sigcontext ) = context->u.X[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* save_fpu
|
|
|
|
*
|
|
|
|
* Set the FPU context from a sigcontext.
|
|
|
|
*/
|
|
|
|
static void save_fpu( CONTEXT *context, ucontext_t *sigcontext )
|
|
|
|
{
|
2020-08-14 20:56:45 +02:00
|
|
|
#ifdef linux
|
2020-06-09 12:32:41 +02:00
|
|
|
struct fpsimd_context *fp = get_fpsimd_context( sigcontext );
|
|
|
|
|
|
|
|
if (!fp) return;
|
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
context->Fpcr = fp->fpcr;
|
|
|
|
context->Fpsr = fp->fpsr;
|
|
|
|
memcpy( context->V, fp->vregs, sizeof(context->V) );
|
2020-08-14 20:56:45 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
context->Fpcr = sigcontext->uc_mcontext->__ns.__fpcr;
|
|
|
|
context->Fpsr = sigcontext->uc_mcontext->__ns.__fpsr;
|
|
|
|
memcpy( context->V, sigcontext->uc_mcontext->__ns.__v, sizeof(context->V) );
|
|
|
|
#endif
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_fpu
|
|
|
|
*
|
|
|
|
* Restore the FPU context to a sigcontext.
|
|
|
|
*/
|
2021-06-11 11:17:36 +02:00
|
|
|
static void restore_fpu( struct syscall_frame *frame, ucontext_t *sigcontext )
|
2020-06-09 12:32:41 +02:00
|
|
|
{
|
2020-08-14 20:56:45 +02:00
|
|
|
#ifdef linux
|
2020-06-09 12:32:41 +02:00
|
|
|
struct fpsimd_context *fp = get_fpsimd_context( sigcontext );
|
|
|
|
|
|
|
|
if (!fp) return;
|
2021-06-11 11:17:36 +02:00
|
|
|
fp->fpcr = frame->fpcr;
|
|
|
|
fp->fpsr = frame->fpsr;
|
|
|
|
memcpy( fp->vregs, frame->v, sizeof(fp->vregs) );
|
2020-08-14 20:56:45 +02:00
|
|
|
#elif defined(__APPLE__)
|
2021-06-11 11:17:36 +02:00
|
|
|
sigcontext->uc_mcontext->__ns.__fpcr = frame->fpcr;
|
|
|
|
sigcontext->uc_mcontext->__ns.__fpsr = frame->fpsr;
|
|
|
|
memcpy( sigcontext->uc_mcontext->__ns.__v, frame->v, sizeof(frame->v) );
|
2020-08-14 20:56:45 +02:00
|
|
|
#endif
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 18:04:16 +01:00
|
|
|
/***********************************************************************
|
2021-06-11 12:40:08 +02:00
|
|
|
* signal_set_full_context
|
2021-02-22 18:04:16 +01:00
|
|
|
*/
|
2021-06-11 12:40:08 +02:00
|
|
|
NTSTATUS signal_set_full_context( CONTEXT *context )
|
2021-02-22 18:04:16 +01:00
|
|
|
{
|
2021-06-11 12:40:08 +02:00
|
|
|
NTSTATUS status = NtSetContextThread( GetCurrentThread(), context );
|
|
|
|
|
|
|
|
if (!status && (context->ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER) raise( SIGUSR2 );
|
|
|
|
return status;
|
2021-02-22 18:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-26 11:13:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_native_context
|
|
|
|
*/
|
|
|
|
void *get_native_context( CONTEXT *context )
|
|
|
|
{
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_wow_context
|
|
|
|
*/
|
|
|
|
void *get_wow_context( CONTEXT *context )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-02 13:11:54 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtSetContextThread (NTDLL.@)
|
|
|
|
* ZwSetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
|
|
|
|
{
|
2021-06-11 11:17:36 +02:00
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
2020-06-02 13:11:54 +02:00
|
|
|
NTSTATUS ret = STATUS_SUCCESS;
|
|
|
|
BOOL self = (handle == GetCurrentThread());
|
2021-06-11 11:17:36 +02:00
|
|
|
DWORD flags = context->ContextFlags & ~CONTEXT_ARM64;
|
2020-06-02 13:11:54 +02:00
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
if (self && (flags & CONTEXT_DEBUG_REGISTERS)) self = FALSE;
|
2020-06-02 13:11:54 +02:00
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
ret = set_thread_context( handle, context, &self, IMAGE_FILE_MACHINE_ARM64 );
|
|
|
|
if (ret || !self) return ret;
|
|
|
|
}
|
2021-05-18 10:18:19 +02:00
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
memcpy( frame->x, context->u.X, sizeof(context->u.X[0]) * 18 );
|
|
|
|
/* skip x18 */
|
|
|
|
memcpy( frame->x + 19, context->u.X + 19, sizeof(context->u.X[0]) * 10 );
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
frame->fp = context->u.s.Fp;
|
|
|
|
frame->lr = context->u.s.Lr;
|
|
|
|
frame->sp = context->Sp;
|
|
|
|
frame->pc = context->Pc;
|
|
|
|
frame->cpsr = context->Cpsr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
2020-06-06 15:41:24 +02:00
|
|
|
{
|
2021-06-11 11:17:36 +02:00
|
|
|
frame->fpcr = context->Fpcr;
|
|
|
|
frame->fpsr = context->Fpsr;
|
|
|
|
memcpy( frame->v, context->V, sizeof(frame->v) );
|
2020-06-06 15:41:24 +02:00
|
|
|
}
|
2021-06-11 11:17:36 +02:00
|
|
|
if (flags & CONTEXT_ARM64_X18)
|
|
|
|
{
|
|
|
|
frame->x[18] = context->u.X[18];
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS) FIXME( "debug registers not supported\n" );
|
|
|
|
frame->restore_flags |= flags & ~CONTEXT_INTEGER;
|
|
|
|
return STATUS_SUCCESS;
|
2020-06-02 13:11:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-02 14:05:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtGetContextThread (NTDLL.@)
|
|
|
|
* ZwGetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
|
|
|
|
{
|
2020-07-28 13:26:48 +02:00
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
|
|
|
DWORD needed_flags = context->ContextFlags & ~CONTEXT_ARM64;
|
2020-06-02 14:05:42 +02:00
|
|
|
BOOL self = (handle == GetCurrentThread());
|
|
|
|
|
|
|
|
if (!self)
|
|
|
|
{
|
2021-06-29 14:46:30 +02:00
|
|
|
NTSTATUS ret = get_thread_context( handle, context, &self, IMAGE_FILE_MACHINE_ARM64 );
|
|
|
|
if (ret || !self) return ret;
|
2020-06-02 14:05:42 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 14:46:30 +02:00
|
|
|
if (needed_flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
memcpy( context->u.X, frame->x, sizeof(context->u.X[0]) * 29 );
|
|
|
|
context->ContextFlags |= CONTEXT_INTEGER;
|
|
|
|
}
|
|
|
|
if (needed_flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
context->u.s.Fp = frame->fp;
|
|
|
|
context->u.s.Lr = frame->lr;
|
|
|
|
context->Sp = frame->sp;
|
|
|
|
context->Pc = frame->pc;
|
|
|
|
context->Cpsr = frame->cpsr;
|
|
|
|
context->ContextFlags |= CONTEXT_CONTROL;
|
|
|
|
}
|
|
|
|
if (needed_flags & CONTEXT_FLOATING_POINT)
|
2020-06-02 14:05:42 +02:00
|
|
|
{
|
2021-06-29 14:46:30 +02:00
|
|
|
context->Fpcr = frame->fpcr;
|
|
|
|
context->Fpsr = frame->fpsr;
|
|
|
|
memcpy( context->V, frame->v, sizeof(context->V) );
|
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
2020-06-02 14:05:42 +02:00
|
|
|
}
|
2021-06-29 14:46:30 +02:00
|
|
|
if (needed_flags & CONTEXT_DEBUG_REGISTERS) FIXME( "debug registers not supported\n" );
|
2020-06-02 14:05:42 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-18 11:58:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_thread_wow64_context
|
|
|
|
*/
|
|
|
|
NTSTATUS set_thread_wow64_context( HANDLE handle, const void *ctx, ULONG size )
|
|
|
|
{
|
|
|
|
BOOL self;
|
|
|
|
USHORT machine;
|
|
|
|
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case sizeof(I386_CONTEXT): machine = IMAGE_FILE_MACHINE_I386; break;
|
|
|
|
case sizeof(ARM_CONTEXT): machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
|
|
|
default: return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
return set_thread_context( handle, ctx, &self, machine );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_thread_wow64_context
|
|
|
|
*/
|
|
|
|
NTSTATUS get_thread_wow64_context( HANDLE handle, void *ctx, ULONG size )
|
|
|
|
{
|
|
|
|
BOOL self;
|
|
|
|
USHORT machine;
|
|
|
|
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case sizeof(I386_CONTEXT): machine = IMAGE_FILE_MACHINE_I386; break;
|
|
|
|
case sizeof(ARM_CONTEXT): machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
|
|
|
default: return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
return get_thread_context( handle, ctx, &self, machine );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 11:16:40 +02:00
|
|
|
/* Note, unwind_builtin_dll above has hardcoded assumptions on how this
|
|
|
|
* function stores things on the stack; if modified, modify that one in
|
|
|
|
* sync as well. */
|
2020-06-09 12:32:41 +02:00
|
|
|
__ASM_GLOBAL_FUNC( raise_func_trampoline,
|
2020-10-05 11:16:40 +02:00
|
|
|
"stp x29, x30, [sp, #-0x30]!\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_offset 48\n\t")
|
|
|
|
__ASM_CFI(".cfi_offset 29, -48\n\t")
|
|
|
|
__ASM_CFI(".cfi_offset 30, -40\n\t")
|
|
|
|
"stp x0, x1, [sp, #0x10]\n\t"
|
|
|
|
"str x2, [sp, #0x20]\n\t"
|
2020-06-09 12:32:41 +02:00
|
|
|
"mov x29, sp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register 29\n\t")
|
|
|
|
__ASM_CFI(".cfi_remember_state\n\t")
|
2020-10-05 11:16:40 +02:00
|
|
|
|
|
|
|
/* Memcpy the context onto the stack */
|
|
|
|
"sub sp, sp, #0x390\n\t"
|
|
|
|
"mov x0, sp\n\t"
|
|
|
|
"mov x2, #0x390\n\t"
|
|
|
|
"bl " __ASM_NAME("memcpy") "\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa 31, 0\n\t")
|
|
|
|
__ASM_CFI(".cfi_escape 0x0f,0x04,0x8f,0x80,0x02,0x06\n\t") /* CFA, DW_OP_breg31 + 0x100, DW_OP_deref */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x13,0x03,0x8f,0xa0,0x01\n\t") /* x19, DW_OP_breg31 + 0xA0 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x14,0x03,0x8f,0xa8,0x01\n\t") /* x20 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x15,0x03,0x8f,0xb0,0x01\n\t") /* x21 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x16,0x03,0x8f,0xb8,0x01\n\t") /* x22 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x17,0x03,0x8f,0xc0,0x01\n\t") /* x23 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x18,0x03,0x8f,0xc8,0x01\n\t") /* x24 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x19,0x03,0x8f,0xd0,0x01\n\t") /* x25 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x1a,0x03,0x8f,0xd8,0x01\n\t") /* x26 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x1b,0x03,0x8f,0xe0,0x01\n\t") /* x27 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x1c,0x03,0x8f,0xe8,0x01\n\t") /* x28 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x1d,0x03,0x8f,0xf0,0x01\n\t") /* x29 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x1e,0x03,0x8f,0x88,0x02\n\t") /* x30 = pc */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x48,0x03,0x8f,0x90,0x03\n\t") /* d8 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x49,0x03,0x8f,0x98,0x03\n\t") /* d9 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4a,0x03,0x8f,0xa0,0x03\n\t") /* d10 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4b,0x03,0x8f,0xa8,0x03\n\t") /* d11 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4c,0x03,0x8f,0xb0,0x03\n\t") /* d12 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4d,0x03,0x8f,0xb8,0x03\n\t") /* d13 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4e,0x03,0x8f,0xc0,0x03\n\t") /* d14 */
|
|
|
|
__ASM_CFI(".cfi_escape 0x10,0x4f,0x03,0x8f,0xc8,0x03\n\t") /* d15 */
|
|
|
|
"ldp x0, x1, [x29, #0x10]\n\t"
|
|
|
|
"ldr x2, [x29, #0x20]\n\t"
|
2020-06-09 12:32:41 +02:00
|
|
|
"blr x2\n\t"
|
|
|
|
__ASM_CFI(".cfi_restore_state\n\t")
|
|
|
|
"brk #1")
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-07-15 10:34:56 +02:00
|
|
|
* setup_exception
|
2020-06-09 12:32:41 +02:00
|
|
|
*
|
|
|
|
* Modify the signal context to call the exception raise function.
|
|
|
|
*/
|
2020-07-15 10:34:56 +02:00
|
|
|
static void setup_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec )
|
2020-06-09 12:32:41 +02:00
|
|
|
{
|
2020-07-15 10:34:56 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
void *redzone[3];
|
|
|
|
} *stack;
|
|
|
|
|
|
|
|
void *stack_ptr = (void *)(SP_sig(sigcontext) & ~15);
|
|
|
|
CONTEXT context;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
rec->ExceptionAddress = (void *)PC_sig(sigcontext);
|
|
|
|
save_context( &context, sigcontext );
|
|
|
|
save_fpu( &context, sigcontext );
|
2020-06-09 12:32:41 +02:00
|
|
|
|
2020-07-15 10:34:56 +02:00
|
|
|
status = send_debug_event( rec, &context, TRUE );
|
2020-06-09 12:32:41 +02:00
|
|
|
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
|
|
|
|
{
|
2020-07-15 10:34:56 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2020-06-09 12:32:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-07-15 10:34:56 +02:00
|
|
|
|
|
|
|
stack = virtual_setup_exception( stack_ptr, (sizeof(*stack) + 15) & ~15, rec );
|
|
|
|
stack->rec = *rec;
|
|
|
|
stack->context = context;
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
SP_sig(sigcontext) = (ULONG_PTR)stack;
|
|
|
|
LR_sig(sigcontext) = PC_sig(sigcontext);
|
2020-07-15 10:34:56 +02:00
|
|
|
PC_sig(sigcontext) = (ULONG_PTR)raise_func_trampoline;
|
|
|
|
REGn_sig(0, sigcontext) = (ULONG_PTR)&stack->rec; /* first arg for KiUserExceptionDispatcher */
|
|
|
|
REGn_sig(1, sigcontext) = (ULONG_PTR)&stack->context; /* second arg for KiUserExceptionDispatcher */
|
|
|
|
REGn_sig(2, sigcontext) = (ULONG_PTR)pKiUserExceptionDispatcher; /* dispatcher arg for raise_func_trampoline */
|
2020-06-09 12:32:41 +02:00
|
|
|
REGn_sig(18, sigcontext) = (ULONG_PTR)NtCurrentTeb();
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:31:24 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2020-08-20 08:24:00 +02:00
|
|
|
* call_user_apc_dispatcher
|
2020-08-06 19:31:24 +02:00
|
|
|
*/
|
2021-06-11 12:40:08 +02:00
|
|
|
NTSTATUS call_user_apc_dispatcher( CONTEXT *context, ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3,
|
|
|
|
PNTAPCFUNC func, NTSTATUS status )
|
2021-06-11 11:17:36 +02:00
|
|
|
{
|
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
|
|
|
ULONG64 sp = context ? context->Sp : frame->sp;
|
|
|
|
struct apc_stack_layout { CONTEXT context; } *stack;
|
|
|
|
|
|
|
|
sp &= ~15;
|
|
|
|
stack = (struct apc_stack_layout *)sp - 1;
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
memmove( &stack->context, context, sizeof(stack->context) );
|
|
|
|
NtSetContextThread( GetCurrentThread(), &stack->context );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stack->context.ContextFlags = CONTEXT_FULL;
|
|
|
|
NtGetContextThread( GetCurrentThread(), &stack->context );
|
|
|
|
stack->context.u.s.X0 = status;
|
|
|
|
}
|
|
|
|
frame->sp = (ULONG64)stack;
|
2021-06-11 12:40:08 +02:00
|
|
|
frame->pc = (ULONG64)pKiUserApcDispatcher;
|
2021-06-11 11:17:36 +02:00
|
|
|
frame->x[0] = (ULONG64)&stack->context;
|
|
|
|
frame->x[1] = arg1;
|
|
|
|
frame->x[2] = arg2;
|
|
|
|
frame->x[3] = arg3;
|
|
|
|
frame->x[4] = (ULONG64)func;
|
|
|
|
frame->restore_flags |= CONTEXT_CONTROL | CONTEXT_INTEGER;
|
|
|
|
return status;
|
|
|
|
}
|
2020-08-06 19:31:24 +02:00
|
|
|
|
|
|
|
|
2020-08-11 15:25:55 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* call_raise_user_exception_dispatcher
|
|
|
|
*/
|
2021-06-11 12:40:08 +02:00
|
|
|
void call_raise_user_exception_dispatcher(void)
|
2021-06-11 11:17:36 +02:00
|
|
|
{
|
2021-06-11 12:40:08 +02:00
|
|
|
arm64_thread_data()->syscall_frame->pc = (UINT64)pKiRaiseUserExceptionDispatcher;
|
2021-06-11 11:17:36 +02:00
|
|
|
}
|
2020-08-11 15:25:55 +02:00
|
|
|
|
|
|
|
|
2020-08-06 19:31:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* call_user_exception_dispatcher
|
|
|
|
*/
|
2021-06-11 12:40:08 +02:00
|
|
|
NTSTATUS call_user_exception_dispatcher( EXCEPTION_RECORD *rec, CONTEXT *context )
|
2021-06-11 11:17:36 +02:00
|
|
|
{
|
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
|
|
|
NTSTATUS status = NtSetContextThread( GetCurrentThread(), context );
|
|
|
|
|
|
|
|
if (status) return status;
|
|
|
|
frame->x[0] = (ULONG64)rec;
|
|
|
|
frame->x[1] = (ULONG64)context;
|
2021-06-11 12:40:08 +02:00
|
|
|
frame->pc = (ULONG64)pKiUserExceptionDispatcher;
|
2021-06-11 11:17:36 +02:00
|
|
|
frame->restore_flags |= CONTEXT_INTEGER | CONTEXT_CONTROL;
|
|
|
|
return status;
|
|
|
|
}
|
2020-08-11 14:49:34 +02:00
|
|
|
|
2020-06-30 22:34:34 +02:00
|
|
|
|
2020-08-24 11:46:22 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* handle_syscall_fault
|
|
|
|
*
|
|
|
|
* Handle a page fault happening during a system call.
|
|
|
|
*/
|
|
|
|
static BOOL handle_syscall_fault( ucontext_t *context, EXCEPTION_RECORD *rec )
|
|
|
|
{
|
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
|
|
|
DWORD i;
|
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
if (!is_inside_syscall( context )) return FALSE;
|
2020-08-24 11:46:22 +02:00
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x addr=%p pc=%p tid=%04x\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
|
|
|
|
(void *)PC_sig(context), GetCurrentThreadId() );
|
|
|
|
for (i = 0; i < rec->NumberParameters; i++)
|
|
|
|
TRACE( " info[%d]=%016lx\n", i, rec->ExceptionInformation[i] );
|
|
|
|
|
|
|
|
TRACE(" x0=%016lx x1=%016lx x2=%016lx x3=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(0, context), (DWORD64)REGn_sig(1, context),
|
|
|
|
(DWORD64)REGn_sig(2, context), (DWORD64)REGn_sig(3, context) );
|
|
|
|
TRACE(" x4=%016lx x5=%016lx x6=%016lx x7=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(4, context), (DWORD64)REGn_sig(5, context),
|
|
|
|
(DWORD64)REGn_sig(6, context), (DWORD64)REGn_sig(7, context) );
|
|
|
|
TRACE(" x8=%016lx x9=%016lx x10=%016lx x11=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(8, context), (DWORD64)REGn_sig(9, context),
|
|
|
|
(DWORD64)REGn_sig(10, context), (DWORD64)REGn_sig(11, context) );
|
|
|
|
TRACE(" x12=%016lx x13=%016lx x14=%016lx x15=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(12, context), (DWORD64)REGn_sig(13, context),
|
|
|
|
(DWORD64)REGn_sig(14, context), (DWORD64)REGn_sig(15, context) );
|
|
|
|
TRACE(" x16=%016lx x17=%016lx x18=%016lx x19=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(16, context), (DWORD64)REGn_sig(17, context),
|
|
|
|
(DWORD64)REGn_sig(18, context), (DWORD64)REGn_sig(19, context) );
|
|
|
|
TRACE(" x20=%016lx x21=%016lx x22=%016lx x23=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(20, context), (DWORD64)REGn_sig(21, context),
|
|
|
|
(DWORD64)REGn_sig(22, context), (DWORD64)REGn_sig(23, context) );
|
|
|
|
TRACE(" x24=%016lx x25=%016lx x26=%016lx x27=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(24, context), (DWORD64)REGn_sig(25, context),
|
|
|
|
(DWORD64)REGn_sig(26, context), (DWORD64)REGn_sig(27, context) );
|
|
|
|
TRACE(" x28=%016lx fp=%016lx lr=%016lx sp=%016lx\n",
|
|
|
|
(DWORD64)REGn_sig(28, context), (DWORD64)FP_sig(context),
|
|
|
|
(DWORD64)LR_sig(context), (DWORD64)SP_sig(context) );
|
|
|
|
|
2021-06-01 15:16:23 +02:00
|
|
|
if (ntdll_get_thread_data()->jmp_buf)
|
2020-08-24 11:46:22 +02:00
|
|
|
{
|
|
|
|
TRACE( "returning to handler\n" );
|
2021-06-01 15:16:23 +02:00
|
|
|
REGn_sig(0, context) = (ULONG_PTR)ntdll_get_thread_data()->jmp_buf;
|
2020-08-24 11:46:22 +02:00
|
|
|
REGn_sig(1, context) = 1;
|
|
|
|
PC_sig(context) = (ULONG_PTR)__wine_longjmp;
|
2021-06-01 15:16:23 +02:00
|
|
|
ntdll_get_thread_data()->jmp_buf = NULL;
|
2020-08-24 11:46:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-11 11:17:36 +02:00
|
|
|
TRACE( "returning to user mode ip=%p ret=%08x\n", (void *)frame->pc, rec->ExceptionCode );
|
2021-06-21 15:43:22 +02:00
|
|
|
REGn_sig(0, context) = (ULONG_PTR)frame;
|
|
|
|
REGn_sig(1, context) = rec->ExceptionCode;
|
|
|
|
PC_sig(context) = (ULONG_PTR)__wine_syscall_dispatcher_return;
|
2020-08-24 11:46:22 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* segv_handler
|
|
|
|
*
|
2020-07-15 10:52:52 +02:00
|
|
|
* Handler for SIGSEGV.
|
2020-06-09 12:32:41 +02:00
|
|
|
*/
|
2020-07-15 10:52:52 +02:00
|
|
|
static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2020-06-09 12:32:41 +02:00
|
|
|
{
|
2020-07-15 10:31:19 +02:00
|
|
|
EXCEPTION_RECORD rec = { 0 };
|
2020-07-15 10:52:52 +02:00
|
|
|
ucontext_t *context = sigcontext;
|
|
|
|
|
|
|
|
rec.NumberParameters = 2;
|
|
|
|
rec.ExceptionInformation[0] = (get_fault_esr( context ) & 0x40) != 0;
|
|
|
|
rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
|
|
|
|
rec.ExceptionCode = virtual_handle_fault( siginfo->si_addr, rec.ExceptionInformation[0],
|
|
|
|
(void *)SP_sig(context) );
|
|
|
|
if (!rec.ExceptionCode) return;
|
2020-08-24 11:46:22 +02:00
|
|
|
if (handle_syscall_fault( context, &rec )) return;
|
2020-07-15 10:34:56 +02:00
|
|
|
setup_exception( context, &rec );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-15 10:52:52 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* ill_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGILL.
|
|
|
|
*/
|
|
|
|
static void ill_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec = { EXCEPTION_ILLEGAL_INSTRUCTION };
|
|
|
|
|
|
|
|
setup_exception( sigcontext, &rec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* bus_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGBUS.
|
|
|
|
*/
|
|
|
|
static void bus_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec = { EXCEPTION_DATATYPE_MISALIGNMENT };
|
|
|
|
|
|
|
|
setup_exception( sigcontext, &rec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* trap_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGTRAP.
|
|
|
|
*/
|
2020-07-15 10:52:52 +02:00
|
|
|
static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2020-06-09 12:32:41 +02:00
|
|
|
{
|
2020-07-15 10:31:19 +02:00
|
|
|
EXCEPTION_RECORD rec = { 0 };
|
2020-06-09 12:32:41 +02:00
|
|
|
|
2020-07-15 10:52:52 +02:00
|
|
|
switch (siginfo->si_code)
|
2020-06-09 12:32:41 +02:00
|
|
|
{
|
|
|
|
case TRAP_TRACE:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
case TRAP_BRKPT:
|
|
|
|
default:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_BREAKPOINT;
|
2020-07-28 13:40:06 +02:00
|
|
|
rec.NumberParameters = 1;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-07-15 10:52:52 +02:00
|
|
|
setup_exception( sigcontext, &rec );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* fpe_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGFPE.
|
|
|
|
*/
|
|
|
|
static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
2020-07-15 10:31:19 +02:00
|
|
|
EXCEPTION_RECORD rec = { 0 };
|
2020-06-09 12:32:41 +02:00
|
|
|
|
|
|
|
switch (siginfo->si_code & 0xffff )
|
|
|
|
{
|
|
|
|
#ifdef FPE_FLTSUB
|
|
|
|
case FPE_FLTSUB:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_INTDIV
|
|
|
|
case FPE_INTDIV:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_INTOVF
|
|
|
|
case FPE_INTOVF:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTDIV
|
|
|
|
case FPE_FLTDIV:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTOVF
|
|
|
|
case FPE_FLTOVF:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTUND
|
|
|
|
case FPE_FLTUND:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTRES
|
|
|
|
case FPE_FLTRES:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTINV
|
|
|
|
case FPE_FLTINV:
|
|
|
|
#endif
|
|
|
|
default:
|
2020-07-15 10:31:19 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
2020-06-09 12:32:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-07-15 10:34:56 +02:00
|
|
|
setup_exception( sigcontext, &rec );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* int_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGINT.
|
|
|
|
*/
|
|
|
|
static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
2021-06-09 15:19:43 +02:00
|
|
|
HANDLE handle;
|
2020-07-15 10:34:56 +02:00
|
|
|
|
2021-06-09 15:19:43 +02:00
|
|
|
if (!p__wine_ctrl_routine) return;
|
|
|
|
if (!NtCreateThreadEx( &handle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(),
|
|
|
|
p__wine_ctrl_routine, 0 /* CTRL_C_EVENT */, 0, 0, 0, 0, NULL ))
|
|
|
|
NtClose( handle );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* abrt_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGABRT.
|
|
|
|
*/
|
|
|
|
static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
2020-07-15 10:31:19 +02:00
|
|
|
EXCEPTION_RECORD rec = { EXCEPTION_WINE_ASSERTION, EH_NONCONTINUABLE };
|
2020-07-15 10:34:56 +02:00
|
|
|
|
|
|
|
setup_exception( sigcontext, &rec );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* quit_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGQUIT.
|
|
|
|
*/
|
|
|
|
static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
|
|
|
abort_thread(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* usr1_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGUSR1, used to signal a thread that it got suspended.
|
|
|
|
*/
|
|
|
|
static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
|
|
|
|
2021-06-11 11:17:36 +02:00
|
|
|
if (is_inside_syscall( sigcontext ))
|
|
|
|
{
|
|
|
|
context.ContextFlags = CONTEXT_FULL;
|
|
|
|
NtGetContextThread( GetCurrentThread(), &context );
|
|
|
|
wait_suspend( &context );
|
|
|
|
NtSetContextThread( GetCurrentThread(), &context );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
save_context( &context, sigcontext );
|
|
|
|
wait_suspend( &context );
|
|
|
|
restore_context( &context, sigcontext );
|
|
|
|
}
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* usr2_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGUSR2, used to set a thread context.
|
|
|
|
*/
|
|
|
|
static void usr2_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
2021-06-11 11:17:36 +02:00
|
|
|
struct syscall_frame *frame = arm64_thread_data()->syscall_frame;
|
|
|
|
ucontext_t *context = sigcontext;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!is_inside_syscall( sigcontext )) return;
|
|
|
|
|
|
|
|
FP_sig(context) = frame->fp;
|
|
|
|
LR_sig(context) = frame->lr;
|
|
|
|
SP_sig(context) = frame->sp;
|
|
|
|
PC_sig(context) = frame->pc;
|
|
|
|
PSTATE_sig(context) = frame->cpsr;
|
|
|
|
for (i = 0; i <= 28; i++) REGn_sig( i, context ) = frame->x[i];
|
|
|
|
restore_fpu( frame, context );
|
2020-06-09 12:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-01 12:52:05 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* get_thread_ldt_entry
|
|
|
|
*/
|
2020-06-18 12:37:50 +02:00
|
|
|
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
|
2020-06-01 12:52:05 +02:00
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSetLdtEntries (NTDLL.@)
|
|
|
|
* ZwSetLdtEntries (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 )
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_threading
|
|
|
|
*/
|
|
|
|
void signal_init_threading(void)
|
|
|
|
{
|
|
|
|
pthread_key_create( &teb_key, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_alloc_thread
|
|
|
|
*/
|
|
|
|
NTSTATUS signal_alloc_thread( TEB *teb )
|
|
|
|
{
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_free_thread
|
|
|
|
*/
|
|
|
|
void signal_free_thread( TEB *teb )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_thread
|
|
|
|
*/
|
|
|
|
void signal_init_thread( TEB *teb )
|
|
|
|
{
|
|
|
|
/* Win64/ARM applications expect the TEB pointer to be in the x18 platform register. */
|
|
|
|
__asm__ __volatile__( "mov x18, %0" : : "r" (teb) );
|
|
|
|
|
|
|
|
pthread_setspecific( teb_key, teb );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_process
|
|
|
|
*/
|
|
|
|
void signal_init_process(void)
|
|
|
|
{
|
|
|
|
struct sigaction sig_act;
|
2021-06-11 11:17:36 +02:00
|
|
|
void *kernel_stack = (char *)ntdll_get_thread_data()->kernel_stack + kernel_stack_size;
|
|
|
|
|
|
|
|
arm64_thread_data()->syscall_frame = (struct syscall_frame *)kernel_stack - 1;
|
2020-06-09 12:32:41 +02:00
|
|
|
|
|
|
|
sig_act.sa_mask = server_block_set;
|
|
|
|
sig_act.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
|
|
|
|
|
|
|
|
sig_act.sa_sigaction = int_handler;
|
|
|
|
if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = fpe_handler;
|
|
|
|
if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = abrt_handler;
|
|
|
|
if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = quit_handler;
|
|
|
|
if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = usr1_handler;
|
|
|
|
if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = usr2_handler;
|
|
|
|
if (sigaction( SIGUSR2, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = trap_handler;
|
|
|
|
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = segv_handler;
|
|
|
|
if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
|
2020-07-15 10:52:52 +02:00
|
|
|
sig_act.sa_sigaction = ill_handler;
|
2020-06-09 12:32:41 +02:00
|
|
|
if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
|
2020-07-15 10:52:52 +02:00
|
|
|
sig_act.sa_sigaction = bus_handler;
|
2020-06-09 12:32:41 +02:00
|
|
|
if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
perror("sigaction");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-02-19 19:08:48 +01:00
|
|
|
|
2020-06-03 16:32:02 +02:00
|
|
|
/***********************************************************************
|
2021-06-21 15:57:26 +02:00
|
|
|
* call_init_thunk
|
2020-06-03 16:32:02 +02:00
|
|
|
*/
|
2021-06-21 15:57:26 +02:00
|
|
|
void DECLSPEC_HIDDEN call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb )
|
2020-06-03 16:32:02 +02:00
|
|
|
{
|
2021-06-21 15:57:26 +02:00
|
|
|
struct arm64_thread_data *thread_data = (struct arm64_thread_data *)&teb->GdiTebBatch;
|
|
|
|
struct syscall_frame *frame = thread_data->syscall_frame;
|
|
|
|
CONTEXT *ctx, context = { CONTEXT_ALL };
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2021-06-21 15:57:26 +02:00
|
|
|
context.u.s.X0 = (DWORD64)entry;
|
|
|
|
context.u.s.X1 = (DWORD64)arg;
|
|
|
|
context.u.s.X18 = (DWORD64)teb;
|
|
|
|
context.Sp = (DWORD64)teb->Tib.StackBase;
|
|
|
|
context.Pc = (DWORD64)pRtlUserThreadStart;
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2021-06-21 15:57:26 +02:00
|
|
|
if (suspend) wait_suspend( &context );
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2021-06-21 15:57:26 +02:00
|
|
|
ctx = (CONTEXT *)((ULONG_PTR)context.Sp & ~15) - 1;
|
|
|
|
*ctx = context;
|
|
|
|
ctx->ContextFlags = CONTEXT_FULL;
|
|
|
|
NtSetContextThread( GetCurrentThread(), ctx );
|
|
|
|
|
|
|
|
frame->sp = (ULONG64)ctx;
|
|
|
|
frame->pc = (ULONG64)pLdrInitializeThunk;
|
|
|
|
frame->x[0] = (ULONG64)ctx;
|
|
|
|
frame->x[18] = (ULONG64)teb;
|
|
|
|
frame->restore_flags |= CONTEXT_INTEGER;
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2020-06-09 12:32:41 +02:00
|
|
|
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
|
2021-06-21 15:57:26 +02:00
|
|
|
__wine_syscall_dispatcher_return( frame, 0 );
|
2020-06-03 16:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* signal_start_thread
|
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC( signal_start_thread,
|
|
|
|
"stp x29, x30, [sp,#-16]!\n\t"
|
|
|
|
/* store exit frame */
|
|
|
|
"mov x29, sp\n\t"
|
2021-06-21 15:57:26 +02:00
|
|
|
"str x29, [x3, #0x2f0]\n\t" /* arm64_thread_data()->exit_frame */
|
2021-06-11 11:17:36 +02:00
|
|
|
/* set syscall frame */
|
2021-06-21 15:57:26 +02:00
|
|
|
"ldr x8, [x3, #0x2f8]\n\t" /* arm64_thread_data()->syscall_frame */
|
2021-06-11 11:17:36 +02:00
|
|
|
"cbnz x8, 1f\n\t"
|
|
|
|
"sub x8, sp, #0x320\n\t" /* sizeof(struct syscall_frame) */
|
2021-06-21 15:57:26 +02:00
|
|
|
"str x8, [x3, #0x2f8]\n\t" /* arm64_thread_data()->syscall_frame */
|
|
|
|
"1:\tmov sp, x8\n\t"
|
|
|
|
"bl " __ASM_NAME("call_init_thunk") )
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2021-06-14 12:56:38 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* signal_exit_thread
|
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC( signal_exit_thread,
|
2020-06-01 17:50:02 +02:00
|
|
|
"stp x29, x30, [sp,#-16]!\n\t"
|
2020-07-23 20:35:00 +02:00
|
|
|
"ldr x3, [x2, #0x2f0]\n\t" /* arm64_thread_data()->exit_frame */
|
|
|
|
"str xzr, [x2, #0x2f0]\n\t"
|
2020-06-01 12:52:05 +02:00
|
|
|
"cbz x3, 1f\n\t"
|
|
|
|
"mov sp, x3\n"
|
2020-06-01 17:50:02 +02:00
|
|
|
"1:\tldp x29, x30, [sp], #16\n\t"
|
|
|
|
"br x1" )
|
2020-06-01 12:52:05 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* NtCurrentTeb (NTDLL.@)
|
|
|
|
*/
|
|
|
|
TEB * WINAPI NtCurrentTeb(void)
|
|
|
|
{
|
|
|
|
return pthread_getspecific( teb_key );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __aarch64__ */
|