ptrace: Fix the timing of save_fp_regs, and Add copy fp_regs to child in clone_thread

refs #702
This commit is contained in:
Ken Sato
2017-09-27 17:02:30 +09:00
parent 79b977ac06
commit a1a2900606
3 changed files with 32 additions and 11 deletions

View File

@@ -1648,13 +1648,11 @@ release_fp_regs(struct thread *thread)
thread->fp_regs = NULL;
}
/*@
@ requires \valid(thread);
@*/
void
save_fp_regs(struct thread *thread)
static int
check_and_allocate_fp_regs(struct thread *thread)
{
int pages;
int pages;
int result = 0;
if (!thread->fp_regs) {
pages = (xsave_size + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
@@ -1663,12 +1661,26 @@ save_fp_regs(struct thread *thread)
if (!thread->fp_regs) {
kprintf("error: allocating fp_regs pages\n");
return;
result = 1;
goto out;
}
memset(thread->fp_regs, 0, sizeof(fp_regs_struct));
memset(thread->fp_regs, 0, pages * PAGE_SIZE);
}
out:
return result;
}
/*@
@ requires \valid(thread);
@*/
void
save_fp_regs(struct thread *thread)
{
if (check_and_allocate_fp_regs(thread) != 0) {
// alloc error
return;
}
if (xsave_available) {
unsigned int low, high;
@@ -1684,6 +1696,13 @@ save_fp_regs(struct thread *thread)
}
}
void copy_fp_regs(struct thread *from, struct thread *to)
{
if ((from->fp_regs != NULL) && (check_and_allocate_fp_regs(to) == 0)) {
memcpy(to->fp_regs, from->fp_regs, sizeof(fp_regs_struct));
}
}
#ifdef POSTK_DEBUG_TEMP_FIX_19
void
clear_fp_regs(struct thread *thread)