12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/errno.h>
16 #include <linux/ptrace.h>
19 #include <linux/audit.h>
20 #include <linux/signal.h>
22 #include <linux/elf.h>
25 #include <asm/pgtable.h>
26 #include <asm/processor.h>
29 #include <asm/uaccess.h>
30 #include <asm/unwind.h>
32 #include <asm/perfmon.h>
46 #define IPSR_MASK (IA64_PSR_UM | IA64_PSR_DB | IA64_PSR_IS \
47 | IA64_PSR_ID | IA64_PSR_DD | IA64_PSR_RI)
49 #define MASK(nbits) ((1UL << (nbits)) - 1)
50 #define PFM_MASK MASK(38)
52 #define PTRACE_DEBUG 0
55 # define dprintk(format...) printk(format)
58 # define dprintk(format...)
66 return (
long) pt->
cr_ifs >= 0;
76 # define GET_BITS(first, last, unat) \
78 unsigned long bit = ia64_unat_pos(&pt->r##first); \
79 unsigned long nbits = (last - first + 1); \
80 unsigned long mask = MASK(nbits) << first; \
83 dist = 64 + bit - first; \
86 ia64_rotr(unat, dist) & mask; \
96 val |=
GET_BITS( 2, 3, scratch_unat);
97 val |=
GET_BITS(12, 13, scratch_unat);
98 val |=
GET_BITS(14, 14, scratch_unat);
99 val |=
GET_BITS(15, 15, scratch_unat);
100 val |=
GET_BITS( 8, 11, scratch_unat);
101 val |=
GET_BITS(16, 31, scratch_unat);
115 # define PUT_BITS(first, last, nat) \
117 unsigned long bit = ia64_unat_pos(&pt->r##first); \
118 unsigned long nbits = (last - first + 1); \
119 unsigned long mask = MASK(nbits) << first; \
122 dist = 64 + bit - first; \
124 dist = bit - first; \
125 ia64_rotl(nat & mask, dist); \
127 unsigned long scratch_unat;
134 scratch_unat =
PUT_BITS( 1, 1, nat);
135 scratch_unat |=
PUT_BITS( 2, 3, nat);
136 scratch_unat |=
PUT_BITS(12, 13, nat);
137 scratch_unat |=
PUT_BITS(14, 14, nat);
138 scratch_unat |=
PUT_BITS(15, 15, nat);
139 scratch_unat |=
PUT_BITS( 8, 11, nat);
140 scratch_unat |=
PUT_BITS(16, 31, nat);
147 #define IA64_MLX_TEMPLATE 0x2
148 #define IA64_MOVL_OPCODE 6
153 unsigned long w0, ri =
ia64_psr(regs)->ri + 1;
158 }
else if (ri == 2) {
176 unsigned long w0, ri =
ia64_psr(regs)->ri - 1;
250 unsigned long *krbs,
unsigned long *urnat_addr,
251 unsigned long *urbs_end)
253 unsigned long rnat0 = 0, rnat1 = 0, urnat = 0, *slot0_kaddr;
254 unsigned long umask = 0,
mask,
m;
255 unsigned long *kbsp, *ubspstore, *rnat0_kaddr, *rnat1_kaddr, shift;
256 long num_regs, nbits;
263 if (urbs_end < urnat_addr)
264 nbits = ia64_rse_num_regs(urnat_addr - 63, urbs_end);
274 num_regs = ia64_rse_num_regs(ubspstore, urnat_addr + 1);
275 slot0_kaddr = ia64_rse_skip_regs(krbs, num_regs);
276 shift = ia64_rse_slot_num(slot0_kaddr);
277 rnat1_kaddr = ia64_rse_rnat_addr(slot0_kaddr);
278 rnat0_kaddr = rnat1_kaddr - 64;
280 if (ubspstore + 63 > urnat_addr) {
282 umask =
MASK(ia64_rse_slot_num(ubspstore)) &
mask;
290 if (rnat0_kaddr >= kbsp)
292 else if (rnat0_kaddr > krbs)
293 rnat0 = *rnat0_kaddr;
294 urnat |= (rnat0 &
m) >> shift;
296 m =
mask >> (63 - shift);
297 if (rnat1_kaddr >= kbsp)
299 else if (rnat1_kaddr > krbs)
300 rnat1 = *rnat1_kaddr;
301 urnat |= (rnat1 &
m) << (63 - shift);
310 unsigned long *krbs,
unsigned long *urnat_addr,
unsigned long urnat,
311 unsigned long *urbs_end)
313 unsigned long rnat0 = 0, rnat1 = 0, *slot0_kaddr, umask = 0,
mask,
m;
314 unsigned long *kbsp, *ubspstore, *rnat0_kaddr, *rnat1_kaddr, shift;
315 long num_regs, nbits;
317 unsigned long cfm, *urbs_kargs;
323 urbs_kargs = urbs_end;
330 urbs_kargs = ia64_rse_skip_regs(urbs_end, -(cfm & 0x7f));
333 if (urbs_kargs >= urnat_addr)
336 if ((urnat_addr - 63) >= urbs_kargs)
338 nbits = ia64_rse_num_regs(urnat_addr - 63, urbs_kargs);
348 num_regs = ia64_rse_num_regs(ubspstore, urnat_addr + 1);
349 slot0_kaddr = ia64_rse_skip_regs(krbs, num_regs);
350 shift = ia64_rse_slot_num(slot0_kaddr);
351 rnat1_kaddr = ia64_rse_rnat_addr(slot0_kaddr);
352 rnat0_kaddr = rnat1_kaddr - 64;
354 if (ubspstore + 63 > urnat_addr) {
356 umask =
MASK(ia64_rse_slot_num(ubspstore)) &
mask;
366 rnat0 = (urnat << shift);
368 if (rnat0_kaddr >= kbsp)
370 else if (rnat0_kaddr > krbs)
371 *rnat0_kaddr = ((*rnat0_kaddr & ~m) | (rnat0 & m));
373 rnat1 = (urnat >> (63 - shift));
374 m =
mask >> (63 - shift);
375 if (rnat1_kaddr >= kbsp)
377 else if (rnat1_kaddr > krbs)
378 *rnat1_kaddr = ((*rnat1_kaddr & ~m) | (rnat1 & m));
382 on_kernel_rbs (
unsigned long addr,
unsigned long bspstore,
383 unsigned long urbs_end)
385 unsigned long *rnat_addr = ia64_rse_rnat_addr((
unsigned long *)
387 return (addr >= bspstore && addr <= (
unsigned long) rnat_addr);
403 unsigned long user_rbs_end,
unsigned long addr,
long *
val)
405 unsigned long *bspstore, *krbs, regnum, *
laddr, *urbs_end, *rnat_addr;
410 urbs_end = (
long *) user_rbs_end;
411 laddr = (
unsigned long *) addr;
413 bspstore = (
unsigned long *) child_regs->
ar_bspstore;
415 if (on_kernel_rbs(addr, (
unsigned long) bspstore,
416 (
unsigned long) urbs_end))
423 rnat_addr = ia64_rse_rnat_addr(laddr);
424 ret = get_rnat(child, child_stack, krbs, rnat_addr, urbs_end);
426 if (laddr == rnat_addr) {
432 if (((1
UL << ia64_rse_slot_num(laddr)) & ret) != 0) {
446 if (laddr < urbs_end) {
451 regnum = ia64_rse_num_regs(bspstore, laddr);
452 *val = *ia64_rse_skip_regs(krbs, regnum);
457 if (copied !=
sizeof(ret))
465 unsigned long user_rbs_end,
unsigned long addr,
long val)
467 unsigned long *bspstore, *krbs, regnum, *
laddr;
468 unsigned long *urbs_end = (
long *) user_rbs_end;
471 laddr = (
unsigned long *) addr;
473 bspstore = (
unsigned long *) child_regs->
ar_bspstore;
475 if (on_kernel_rbs(addr, (
unsigned long) bspstore,
476 (
unsigned long) urbs_end))
483 if (ia64_rse_is_rnat_slot(laddr))
484 put_rnat(child, child_stack, krbs, laddr, val,
487 if (laddr < urbs_end) {
488 regnum = ia64_rse_num_regs(bspstore, laddr);
489 *ia64_rse_skip_regs(krbs, regnum) =
val;
510 unsigned long *krbs, *bspstore, cfm = pt->
cr_ifs;
515 ndirty = ia64_rse_num_regs(krbs, krbs + (pt->
loadrs >> 19));
518 ndirty += (cfm & 0x7f);
524 return (
unsigned long) ia64_rse_skip_regs(bspstore, ndirty);
536 unsigned long user_rbs_start,
unsigned long user_rbs_end)
542 for (addr = user_rbs_start; addr < user_rbs_end; addr += 8) {
543 ret =
ia64_peek(child, sw, user_rbs_end, addr, &val);
555 unsigned long user_rbs_start,
unsigned long user_rbs_end)
561 for (addr = user_rbs_start; addr < user_rbs_end; addr += 8) {
566 ret =
ia64_poke(child, sw, user_rbs_end, addr, val);
579 unsigned long urbs_end;
641 spin_lock_irq(&child->
sighand->siglock);
644 set_notify_resume(child);
649 spin_unlock_irq(&child->
sighand->siglock);
665 spin_lock_irq(&child->
sighand->siglock);
670 spin_unlock_irq(&child->
sighand->siglock);
678 unsigned long thread_rbs_end;
696 if (!on_kernel_rbs(addr, thread_regs->
ar_bspstore, thread_rbs_end))
718 ia64_save_fpu(&task->
thread.fph[0]);
762 unw_get_sp(&
info, &sp);
764 < IA64_PT_REGS_SIZE) {
765 dprintk(
"ptrace.%s: ran off the top of the kernel "
766 "stack\n", __func__);
770 unw_get_rp(&prev_info, &ip);
771 dprintk(
"ptrace.%s: failed to read "
772 "predicate register (ip=0x%lx)\n",
790 unw_set_pr(&prev_info, pr);
812 unsigned long *
data,
int write_access)
814 unsigned long regnum, nat_bits, scratch_unat,
dummy = 0;
820 if (unw_set_ar(info,
UNW_AR_UNAT, scratch_unat) < 0) {
821 dprintk(
"ptrace: failed to set ar.unat\n");
824 for (regnum = 4; regnum <= 7; ++regnum) {
826 unw_set_gr(info, regnum, dummy,
827 (nat_bits >> regnum) & 1);
831 dprintk(
"ptrace: failed to read ar.unat\n");
835 for (regnum = 4; regnum <= 7; ++regnum) {
837 nat_bits |= (nat != 0) << regnum;
845 access_uarea (
struct task_struct *child,
unsigned long addr,
846 unsigned long *data,
int write_access);
870 if (((
unsigned long) ppr & 0x7) != 0) {
871 dprintk(
"ptrace:unaligned register address %p\n", ppr);
875 if (access_uarea(child,
PT_CR_IPSR, &psr, 0) < 0
876 || access_uarea(child,
PT_AR_EC, &ec, 0) < 0
877 || access_uarea(child,
PT_AR_LC, &lc, 0) < 0
878 || access_uarea(child,
PT_AR_RNAT, &rnat, 0) < 0
879 || access_uarea(child,
PT_AR_BSP, &bsp, 0) < 0
880 || access_uarea(child,
PT_CFM, &cfm, 0)
911 for (i = 4; i < 8; i++) {
937 for (i = 1; i < 6; i++) {
950 for (i = 2; i < 6; i++) {
968 for (i = 16; i < 32; i++) {
978 sizeof(ppr->fr[32]) * 96);
988 ret = retval ? -
EIO : 0;
995 unsigned long psr,
rsc, ec,
lc, rnat, bsp,
cfm, nat_bits, val = 0;
1000 long ret, retval = 0;
1003 memset(&fpval, 0,
sizeof(fpval));
1015 if (((
unsigned long) ppr & 0x7) != 0) {
1016 dprintk(
"ptrace:unaligned register address %p\n", ppr);
1047 for (i = 4; i < 8; i++) {
1050 if (unw_set_gr(&info, i, val, 0) < 0)
1074 for (i = 1; i < 6; i++) {
1076 unw_set_br(&info, i, val);
1086 for (i = 2; i < 6; i++) {
1088 if (unw_set_fr(&info, i, fpval) < 0)
1095 sizeof(ppr->fr[6]) * 6);
1100 sizeof(ppr->fr[12]) * 4);
1104 for (i = 16; i < 32; i++) {
1107 if (unw_set_fr(&info, i, fpval) < 0)
1115 sizeof(ppr->fr[32]) * 96);
1125 retval |= access_uarea(child,
PT_CR_IPSR, &psr, 1);
1126 retval |= access_uarea(child,
PT_AR_RSC, &rsc, 1);
1127 retval |= access_uarea(child,
PT_AR_EC, &ec, 1);
1128 retval |= access_uarea(child,
PT_AR_LC, &lc, 1);
1129 retval |= access_uarea(child,
PT_AR_RNAT, &rnat, 1);
1130 retval |= access_uarea(child,
PT_AR_BSP, &bsp, 1);
1131 retval |= access_uarea(child,
PT_CFM, &cfm, 1);
1132 retval |= access_uarea(child,
PT_NAT_BITS, &nat_bits, 1);
1134 ret = retval ? -
EIO : 0;
1180 unsigned long addr,
unsigned long data)
1199 if (access_uarea(child, addr, &data, 0) < 0)
1207 if (access_uarea(child, addr, &data, 1) < 0)
1220 return ptrace_getregs(child,
1224 return ptrace_setregs(child,
1237 long arg4,
long arg5,
long arg6,
long arg7,
1241 if (tracehook_report_syscall_entry(®s))
1258 long arg4,
long arg5,
long arg6,
long arg7,
1263 audit_syscall_exit(®s);
1267 tracehook_report_syscall_exit(®s, step);
1299 unsigned long addr,
unsigned long *data,
int write_access)
1318 unsigned long dummy;
1320 ret =
unw_get_gr(info, addr/8, &dummy, &nat);
1324 return unw_access_gr(info, addr/8, data, &nat, write_access);
1347 unsigned long addr,
unsigned long *data,
int write_access)
1350 unsigned long *ptr =
NULL;
1359 data, write_access);
1375 unsigned long addr,
unsigned long *data,
int write_access)
1378 unsigned long cfm, urbs_end;
1379 unsigned long *ptr =
NULL;
1387 pt->
ar_rsc = *data | (3 << 2);
1418 if (*data != urbs_end) {
1420 convert_to_non_syscall(target,
1471 if (((cfm ^ *data) &
PFM_MASK) != 0) {
1473 convert_to_non_syscall(target,
1477 | (*data & PFM_MASK));
1487 tmp &= ~IA64_PSR_RI;
1495 return access_nat_bits(target, pt, info,
1496 data, write_access);
1512 unsigned long addr,
unsigned long *data,
int write_access)
1515 return access_elf_gpreg(target, info, addr, data, write_access);
1517 return access_elf_breg(target, info, addr, data, write_access);
1519 return access_elf_areg(target, info, addr, data, write_access);
1527 unsigned int i,
index, min_copy;
1546 dst->
ret = user_regset_copyout_zero(&dst->
pos, &dst->
count,
1561 if (access_elf_reg(dst->
target, info, i,
1562 &tmp[index], 0) < 0) {
1566 dst->
ret = user_regset_copyout(&dst->
pos, &dst->
count,
1567 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf, tmp,
1576 dst->
ret = user_regset_copyout(&dst->
pos, &dst->
count,
1590 if (access_elf_reg(dst->
target, info, i,
1591 &tmp[index], 0) < 0) {
1595 dst->
ret = user_regset_copyout(&dst->
pos, &dst->
count,
1596 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf, tmp,
1611 if (access_elf_reg(dst->
target, info, i,
1612 &tmp[index], 0) < 0) {
1616 dst->
ret = user_regset_copyout(&dst->
pos, &dst->
count,
1617 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf, tmp,
1634 dst->
ret = user_regset_copyin_ignore(&dst->
pos, &dst->
count,
1646 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1647 &dst->
u.
set.kbuf, &dst->
u.
set.ubuf, tmp,
1652 if (access_elf_reg(dst->
target, info, i,
1653 &tmp[index], 1) < 0) {
1657 if (dst->
count == 0)
1664 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1675 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1676 &dst->
u.
set.kbuf, &dst->
u.
set.ubuf, tmp,
1681 if (access_elf_reg(dst->
target, info, i,
1682 &tmp[index], 1) < 0) {
1686 if (dst->
count == 0)
1696 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1697 &dst->
u.
set.kbuf, &dst->
u.
set.ubuf, tmp,
1702 if (access_elf_reg(dst->
target, info, i,
1703 &tmp[index], 1) < 0) {
1710 #define ELF_FP_OFFSET(i) (i * sizeof(elf_fpreg_t))
1724 dst->
ret = user_regset_copyout_zero(&dst->
pos, &dst->
count,
1745 dst->
ret = user_regset_copyout(&dst->
pos, &dst->
count,
1746 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf, tmp,
1753 if (dst->
count > 0) {
1756 dst->
ret = user_regset_copyout(
1758 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf,
1759 &dst->
target->thread.fph,
1763 dst->
ret = user_regset_copyout_zero(
1765 &dst->
u.
get.kbuf, &dst->
u.
get.ubuf,
1781 dst->
ret = user_regset_copyin_ignore(&dst->
pos, &dst->
count,
1794 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1795 &dst->
u.
set.kbuf, &dst->
u.
set.ubuf, tmp,
1818 end = (end + 0xF) & ~0xF
UL;
1823 if (unw_set_fr(info, index, tmp[index - 2])) {
1835 dst->
ret = user_regset_copyin(&dst->
pos, &dst->
count,
1838 &dst->
target->thread.fph,
1847 unsigned int pos,
unsigned int count,
1848 const void *kbuf,
const void __user *ubuf)
1852 .u.set = { .kbuf = kbuf, .ubuf = ubuf },
1859 memset(&ufi, 0,
sizeof(ufi));
1861 (*call)(&ufi, &
info);
1870 unsigned int pos,
unsigned int count,
1871 void *kbuf,
void __user *ubuf)
1873 return do_regset_call(
do_gpregs_get, target, regset, pos, count,
1879 unsigned int pos,
unsigned int count,
1880 const void *kbuf,
const void __user *ubuf)
1882 return do_regset_call(
do_gpregs_set, target, regset, pos, count,
1903 set_notify_resume(target);
1904 return do_regset_call(do_gpregs_writeback, target, regset, 0, 0,
1916 unsigned int pos,
unsigned int count,
1917 void *kbuf,
void __user *ubuf)
1919 return do_regset_call(
do_fpregs_get, target, regset, pos, count,
1925 unsigned int pos,
unsigned int count,
1926 const void *kbuf,
const void __user *ubuf)
1928 return do_regset_call(
do_fpregs_set, target, regset, pos, count,
1933 access_uarea(
struct task_struct *child,
unsigned long addr,
1934 unsigned long *data,
int write_access)
1936 unsigned int pos = -1;
1938 unsigned long *
ptr, regnum;
1940 if ((addr & 0x7) != 0) {
1941 dprintk(
"ptrace: unaligned register address 0x%lx\n", addr);
1948 dprintk(
"ptrace: rejecting access to register "
1949 "address 0x%lx\n", addr);
1971 sizeof(
unsigned long), data,
NULL);
1974 sizeof(
unsigned long), data,
NULL);
2063 ret = gpregs_set(child,
NULL, pos,
2064 sizeof(
unsigned long), data,
NULL);
2066 ret = gpregs_get(child,
NULL, pos,
2067 sizeof(
unsigned long), data,
NULL);
2075 regnum = (addr -
PT_IBR) >> 3;
2076 ptr = &child->
thread.ibr[0];
2078 regnum = (addr -
PT_DBR) >> 3;
2079 ptr = &child->
thread.dbr[0];
2083 dprintk(
"ptrace: rejecting access to register "
2084 "address 0x%lx\n", addr);
2087 #ifdef CONFIG_PERFMON
2112 sizeof(child->
thread.dbr));
2114 sizeof(child->
thread.ibr));
2119 if ((regnum & 1) && write_access) {
2121 *ptr = *data & ~(7
UL << 56);
2131 static const struct user_regset native_regsets[] = {
2136 .get = gpregs_get, .set = gpregs_set,
2137 .writeback = gpregs_writeback
2150 .regsets = native_regsets, .
n =
ARRAY_SIZE(native_regsets)
2155 return &user_ia64_view;
2166 static void syscall_get_set_args_cb(
struct unw_frame_info *info,
void *data)
2170 unsigned long *krbs,
cfm, ndirty;
2178 ndirty = ia64_rse_num_regs(krbs, krbs + (pt->
loadrs >> 19));
2182 count =
min_t(
int, args->
n, cfm & 0x7f);
2184 for (i = 0; i <
count; i++) {
2186 *ia64_rse_skip_regs(krbs, ndirty + i + args->
i) =
2189 args->
args[
i] = *ia64_rse_skip_regs(krbs,
2190 ndirty + i + args->
i);
2194 while (i < args->
n) {
2203 unsigned long *args,
int rw)
2217 memset(&ufi, 0,
sizeof(ufi));
2219 syscall_get_set_args_cb(&ufi, &data);