server: Set the context flags in get_thread_context to indicate which
parts of the returned context are valid.
This commit is contained in:
parent
b2c62c9455
commit
bd298b511e
|
@ -142,7 +142,7 @@ static void get_thread_context( struct thread *thread, unsigned int flags, CONTE
|
|||
context->Fpcr = regs.regs[EF_SIZE/8+31];
|
||||
context->SoftFpcr = 0; /* FIXME */
|
||||
}
|
||||
if (ptrace( PTRACE_SETREGS, pid, 0, ®s ) == -1) goto error;
|
||||
context->ContextFlags |= flags & CONTEXT_FULL;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -231,6 +231,7 @@ static void set_thread_context( struct thread *thread, unsigned int flags, const
|
|||
regs.regs[EF_SIZE/8+30] = context->FltF30;
|
||||
regs.regs[EF_SIZE/8+31] = context->Fpcr;
|
||||
}
|
||||
if (ptrace( PTRACE_SETREGS, pid, 0, ®s ) == -1) goto error;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -238,7 +239,7 @@ static void set_thread_context( struct thread *thread, unsigned int flags, const
|
|||
}
|
||||
|
||||
/* copy a context structure according to the flags */
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
||||
{
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
|
@ -317,6 +318,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
to->Fpcr = from->Fpcr;
|
||||
to->SoftFpcr = from->SoftFpcr;
|
||||
}
|
||||
to->ContextFlags |= flags;
|
||||
}
|
||||
|
||||
/* retrieve the current instruction pointer of a thread */
|
||||
|
@ -346,60 +348,36 @@ int tkill( int pid, int sig )
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* retrieve the current context of a thread */
|
||||
DECL_HANDLER(get_thread_context)
|
||||
/* retrieve the thread context */
|
||||
void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
|
||||
{
|
||||
struct thread *thread;
|
||||
void *data;
|
||||
int flags = req->flags & ~CONTEXT_ALPHA; /* get rid of CPU id */
|
||||
context->ContextFlags |= CONTEXT_ALPHA;
|
||||
flags &= ~CONTEXT_ALPHA; /* get rid of CPU id */
|
||||
|
||||
if (get_reply_max_size() < sizeof(CONTEXT))
|
||||
if (thread->context) /* thread is inside an exception event or suspended */
|
||||
{
|
||||
set_error( STATUS_INVALID_PARAMETER );
|
||||
return;
|
||||
copy_context( context, thread->context, flags );
|
||||
}
|
||||
if (!(thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT ))) return;
|
||||
|
||||
if ((data = set_reply_data_size( sizeof(CONTEXT) )))
|
||||
else if (flags && suspend_for_ptrace( thread ))
|
||||
{
|
||||
if (thread->context) /* thread is inside an exception event */
|
||||
{
|
||||
copy_context( data, thread->context, flags );
|
||||
flags = 0;
|
||||
}
|
||||
if (flags && suspend_for_ptrace( thread ))
|
||||
{
|
||||
get_thread_context( thread, flags, data );
|
||||
resume_after_ptrace( thread );
|
||||
}
|
||||
get_thread_context_ptrace( thread, flags, context );
|
||||
resume_after_ptrace( thread );
|
||||
}
|
||||
release_object( thread );
|
||||
}
|
||||
|
||||
/* set the current context of a thread */
|
||||
DECL_HANDLER(set_thread_context)
|
||||
/* set the thread context */
|
||||
void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned int flags )
|
||||
{
|
||||
struct thread *thread;
|
||||
int flags = req->flags & ~CONTEXT_ALPHA; /* get rid of CPU id */
|
||||
flags &= ~CONTEXT_ALPHA; /* get rid of CPU id */
|
||||
|
||||
if (get_req_data_size() < sizeof(CONTEXT))
|
||||
if (thread->context) /* thread is inside an exception event or suspended */
|
||||
{
|
||||
set_error( STATUS_INVALID_PARAMETER );
|
||||
return;
|
||||
copy_context( thread->context, context, flags );
|
||||
}
|
||||
if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
|
||||
else if (flags && suspend_for_ptrace( thread ))
|
||||
{
|
||||
if (thread->context) /* thread is inside an exception event */
|
||||
{
|
||||
copy_context( thread->context, get_req_data(), flags );
|
||||
flags = 0;
|
||||
}
|
||||
if (flags && suspend_for_ptrace( thread ))
|
||||
{
|
||||
set_thread_context( thread, flags, get_req_data() );
|
||||
resume_after_ptrace( thread );
|
||||
}
|
||||
release_object( thread );
|
||||
set_thread_context_ptrace( thread, flags, context );
|
||||
resume_after_ptrace( thread );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->SegFs = regs.fs;
|
||||
context->SegGs = regs.gs;
|
||||
}
|
||||
context->ContextFlags |= flags & CONTEXT_FULL;
|
||||
}
|
||||
if (flags & CONTEXT_DEBUG_REGISTERS)
|
||||
{
|
||||
|
@ -156,6 +157,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
if (get_debug_reg( pid, 3, &context->Dr3 ) == -1) goto error;
|
||||
if (get_debug_reg( pid, 6, &context->Dr6 ) == -1) goto error;
|
||||
if (get_debug_reg( pid, 7, &context->Dr7 ) == -1) goto error;
|
||||
context->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
{
|
||||
|
@ -163,6 +165,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
/* correct structure (the same as fsave/frstor) */
|
||||
if (ptrace( PTRACE_GETFPREGS, pid, 0, &context->FloatSave ) == -1) goto error;
|
||||
context->FloatSave.Cr0NpxState = 0; /* FIXME */
|
||||
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -263,6 +266,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->SegFs = regs.r_fs & 0xffff;
|
||||
context->SegGs = regs.r_gs & 0xffff;
|
||||
}
|
||||
context->ContextFlags |= flags & CONTEXT_FULL;
|
||||
}
|
||||
if (flags & CONTEXT_DEBUG_REGISTERS)
|
||||
{
|
||||
|
@ -274,6 +278,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
/* correct structure (the same as fsave/frstor) */
|
||||
if (ptrace( PTRACE_GETFPREGS, pid, (int) &context->FloatSave, 0 ) == -1) goto error;
|
||||
context->FloatSave.Cr0NpxState = 0; /* FIXME */
|
||||
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -371,6 +376,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->SegFs = regs.r_fs & 0xffff;
|
||||
context->SegGs = regs.r_gs & 0xffff;
|
||||
}
|
||||
context->ContextFlags |= flags & CONTEXT_FULL;
|
||||
}
|
||||
if (flags & CONTEXT_DEBUG_REGISTERS)
|
||||
{
|
||||
|
@ -394,7 +400,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->Dr6 = dbregs.dr6;
|
||||
context->Dr7 = dbregs.dr7;
|
||||
#endif
|
||||
|
||||
context->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
|
||||
#endif
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
|
@ -403,6 +409,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
/* correct structure (the same as fsave/frstor) */
|
||||
if (ptrace( PTRACE_GETFPREGS, pid, (caddr_t) &context->FloatSave, 0 ) == -1) goto error;
|
||||
context->FloatSave.Cr0NpxState = 0; /* FIXME */
|
||||
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -494,7 +501,7 @@ static void set_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
|
||||
|
||||
/* copy a context structure according to the flags */
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
||||
{
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
|
@ -527,6 +534,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
}
|
||||
/* we don't bother copying the debug registers, since they */
|
||||
/* always need to be accessed by ptrace anyway */
|
||||
to->ContextFlags |= flags & ~CONTEXT_DEBUG_REGISTERS;
|
||||
}
|
||||
|
||||
/* retrieve the current instruction pointer of a thread */
|
||||
|
@ -574,6 +582,7 @@ int tkill( int pid, int sig )
|
|||
/* retrieve the thread context */
|
||||
void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
|
||||
{
|
||||
context->ContextFlags |= CONTEXT_i386;
|
||||
flags &= ~CONTEXT_i386; /* get rid of CPU id */
|
||||
|
||||
if (thread->context) /* thread is inside an exception event or suspended */
|
||||
|
|
|
@ -56,28 +56,27 @@
|
|||
static void get_thread_context_ptrace( struct thread *thread, unsigned int flags, CONTEXT *context )
|
||||
{
|
||||
int pid = get_ptrace_pid(thread);
|
||||
if (flags & CONTEXT_FULL)
|
||||
if (flags & CONTEXT_INTEGER)
|
||||
{
|
||||
if (flags & CONTEXT_INTEGER)
|
||||
{
|
||||
#define XREG(x,y) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->y) == -1) goto error;
|
||||
#define IREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error;
|
||||
IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
|
||||
IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
|
||||
IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
|
||||
IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
|
||||
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
||||
IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
|
||||
IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
|
||||
IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
|
||||
IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
|
||||
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
||||
#undef IREG
|
||||
XREG(37,Xer);
|
||||
XREG(38,Cr);
|
||||
}
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
XREG(32,Iar);
|
||||
XREG(33,Msr);
|
||||
XREG(35,Ctr);
|
||||
XREG(36,Lr); /* 36 is LNK ... probably Lr ? */
|
||||
}
|
||||
XREG(37,Xer);
|
||||
XREG(38,Cr);
|
||||
context->ContextFlags |= CONTEXT_INTEGER;
|
||||
}
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
XREG(32,Iar);
|
||||
XREG(33,Msr);
|
||||
XREG(35,Ctr);
|
||||
XREG(36,Lr); /* 36 is LNK ... probably Lr ? */
|
||||
context->ContextFlags |= CONTEXT_CONTROL;
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
{
|
||||
|
@ -115,6 +114,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
FREG(30);
|
||||
FREG(31);
|
||||
XREG((48+32*2),Fpscr);
|
||||
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -201,13 +201,14 @@ static void set_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
#define FREG(x) to->Fpr##x = from->Fpr##x;
|
||||
#define CREG(x) to->x = from->x;
|
||||
/* copy a context structure according to the flags */
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
||||
{
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
CREG(Msr);
|
||||
CREG(Ctr);
|
||||
CREG(Iar);
|
||||
to->ContextFlags |= CONTEXT_CONTROL;
|
||||
}
|
||||
if (flags & CONTEXT_INTEGER)
|
||||
{
|
||||
|
@ -218,6 +219,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
||||
CREG(Xer);
|
||||
CREG(Cr);
|
||||
to->ContextFlags |= CONTEXT_INTEGER;
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
{
|
||||
|
@ -254,6 +256,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
FREG(30);
|
||||
FREG(31);
|
||||
CREG(Fpscr);
|
||||
to->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->wim = 0; /* FIXME */
|
||||
context->tbr = 0; /* FIXME */
|
||||
}
|
||||
context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER);
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
{
|
||||
|
@ -105,7 +106,7 @@ static void set_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
|
||||
|
||||
/* copy a context structure according to the flags */
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
||||
{
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
|
@ -155,6 +156,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
{
|
||||
/* FIXME */
|
||||
}
|
||||
context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER);
|
||||
}
|
||||
|
||||
/* retrieve the current instruction pointer of a thread */
|
||||
|
@ -187,6 +189,7 @@ int tkill( int pid, int sig )
|
|||
/* retrieve the thread context */
|
||||
void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
|
||||
{
|
||||
context->ContextFlags |= CONTEXT_SPARC;
|
||||
flags &= ~CONTEXT_SPARC; /* get rid of CPU id */
|
||||
|
||||
if (thread->context) /* thread is inside an exception event or suspended */
|
||||
|
|
|
@ -106,6 +106,7 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
context->SegFs = regs.fs;
|
||||
context->SegGs = regs.gs;
|
||||
}
|
||||
context->ContextFlags |= flags & CONTEXT_FULL;
|
||||
}
|
||||
if (flags & CONTEXT_DEBUG_REGISTERS)
|
||||
{
|
||||
|
@ -115,12 +116,14 @@ static void get_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
if (get_debug_reg( pid, 3, &context->Dr3 ) == -1) goto error;
|
||||
if (get_debug_reg( pid, 6, &context->Dr6 ) == -1) goto error;
|
||||
if (get_debug_reg( pid, 7, &context->Dr7 ) == -1) goto error;
|
||||
context->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
|
||||
}
|
||||
if (flags & CONTEXT_FLOATING_POINT)
|
||||
{
|
||||
/* we can use context->FloatSave directly as it is using the */
|
||||
/* correct structure (the same as fsave/frstor) */
|
||||
if (ptrace( PTRACE_GETFPREGS, pid, 0, &context->u.FltSave ) == -1) goto error;
|
||||
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
||||
}
|
||||
return;
|
||||
error:
|
||||
|
@ -200,7 +203,7 @@ static void set_thread_context_ptrace( struct thread *thread, unsigned int flags
|
|||
|
||||
|
||||
/* copy a context structure according to the flags */
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
||||
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
||||
{
|
||||
if (flags & CONTEXT_CONTROL)
|
||||
{
|
||||
|
@ -242,6 +245,7 @@ static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
|
|||
}
|
||||
/* we don't bother copying the debug registers, since they */
|
||||
/* always need to be accessed by ptrace anyway */
|
||||
to->ContextFlags |= flags & ~CONTEXT_DEBUG_REGISTERS;
|
||||
}
|
||||
|
||||
/* retrieve the current instruction pointer of a thread */
|
||||
|
@ -285,6 +289,7 @@ int tkill( int pid, int sig )
|
|||
/* retrieve the thread context */
|
||||
void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
|
||||
{
|
||||
context->ContextFlags |= CONTEXT_AMD64;
|
||||
flags &= ~CONTEXT_AMD64; /* get rid of CPU id */
|
||||
|
||||
if (thread->context) /* thread is inside an exception event or suspended */
|
||||
|
|
Loading…
Reference in New Issue