Merge branch 'work.regset' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull ptrace regset updates from Al Viro: "Internal regset API changes: - regularize copy_regset_{to,from}_user() callers - switch to saner calling conventions for ->get() - kill user_regset_copyout() The ->put() side of things will have to wait for the next cycle, unfortunately. The balance is about -1KLoC and replacements for ->get() instances are a lot saner" * 'work.regset' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (41 commits) regset: kill user_regset_copyout{,_zero}() regset(): kill ->get_size() regset: kill ->get() csky: switch to ->regset_get() xtensa: switch to ->regset_get() parisc: switch to ->regset_get() nds32: switch to ->regset_get() nios2: switch to ->regset_get() hexagon: switch to ->regset_get() h8300: switch to ->regset_get() openrisc: switch to ->regset_get() riscv: switch to ->regset_get() c6x: switch to ->regset_get() ia64: switch to ->regset_get() arc: switch to ->regset_get() arm: switch to ->regset_get() sh: convert to ->regset_get() arm64: switch to ->regset_get() mips: switch to ->regset_get() sparc: switch to ->regset_get() ...
This commit is contained in:
@@ -83,41 +83,25 @@ static int regwindow32_set(struct task_struct *target,
|
||||
|
||||
static int genregs32_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = target->thread.kregs;
|
||||
u32 uregs[16];
|
||||
int ret;
|
||||
|
||||
if (target == current)
|
||||
flush_user_windows();
|
||||
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
regs->u_regs,
|
||||
0, 16 * sizeof(u32));
|
||||
if (ret || !count)
|
||||
return ret;
|
||||
|
||||
if (pos < 32 * sizeof(u32)) {
|
||||
if (regwindow32_get(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
uregs,
|
||||
16 * sizeof(u32), 32 * sizeof(u32));
|
||||
if (ret || !count)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uregs[0] = regs->psr;
|
||||
uregs[1] = regs->pc;
|
||||
uregs[2] = regs->npc;
|
||||
uregs[3] = regs->y;
|
||||
uregs[4] = 0; /* WIM */
|
||||
uregs[5] = 0; /* TBR */
|
||||
return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
uregs,
|
||||
32 * sizeof(u32), 38 * sizeof(u32));
|
||||
membuf_write(&to, regs->u_regs, 16 * sizeof(u32));
|
||||
if (!to.left)
|
||||
return 0;
|
||||
if (regwindow32_get(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
membuf_write(&to, uregs, 16 * sizeof(u32));
|
||||
membuf_store(&to, regs->psr);
|
||||
membuf_store(&to, regs->pc);
|
||||
membuf_store(&to, regs->npc);
|
||||
membuf_store(&to, regs->y);
|
||||
return membuf_zero(&to, 2 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int genregs32_set(struct task_struct *target,
|
||||
@@ -139,19 +123,18 @@ static int genregs32_set(struct task_struct *target,
|
||||
if (ret || !count)
|
||||
return ret;
|
||||
|
||||
if (pos < 32 * sizeof(u32)) {
|
||||
if (regwindow32_get(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
uregs,
|
||||
16 * sizeof(u32), 32 * sizeof(u32));
|
||||
if (ret)
|
||||
return ret;
|
||||
if (regwindow32_set(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
if (!count)
|
||||
return 0;
|
||||
}
|
||||
if (regwindow32_get(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
uregs,
|
||||
16 * sizeof(u32), 32 * sizeof(u32));
|
||||
if (ret)
|
||||
return ret;
|
||||
if (regwindow32_set(target, regs, uregs))
|
||||
return -EFAULT;
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&psr,
|
||||
32 * sizeof(u32), 33 * sizeof(u32));
|
||||
@@ -182,46 +165,18 @@ static int genregs32_set(struct task_struct *target,
|
||||
|
||||
static int fpregs32_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const unsigned long *fpregs = target->thread.float_regs;
|
||||
int ret = 0;
|
||||
|
||||
#if 0
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
#endif
|
||||
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
fpregs,
|
||||
0, 32 * sizeof(u32));
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
32 * sizeof(u32),
|
||||
33 * sizeof(u32));
|
||||
if (!ret)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&target->thread.fsr,
|
||||
33 * sizeof(u32),
|
||||
34 * sizeof(u32));
|
||||
|
||||
if (!ret) {
|
||||
unsigned long val;
|
||||
|
||||
val = (1 << 8) | (8 << 16);
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&val,
|
||||
34 * sizeof(u32),
|
||||
35 * sizeof(u32));
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
35 * sizeof(u32), -1);
|
||||
|
||||
return ret;
|
||||
membuf_write(&to, target->thread.float_regs, 32 * sizeof(u32));
|
||||
membuf_zero(&to, sizeof(u32));
|
||||
membuf_write(&to, &target->thread.fsr, sizeof(u32));
|
||||
membuf_store(&to, (u32)((1 << 8) | (8 << 16)));
|
||||
return membuf_zero(&to, 64 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int fpregs32_set(struct task_struct *target,
|
||||
@@ -243,13 +198,11 @@ static int fpregs32_set(struct task_struct *target,
|
||||
user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
|
||||
32 * sizeof(u32),
|
||||
33 * sizeof(u32));
|
||||
if (!ret && count > 0) {
|
||||
if (!ret)
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&target->thread.fsr,
|
||||
33 * sizeof(u32),
|
||||
34 * sizeof(u32));
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
|
||||
34 * sizeof(u32), -1);
|
||||
@@ -268,7 +221,7 @@ static const struct user_regset sparc32_regsets[] = {
|
||||
.core_note_type = NT_PRSTATUS,
|
||||
.n = 38,
|
||||
.size = sizeof(u32), .align = sizeof(u32),
|
||||
.get = genregs32_get, .set = genregs32_set
|
||||
.regset_get = genregs32_get, .set = genregs32_set
|
||||
},
|
||||
/* Format is:
|
||||
* F0 --> F31
|
||||
@@ -284,10 +237,104 @@ static const struct user_regset sparc32_regsets[] = {
|
||||
.core_note_type = NT_PRFPREG,
|
||||
.n = 99,
|
||||
.size = sizeof(u32), .align = sizeof(u32),
|
||||
.get = fpregs32_get, .set = fpregs32_set
|
||||
.regset_get = fpregs32_get, .set = fpregs32_set
|
||||
},
|
||||
};
|
||||
|
||||
static int getregs_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = target->thread.kregs;
|
||||
|
||||
if (target == current)
|
||||
flush_user_windows();
|
||||
|
||||
membuf_store(&to, regs->psr);
|
||||
membuf_store(&to, regs->pc);
|
||||
membuf_store(&to, regs->npc);
|
||||
membuf_store(&to, regs->y);
|
||||
return membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int setregs_set(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
{
|
||||
struct pt_regs *regs = target->thread.kregs;
|
||||
u32 v[4];
|
||||
int ret;
|
||||
|
||||
if (target == current)
|
||||
flush_user_windows();
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
v,
|
||||
0, 4 * sizeof(u32));
|
||||
if (ret)
|
||||
return ret;
|
||||
regs->psr = (regs->psr & ~(PSR_ICC | PSR_SYSCALL)) |
|
||||
(v[0] & (PSR_ICC | PSR_SYSCALL));
|
||||
regs->pc = v[1];
|
||||
regs->npc = v[2];
|
||||
regs->y = v[3];
|
||||
return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
regs->u_regs + 1,
|
||||
4 * sizeof(u32) , 19 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int getfpregs_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
struct membuf to)
|
||||
{
|
||||
#if 0
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
#endif
|
||||
membuf_write(&to, &target->thread.float_regs, 32 * sizeof(u32));
|
||||
membuf_write(&to, &target->thread.fsr, sizeof(u32));
|
||||
return membuf_zero(&to, 35 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int setfpregs_set(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
{
|
||||
unsigned long *fpregs = target->thread.float_regs;
|
||||
int ret;
|
||||
|
||||
#if 0
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
#endif
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
fpregs,
|
||||
0, 32 * sizeof(u32));
|
||||
if (ret)
|
||||
return ret;
|
||||
return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&target->thread.fsr,
|
||||
32 * sizeof(u32),
|
||||
33 * sizeof(u32));
|
||||
}
|
||||
|
||||
static const struct user_regset ptrace32_regsets[] = {
|
||||
[REGSET_GENERAL] = {
|
||||
.n = 19, .size = sizeof(u32),
|
||||
.regset_get = getregs_get, .set = setregs_set,
|
||||
},
|
||||
[REGSET_FP] = {
|
||||
.n = 68, .size = sizeof(u32),
|
||||
.regset_get = getfpregs_get, .set = setfpregs_set,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct user_regset_view ptrace32_view = {
|
||||
.regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
|
||||
};
|
||||
|
||||
static const struct user_regset_view user_sparc32_view = {
|
||||
.name = "sparc", .e_machine = EM_SPARC,
|
||||
.regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
|
||||
@@ -315,74 +362,44 @@ long arch_ptrace(struct task_struct *child, long request,
|
||||
{
|
||||
unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
|
||||
void __user *addr2p;
|
||||
const struct user_regset_view *view;
|
||||
struct pt_regs __user *pregs;
|
||||
struct fps __user *fps;
|
||||
int ret;
|
||||
|
||||
view = task_user_regset_view(current);
|
||||
addr2p = (void __user *) addr2;
|
||||
pregs = (struct pt_regs __user *) addr;
|
||||
fps = (struct fps __user *) addr;
|
||||
|
||||
switch(request) {
|
||||
case PTRACE_GETREGS: {
|
||||
ret = copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u32),
|
||||
4 * sizeof(u32),
|
||||
&pregs->psr);
|
||||
if (!ret)
|
||||
copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u32),
|
||||
15 * sizeof(u32),
|
||||
&pregs->u_regs[0]);
|
||||
ret = copy_regset_to_user(child, &ptrace32_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u32),
|
||||
pregs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PTRACE_SETREGS: {
|
||||
ret = copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u32),
|
||||
4 * sizeof(u32),
|
||||
&pregs->psr);
|
||||
if (!ret)
|
||||
copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u32),
|
||||
15 * sizeof(u32),
|
||||
&pregs->u_regs[0]);
|
||||
ret = copy_regset_from_user(child, &ptrace32_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u32),
|
||||
pregs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PTRACE_GETFPREGS: {
|
||||
ret = copy_regset_to_user(child, view, REGSET_FP,
|
||||
0 * sizeof(u32),
|
||||
32 * sizeof(u32),
|
||||
&fps->regs[0]);
|
||||
if (!ret)
|
||||
ret = copy_regset_to_user(child, view, REGSET_FP,
|
||||
33 * sizeof(u32),
|
||||
1 * sizeof(u32),
|
||||
&fps->fsr);
|
||||
|
||||
if (!ret) {
|
||||
if (__put_user(0, &fps->fpqd) ||
|
||||
__put_user(0, &fps->flags) ||
|
||||
__put_user(0, &fps->extra) ||
|
||||
clear_user(fps->fpq, sizeof(fps->fpq)))
|
||||
ret = -EFAULT;
|
||||
}
|
||||
ret = copy_regset_to_user(child, &ptrace32_view,
|
||||
REGSET_FP, 0,
|
||||
68 * sizeof(u32),
|
||||
fps);
|
||||
break;
|
||||
}
|
||||
|
||||
case PTRACE_SETFPREGS: {
|
||||
ret = copy_regset_from_user(child, view, REGSET_FP,
|
||||
0 * sizeof(u32),
|
||||
32 * sizeof(u32),
|
||||
&fps->regs[0]);
|
||||
if (!ret)
|
||||
ret = copy_regset_from_user(child, view, REGSET_FP,
|
||||
33 * sizeof(u32),
|
||||
1 * sizeof(u32),
|
||||
&fps->fsr);
|
||||
ret = copy_regset_from_user(child, &ptrace32_view,
|
||||
REGSET_FP, 0,
|
||||
33 * sizeof(u32),
|
||||
fps);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -246,52 +246,23 @@ enum sparc_regset {
|
||||
|
||||
static int genregs64_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = task_pt_regs(target);
|
||||
int ret;
|
||||
struct reg_window window;
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
regs->u_regs,
|
||||
0, 16 * sizeof(u64));
|
||||
if (!ret && count && pos < (32 * sizeof(u64))) {
|
||||
struct reg_window window;
|
||||
|
||||
if (regwindow64_get(target, regs, &window))
|
||||
return -EFAULT;
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&window,
|
||||
16 * sizeof(u64),
|
||||
32 * sizeof(u64));
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
/* TSTATE, TPC, TNPC */
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
®s->tstate,
|
||||
32 * sizeof(u64),
|
||||
35 * sizeof(u64));
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
unsigned long y = regs->y;
|
||||
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&y,
|
||||
35 * sizeof(u64),
|
||||
36 * sizeof(u64));
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
36 * sizeof(u64), -1);
|
||||
|
||||
}
|
||||
return ret;
|
||||
membuf_write(&to, regs->u_regs, 16 * sizeof(u64));
|
||||
if (!to.left)
|
||||
return 0;
|
||||
if (regwindow64_get(target, regs, &window))
|
||||
return -EFAULT;
|
||||
membuf_write(&to, &window, 16 * sizeof(u64));
|
||||
/* TSTATE, TPC, TNPC */
|
||||
membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
|
||||
return membuf_store(&to, (u64)regs->y);
|
||||
}
|
||||
|
||||
static int genregs64_set(struct task_struct *target,
|
||||
@@ -370,69 +341,32 @@ static int genregs64_set(struct task_struct *target,
|
||||
|
||||
static int fpregs64_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const unsigned long *fpregs = task_thread_info(target)->fpregs;
|
||||
unsigned long fprs, fsr, gsr;
|
||||
int ret;
|
||||
struct thread_info *t = task_thread_info(target);
|
||||
unsigned long fprs;
|
||||
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
|
||||
fprs = task_thread_info(target)->fpsaved[0];
|
||||
fprs = t->fpsaved[0];
|
||||
|
||||
if (fprs & FPRS_DL)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
fpregs,
|
||||
0, 16 * sizeof(u64));
|
||||
membuf_write(&to, t->fpregs, 16 * sizeof(u64));
|
||||
else
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
0,
|
||||
16 * sizeof(u64));
|
||||
|
||||
if (!ret) {
|
||||
if (fprs & FPRS_DU)
|
||||
ret = user_regset_copyout(&pos, &count,
|
||||
&kbuf, &ubuf,
|
||||
fpregs + 16,
|
||||
16 * sizeof(u64),
|
||||
32 * sizeof(u64));
|
||||
else
|
||||
ret = user_regset_copyout_zero(&pos, &count,
|
||||
&kbuf, &ubuf,
|
||||
16 * sizeof(u64),
|
||||
32 * sizeof(u64));
|
||||
}
|
||||
membuf_zero(&to, 16 * sizeof(u64));
|
||||
|
||||
if (fprs & FPRS_DU)
|
||||
membuf_write(&to, t->fpregs + 16, 16 * sizeof(u64));
|
||||
else
|
||||
membuf_zero(&to, 16 * sizeof(u64));
|
||||
if (fprs & FPRS_FEF) {
|
||||
fsr = task_thread_info(target)->xfsr[0];
|
||||
gsr = task_thread_info(target)->gsr[0];
|
||||
membuf_store(&to, t->xfsr[0]);
|
||||
membuf_store(&to, t->gsr[0]);
|
||||
} else {
|
||||
fsr = gsr = 0;
|
||||
membuf_zero(&to, 2 * sizeof(u64));
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&fsr,
|
||||
32 * sizeof(u64),
|
||||
33 * sizeof(u64));
|
||||
if (!ret)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&gsr,
|
||||
33 * sizeof(u64),
|
||||
34 * sizeof(u64));
|
||||
if (!ret)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&fprs,
|
||||
34 * sizeof(u64),
|
||||
35 * sizeof(u64));
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
35 * sizeof(u64), -1);
|
||||
|
||||
return ret;
|
||||
return membuf_store(&to, fprs);
|
||||
}
|
||||
|
||||
static int fpregs64_set(struct task_struct *target,
|
||||
@@ -490,7 +424,7 @@ static const struct user_regset sparc64_regsets[] = {
|
||||
.core_note_type = NT_PRSTATUS,
|
||||
.n = 36,
|
||||
.size = sizeof(u64), .align = sizeof(u64),
|
||||
.get = genregs64_get, .set = genregs64_set
|
||||
.regset_get = genregs64_get, .set = genregs64_set
|
||||
},
|
||||
/* Format is:
|
||||
* F0 --> F63
|
||||
@@ -502,10 +436,96 @@ static const struct user_regset sparc64_regsets[] = {
|
||||
.core_note_type = NT_PRFPREG,
|
||||
.n = 35,
|
||||
.size = sizeof(u64), .align = sizeof(u64),
|
||||
.get = fpregs64_get, .set = fpregs64_set
|
||||
.regset_get = fpregs64_get, .set = fpregs64_set
|
||||
},
|
||||
};
|
||||
|
||||
static int getregs64_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = task_pt_regs(target);
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u64));
|
||||
membuf_store(&to, (u64)0);
|
||||
membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
|
||||
return membuf_store(&to, (u64)regs->y);
|
||||
}
|
||||
|
||||
static int setregs64_set(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(target);
|
||||
unsigned long y = regs->y;
|
||||
unsigned long tstate;
|
||||
int ret;
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
regs->u_regs + 1,
|
||||
0 * sizeof(u64),
|
||||
15 * sizeof(u64));
|
||||
if (ret)
|
||||
return ret;
|
||||
ret =user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
|
||||
15 * sizeof(u64), 16 * sizeof(u64));
|
||||
if (ret)
|
||||
return ret;
|
||||
/* TSTATE */
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&tstate,
|
||||
16 * sizeof(u64),
|
||||
17 * sizeof(u64));
|
||||
if (ret)
|
||||
return ret;
|
||||
/* Only the condition codes and the "in syscall"
|
||||
* state can be modified in the %tstate register.
|
||||
*/
|
||||
tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
|
||||
regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
|
||||
regs->tstate |= tstate;
|
||||
|
||||
/* TPC, TNPC */
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
®s->tpc,
|
||||
17 * sizeof(u64),
|
||||
19 * sizeof(u64));
|
||||
if (ret)
|
||||
return ret;
|
||||
/* Y */
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&y,
|
||||
19 * sizeof(u64),
|
||||
20 * sizeof(u64));
|
||||
if (!ret)
|
||||
regs->y = y;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct user_regset ptrace64_regsets[] = {
|
||||
/* Format is:
|
||||
* G1 --> G7
|
||||
* O0 --> O7
|
||||
* 0
|
||||
* TSTATE, TPC, TNPC, Y
|
||||
*/
|
||||
[REGSET_GENERAL] = {
|
||||
.n = 20, .size = sizeof(u64),
|
||||
.regset_get = getregs64_get, .set = setregs64_set,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct user_regset_view ptrace64_view = {
|
||||
.regsets = ptrace64_regsets, .n = ARRAY_SIZE(ptrace64_regsets)
|
||||
};
|
||||
|
||||
static const struct user_regset_view user_sparc64_view = {
|
||||
.name = "sparc64", .e_machine = EM_SPARCV9,
|
||||
.regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
|
||||
@@ -514,108 +534,28 @@ static const struct user_regset_view user_sparc64_view = {
|
||||
#ifdef CONFIG_COMPAT
|
||||
static int genregs32_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = task_pt_regs(target);
|
||||
compat_ulong_t __user *reg_window;
|
||||
compat_ulong_t *k = kbuf;
|
||||
compat_ulong_t __user *u = ubuf;
|
||||
compat_ulong_t reg;
|
||||
u32 uregs[16];
|
||||
int i;
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
pos /= sizeof(reg);
|
||||
count /= sizeof(reg);
|
||||
|
||||
if (kbuf) {
|
||||
for (; count > 0 && pos < 16; count--)
|
||||
*k++ = regs->u_regs[pos++];
|
||||
|
||||
reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
|
||||
reg_window -= 16;
|
||||
if (target == current) {
|
||||
for (; count > 0 && pos < 32; count--) {
|
||||
if (get_user(*k++, ®_window[pos++]))
|
||||
return -EFAULT;
|
||||
}
|
||||
} else {
|
||||
for (; count > 0 && pos < 32; count--) {
|
||||
if (access_process_vm(target,
|
||||
(unsigned long)
|
||||
®_window[pos],
|
||||
k, sizeof(*k),
|
||||
FOLL_FORCE)
|
||||
!= sizeof(*k))
|
||||
return -EFAULT;
|
||||
k++;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (; count > 0 && pos < 16; count--) {
|
||||
if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
|
||||
reg_window -= 16;
|
||||
if (target == current) {
|
||||
for (; count > 0 && pos < 32; count--) {
|
||||
if (get_user(reg, ®_window[pos++]) ||
|
||||
put_user(reg, u++))
|
||||
return -EFAULT;
|
||||
}
|
||||
} else {
|
||||
for (; count > 0 && pos < 32; count--) {
|
||||
if (access_process_vm(target,
|
||||
(unsigned long)
|
||||
®_window[pos++],
|
||||
®, sizeof(reg),
|
||||
FOLL_FORCE)
|
||||
!= sizeof(reg))
|
||||
return -EFAULT;
|
||||
if (put_user(reg, u++))
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (count > 0) {
|
||||
switch (pos) {
|
||||
case 32: /* PSR */
|
||||
reg = tstate_to_psr(regs->tstate);
|
||||
break;
|
||||
case 33: /* PC */
|
||||
reg = regs->tpc;
|
||||
break;
|
||||
case 34: /* NPC */
|
||||
reg = regs->tnpc;
|
||||
break;
|
||||
case 35: /* Y */
|
||||
reg = regs->y;
|
||||
break;
|
||||
case 36: /* WIM */
|
||||
case 37: /* TBR */
|
||||
reg = 0;
|
||||
break;
|
||||
default:
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (kbuf)
|
||||
*k++ = reg;
|
||||
else if (put_user(reg, u++))
|
||||
return -EFAULT;
|
||||
pos++;
|
||||
count--;
|
||||
}
|
||||
finish:
|
||||
pos *= sizeof(reg);
|
||||
count *= sizeof(reg);
|
||||
|
||||
return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
38 * sizeof(reg), -1);
|
||||
for (i = 0; i < 16; i++)
|
||||
membuf_store(&to, (u32)regs->u_regs[i]);
|
||||
if (!to.left)
|
||||
return 0;
|
||||
if (get_from_target(target, regs->u_regs[UREG_I6],
|
||||
uregs, sizeof(uregs)))
|
||||
return -EFAULT;
|
||||
membuf_write(&to, uregs, 16 * sizeof(u32));
|
||||
membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
|
||||
membuf_store(&to, (u32)(regs->tpc));
|
||||
membuf_store(&to, (u32)(regs->tnpc));
|
||||
membuf_store(&to, (u32)(regs->y));
|
||||
return membuf_zero(&to, 2 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int genregs32_set(struct task_struct *target,
|
||||
@@ -737,56 +677,24 @@ finish:
|
||||
|
||||
static int fpregs32_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
void *kbuf, void __user *ubuf)
|
||||
struct membuf to)
|
||||
{
|
||||
const unsigned long *fpregs = task_thread_info(target)->fpregs;
|
||||
compat_ulong_t enabled;
|
||||
unsigned long fprs;
|
||||
compat_ulong_t fsr;
|
||||
int ret = 0;
|
||||
struct thread_info *t = task_thread_info(target);
|
||||
bool enabled;
|
||||
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
|
||||
fprs = task_thread_info(target)->fpsaved[0];
|
||||
if (fprs & FPRS_FEF) {
|
||||
fsr = task_thread_info(target)->xfsr[0];
|
||||
enabled = 1;
|
||||
} else {
|
||||
fsr = 0;
|
||||
enabled = 0;
|
||||
}
|
||||
enabled = t->fpsaved[0] & FPRS_FEF;
|
||||
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
fpregs,
|
||||
0, 32 * sizeof(u32));
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
32 * sizeof(u32),
|
||||
33 * sizeof(u32));
|
||||
if (!ret)
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&fsr,
|
||||
33 * sizeof(u32),
|
||||
34 * sizeof(u32));
|
||||
|
||||
if (!ret) {
|
||||
compat_ulong_t val;
|
||||
|
||||
val = (enabled << 8) | (8 << 16);
|
||||
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
|
||||
&val,
|
||||
34 * sizeof(u32),
|
||||
35 * sizeof(u32));
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
|
||||
35 * sizeof(u32), -1);
|
||||
|
||||
return ret;
|
||||
membuf_write(&to, t->fpregs, 32 * sizeof(u32));
|
||||
membuf_zero(&to, sizeof(u32));
|
||||
if (enabled)
|
||||
membuf_store(&to, (u32)t->xfsr[0]);
|
||||
else
|
||||
membuf_zero(&to, sizeof(u32));
|
||||
membuf_store(&to, (u32)((enabled << 8) | (8 << 16)));
|
||||
return membuf_zero(&to, 64 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int fpregs32_set(struct task_struct *target,
|
||||
@@ -847,7 +755,7 @@ static const struct user_regset sparc32_regsets[] = {
|
||||
.core_note_type = NT_PRSTATUS,
|
||||
.n = 38,
|
||||
.size = sizeof(u32), .align = sizeof(u32),
|
||||
.get = genregs32_get, .set = genregs32_set
|
||||
.regset_get = genregs32_get, .set = genregs32_set
|
||||
},
|
||||
/* Format is:
|
||||
* F0 --> F31
|
||||
@@ -863,10 +771,133 @@ static const struct user_regset sparc32_regsets[] = {
|
||||
.core_note_type = NT_PRFPREG,
|
||||
.n = 99,
|
||||
.size = sizeof(u32), .align = sizeof(u32),
|
||||
.get = fpregs32_get, .set = fpregs32_set
|
||||
.regset_get = fpregs32_get, .set = fpregs32_set
|
||||
},
|
||||
};
|
||||
|
||||
static int getregs_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
struct membuf to)
|
||||
{
|
||||
const struct pt_regs *regs = task_pt_regs(target);
|
||||
int i;
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
|
||||
membuf_store(&to, (u32)(regs->tpc));
|
||||
membuf_store(&to, (u32)(regs->tnpc));
|
||||
membuf_store(&to, (u32)(regs->y));
|
||||
for (i = 1; i < 16; i++)
|
||||
membuf_store(&to, (u32)regs->u_regs[i]);
|
||||
return to.left;
|
||||
}
|
||||
|
||||
static int setregs_set(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(target);
|
||||
unsigned long tstate;
|
||||
u32 uregs[19];
|
||||
int i, ret;
|
||||
|
||||
if (target == current)
|
||||
flushw_user();
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
uregs,
|
||||
0, 19 * sizeof(u32));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
tstate = regs->tstate;
|
||||
tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
|
||||
tstate |= psr_to_tstate_icc(uregs[0]);
|
||||
if (uregs[0] & PSR_SYSCALL)
|
||||
tstate |= TSTATE_SYSCALL;
|
||||
regs->tstate = tstate;
|
||||
regs->tpc = uregs[1];
|
||||
regs->tnpc = uregs[2];
|
||||
regs->y = uregs[3];
|
||||
|
||||
for (i = 1; i < 15; i++)
|
||||
regs->u_regs[i] = uregs[3 + i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getfpregs_get(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
struct membuf to)
|
||||
{
|
||||
struct thread_info *t = task_thread_info(target);
|
||||
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
|
||||
membuf_write(&to, t->fpregs, 32 * sizeof(u32));
|
||||
if (t->fpsaved[0] & FPRS_FEF)
|
||||
membuf_store(&to, (u32)t->xfsr[0]);
|
||||
else
|
||||
membuf_zero(&to, sizeof(u32));
|
||||
return membuf_zero(&to, 35 * sizeof(u32));
|
||||
}
|
||||
|
||||
static int setfpregs_set(struct task_struct *target,
|
||||
const struct user_regset *regset,
|
||||
unsigned int pos, unsigned int count,
|
||||
const void *kbuf, const void __user *ubuf)
|
||||
{
|
||||
unsigned long *fpregs = task_thread_info(target)->fpregs;
|
||||
unsigned long fprs;
|
||||
int ret;
|
||||
|
||||
if (target == current)
|
||||
save_and_clear_fpu();
|
||||
|
||||
fprs = task_thread_info(target)->fpsaved[0];
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
fpregs,
|
||||
0, 32 * sizeof(u32));
|
||||
if (!ret) {
|
||||
compat_ulong_t fsr;
|
||||
unsigned long val;
|
||||
|
||||
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
|
||||
&fsr,
|
||||
32 * sizeof(u32),
|
||||
33 * sizeof(u32));
|
||||
if (!ret) {
|
||||
val = task_thread_info(target)->xfsr[0];
|
||||
val &= 0xffffffff00000000UL;
|
||||
val |= fsr;
|
||||
task_thread_info(target)->xfsr[0] = val;
|
||||
}
|
||||
}
|
||||
|
||||
fprs |= (FPRS_FEF | FPRS_DL);
|
||||
task_thread_info(target)->fpsaved[0] = fprs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct user_regset ptrace32_regsets[] = {
|
||||
[REGSET_GENERAL] = {
|
||||
.n = 19, .size = sizeof(u32),
|
||||
.regset_get = getregs_get, .set = setregs_set,
|
||||
},
|
||||
[REGSET_FP] = {
|
||||
.n = 68, .size = sizeof(u32),
|
||||
.regset_get = getfpregs_get, .set = setfpregs_set,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct user_regset_view ptrace32_view = {
|
||||
.regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
|
||||
};
|
||||
|
||||
static const struct user_regset_view user_sparc32_view = {
|
||||
.name = "sparc", .e_machine = EM_SPARC,
|
||||
.regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
|
||||
@@ -898,7 +929,6 @@ struct compat_fps {
|
||||
long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
|
||||
compat_ulong_t caddr, compat_ulong_t cdata)
|
||||
{
|
||||
const struct user_regset_view *view = task_user_regset_view(current);
|
||||
compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
|
||||
struct pt_regs32 __user *pregs;
|
||||
struct compat_fps __user *fps;
|
||||
@@ -916,58 +946,31 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
|
||||
break;
|
||||
|
||||
case PTRACE_GETREGS:
|
||||
ret = copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u32),
|
||||
4 * sizeof(u32),
|
||||
&pregs->psr);
|
||||
if (!ret)
|
||||
ret = copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u32),
|
||||
15 * sizeof(u32),
|
||||
&pregs->u_regs[0]);
|
||||
ret = copy_regset_to_user(child, &ptrace32_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u32),
|
||||
pregs);
|
||||
break;
|
||||
|
||||
case PTRACE_SETREGS:
|
||||
ret = copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u32),
|
||||
4 * sizeof(u32),
|
||||
&pregs->psr);
|
||||
if (!ret)
|
||||
ret = copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u32),
|
||||
15 * sizeof(u32),
|
||||
&pregs->u_regs[0]);
|
||||
ret = copy_regset_from_user(child, &ptrace32_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u32),
|
||||
pregs);
|
||||
break;
|
||||
|
||||
case PTRACE_GETFPREGS:
|
||||
ret = copy_regset_to_user(child, view, REGSET_FP,
|
||||
0 * sizeof(u32),
|
||||
32 * sizeof(u32),
|
||||
&fps->regs[0]);
|
||||
if (!ret)
|
||||
ret = copy_regset_to_user(child, view, REGSET_FP,
|
||||
33 * sizeof(u32),
|
||||
1 * sizeof(u32),
|
||||
&fps->fsr);
|
||||
if (!ret) {
|
||||
if (__put_user(0, &fps->flags) ||
|
||||
__put_user(0, &fps->extra) ||
|
||||
__put_user(0, &fps->fpqd) ||
|
||||
clear_user(&fps->fpq[0], 32 * sizeof(unsigned int)))
|
||||
ret = -EFAULT;
|
||||
}
|
||||
ret = copy_regset_to_user(child, &ptrace32_view,
|
||||
REGSET_FP, 0,
|
||||
68 * sizeof(u32),
|
||||
fps);
|
||||
break;
|
||||
|
||||
case PTRACE_SETFPREGS:
|
||||
ret = copy_regset_from_user(child, view, REGSET_FP,
|
||||
0 * sizeof(u32),
|
||||
32 * sizeof(u32),
|
||||
&fps->regs[0]);
|
||||
if (!ret)
|
||||
ret = copy_regset_from_user(child, view, REGSET_FP,
|
||||
33 * sizeof(u32),
|
||||
1 * sizeof(u32),
|
||||
&fps->fsr);
|
||||
ret = copy_regset_from_user(child, &ptrace32_view,
|
||||
REGSET_FP, 0,
|
||||
33 * sizeof(u32),
|
||||
fps);
|
||||
break;
|
||||
|
||||
case PTRACE_READTEXT:
|
||||
@@ -1026,31 +1029,17 @@ long arch_ptrace(struct task_struct *child, long request,
|
||||
break;
|
||||
|
||||
case PTRACE_GETREGS64:
|
||||
ret = copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u64),
|
||||
15 * sizeof(u64),
|
||||
&pregs->u_regs[0]);
|
||||
if (!ret) {
|
||||
/* XXX doesn't handle 'y' register correctly XXX */
|
||||
ret = copy_regset_to_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u64),
|
||||
4 * sizeof(u64),
|
||||
&pregs->tstate);
|
||||
}
|
||||
ret = copy_regset_to_user(child, &ptrace64_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u64),
|
||||
pregs);
|
||||
break;
|
||||
|
||||
case PTRACE_SETREGS64:
|
||||
ret = copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
1 * sizeof(u64),
|
||||
15 * sizeof(u64),
|
||||
&pregs->u_regs[0]);
|
||||
if (!ret) {
|
||||
/* XXX doesn't handle 'y' register correctly XXX */
|
||||
ret = copy_regset_from_user(child, view, REGSET_GENERAL,
|
||||
32 * sizeof(u64),
|
||||
4 * sizeof(u64),
|
||||
&pregs->tstate);
|
||||
}
|
||||
ret = copy_regset_from_user(child, &ptrace64_view,
|
||||
REGSET_GENERAL, 0,
|
||||
19 * sizeof(u64),
|
||||
pregs);
|
||||
break;
|
||||
|
||||
case PTRACE_GETFPREGS64:
|
||||
|
Reference in New Issue
Block a user