diff options
Diffstat (limited to 'arch/ia64/kernel/ptrace.c')
-rw-r--r-- | arch/ia64/kernel/ptrace.c | 327 |
1 files changed, 71 insertions, 256 deletions
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c index 331d6768b5d5..ab784ec4319d 100644 --- a/arch/ia64/kernel/ptrace.c +++ b/arch/ia64/kernel/ptrace.c | |||
@@ -698,52 +698,6 @@ thread_matches (struct task_struct *thread, unsigned long addr) | |||
698 | } | 698 | } |
699 | 699 | ||
700 | /* | 700 | /* |
701 | * GDB apparently wants to be able to read the register-backing store | ||
702 | * of any thread when attached to a given process. If we are peeking | ||
703 | * or poking an address that happens to reside in the kernel-backing | ||
704 | * store of another thread, we need to attach to that thread, because | ||
705 | * otherwise we end up accessing stale data. | ||
706 | * | ||
707 | * task_list_lock must be read-locked before calling this routine! | ||
708 | */ | ||
709 | static struct task_struct * | ||
710 | find_thread_for_addr (struct task_struct *child, unsigned long addr) | ||
711 | { | ||
712 | struct task_struct *p; | ||
713 | struct mm_struct *mm; | ||
714 | struct list_head *this, *next; | ||
715 | int mm_users; | ||
716 | |||
717 | if (!(mm = get_task_mm(child))) | ||
718 | return child; | ||
719 | |||
720 | /* -1 because of our get_task_mm(): */ | ||
721 | mm_users = atomic_read(&mm->mm_users) - 1; | ||
722 | if (mm_users <= 1) | ||
723 | goto out; /* not multi-threaded */ | ||
724 | |||
725 | /* | ||
726 | * Traverse the current process' children list. Every task that | ||
727 | * one attaches to becomes a child. And it is only attached children | ||
728 | * of the debugger that are of interest (ptrace_check_attach checks | ||
729 | * for this). | ||
730 | */ | ||
731 | list_for_each_safe(this, next, ¤t->children) { | ||
732 | p = list_entry(this, struct task_struct, sibling); | ||
733 | if (p->tgid != child->tgid) | ||
734 | continue; | ||
735 | if (thread_matches(p, addr)) { | ||
736 | child = p; | ||
737 | goto out; | ||
738 | } | ||
739 | } | ||
740 | |||
741 | out: | ||
742 | mmput(mm); | ||
743 | return child; | ||
744 | } | ||
745 | |||
746 | /* | ||
747 | * Write f32-f127 back to task->thread.fph if it has been modified. | 701 | * Write f32-f127 back to task->thread.fph if it has been modified. |
748 | */ | 702 | */ |
749 | inline void | 703 | inline void |
@@ -826,14 +780,14 @@ convert_to_non_syscall (struct task_struct *child, struct pt_regs *pt, | |||
826 | if ((long)((unsigned long)child + IA64_STK_OFFSET - sp) | 780 | if ((long)((unsigned long)child + IA64_STK_OFFSET - sp) |
827 | < IA64_PT_REGS_SIZE) { | 781 | < IA64_PT_REGS_SIZE) { |
828 | dprintk("ptrace.%s: ran off the top of the kernel " | 782 | dprintk("ptrace.%s: ran off the top of the kernel " |
829 | "stack\n", __FUNCTION__); | 783 | "stack\n", __func__); |
830 | return; | 784 | return; |
831 | } | 785 | } |
832 | if (unw_get_pr (&prev_info, &pr) < 0) { | 786 | if (unw_get_pr (&prev_info, &pr) < 0) { |
833 | unw_get_rp(&prev_info, &ip); | 787 | unw_get_rp(&prev_info, &ip); |
834 | dprintk("ptrace.%s: failed to read " | 788 | dprintk("ptrace.%s: failed to read " |
835 | "predicate register (ip=0x%lx)\n", | 789 | "predicate register (ip=0x%lx)\n", |
836 | __FUNCTION__, ip); | 790 | __func__, ip); |
837 | return; | 791 | return; |
838 | } | 792 | } |
839 | if (unw_is_intr_frame(&info) | 793 | if (unw_is_intr_frame(&info) |
@@ -908,7 +862,7 @@ static int | |||
908 | access_uarea (struct task_struct *child, unsigned long addr, | 862 | access_uarea (struct task_struct *child, unsigned long addr, |
909 | unsigned long *data, int write_access) | 863 | unsigned long *data, int write_access) |
910 | { | 864 | { |
911 | unsigned long *ptr, regnum, urbs_end, rnat_addr, cfm; | 865 | unsigned long *ptr, regnum, urbs_end, cfm; |
912 | struct switch_stack *sw; | 866 | struct switch_stack *sw; |
913 | struct pt_regs *pt; | 867 | struct pt_regs *pt; |
914 | # define pt_reg_addr(pt, reg) ((void *) \ | 868 | # define pt_reg_addr(pt, reg) ((void *) \ |
@@ -1011,14 +965,9 @@ access_uarea (struct task_struct *child, unsigned long addr, | |||
1011 | * the kernel was entered. | 965 | * the kernel was entered. |
1012 | * | 966 | * |
1013 | * Furthermore, when changing the contents of | 967 | * Furthermore, when changing the contents of |
1014 | * PT_AR_BSP (or PT_CFM) we MUST copy any | 968 | * PT_AR_BSP (or PT_CFM) while the task is |
1015 | * users-level stacked registers that are | 969 | * blocked in a system call, convert the state |
1016 | * stored on the kernel stack back to | 970 | * so that the non-system-call exit |
1017 | * user-space because otherwise, we might end | ||
1018 | * up clobbering kernel stacked registers. | ||
1019 | * Also, if this happens while the task is | ||
1020 | * blocked in a system call, which convert the | ||
1021 | * state such that the non-system-call exit | ||
1022 | * path is used. This ensures that the proper | 971 | * path is used. This ensures that the proper |
1023 | * state will be picked up when resuming | 972 | * state will be picked up when resuming |
1024 | * execution. However, it *also* means that | 973 | * execution. However, it *also* means that |
@@ -1035,10 +984,6 @@ access_uarea (struct task_struct *child, unsigned long addr, | |||
1035 | urbs_end = ia64_get_user_rbs_end(child, pt, &cfm); | 984 | urbs_end = ia64_get_user_rbs_end(child, pt, &cfm); |
1036 | if (write_access) { | 985 | if (write_access) { |
1037 | if (*data != urbs_end) { | 986 | if (*data != urbs_end) { |
1038 | if (ia64_sync_user_rbs(child, sw, | ||
1039 | pt->ar_bspstore, | ||
1040 | urbs_end) < 0) | ||
1041 | return -1; | ||
1042 | if (in_syscall(pt)) | 987 | if (in_syscall(pt)) |
1043 | convert_to_non_syscall(child, | 988 | convert_to_non_syscall(child, |
1044 | pt, | 989 | pt, |
@@ -1058,10 +1003,6 @@ access_uarea (struct task_struct *child, unsigned long addr, | |||
1058 | urbs_end = ia64_get_user_rbs_end(child, pt, &cfm); | 1003 | urbs_end = ia64_get_user_rbs_end(child, pt, &cfm); |
1059 | if (write_access) { | 1004 | if (write_access) { |
1060 | if (((cfm ^ *data) & PFM_MASK) != 0) { | 1005 | if (((cfm ^ *data) & PFM_MASK) != 0) { |
1061 | if (ia64_sync_user_rbs(child, sw, | ||
1062 | pt->ar_bspstore, | ||
1063 | urbs_end) < 0) | ||
1064 | return -1; | ||
1065 | if (in_syscall(pt)) | 1006 | if (in_syscall(pt)) |
1066 | convert_to_non_syscall(child, | 1007 | convert_to_non_syscall(child, |
1067 | pt, | 1008 | pt, |
@@ -1093,16 +1034,8 @@ access_uarea (struct task_struct *child, unsigned long addr, | |||
1093 | return 0; | 1034 | return 0; |
1094 | 1035 | ||
1095 | case PT_AR_RNAT: | 1036 | case PT_AR_RNAT: |
1096 | urbs_end = ia64_get_user_rbs_end(child, pt, NULL); | 1037 | ptr = pt_reg_addr(pt, ar_rnat); |
1097 | rnat_addr = (long) ia64_rse_rnat_addr((long *) | 1038 | break; |
1098 | urbs_end); | ||
1099 | if (write_access) | ||
1100 | return ia64_poke(child, sw, urbs_end, | ||
1101 | rnat_addr, *data); | ||
1102 | else | ||
1103 | return ia64_peek(child, sw, urbs_end, | ||
1104 | rnat_addr, data); | ||
1105 | |||
1106 | case PT_R1: | 1039 | case PT_R1: |
1107 | ptr = pt_reg_addr(pt, r1); | 1040 | ptr = pt_reg_addr(pt, r1); |
1108 | break; | 1041 | break; |
@@ -1521,215 +1454,97 @@ ptrace_setregs (struct task_struct *child, struct pt_all_user_regs __user *ppr) | |||
1521 | return ret; | 1454 | return ret; |
1522 | } | 1455 | } |
1523 | 1456 | ||
1524 | /* | ||
1525 | * Called by kernel/ptrace.c when detaching.. | ||
1526 | * | ||
1527 | * Make sure the single step bit is not set. | ||
1528 | */ | ||
1529 | void | 1457 | void |
1530 | ptrace_disable (struct task_struct *child) | 1458 | user_enable_single_step (struct task_struct *child) |
1531 | { | 1459 | { |
1532 | struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child)); | 1460 | struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child)); |
1533 | 1461 | ||
1534 | /* make sure the single step/taken-branch trap bits are not set: */ | 1462 | set_tsk_thread_flag(child, TIF_SINGLESTEP); |
1535 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | 1463 | child_psr->ss = 1; |
1536 | child_psr->ss = 0; | ||
1537 | child_psr->tb = 0; | ||
1538 | } | 1464 | } |
1539 | 1465 | ||
1540 | asmlinkage long | 1466 | void |
1541 | sys_ptrace (long request, pid_t pid, unsigned long addr, unsigned long data) | 1467 | user_enable_block_step (struct task_struct *child) |
1542 | { | 1468 | { |
1543 | struct pt_regs *pt; | 1469 | struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child)); |
1544 | unsigned long urbs_end, peek_or_poke; | ||
1545 | struct task_struct *child; | ||
1546 | struct switch_stack *sw; | ||
1547 | long ret; | ||
1548 | struct unw_frame_info info; | ||
1549 | 1470 | ||
1550 | lock_kernel(); | 1471 | set_tsk_thread_flag(child, TIF_SINGLESTEP); |
1551 | ret = -EPERM; | 1472 | child_psr->tb = 1; |
1552 | if (request == PTRACE_TRACEME) { | 1473 | } |
1553 | ret = ptrace_traceme(); | ||
1554 | goto out; | ||
1555 | } | ||
1556 | 1474 | ||
1557 | peek_or_poke = (request == PTRACE_PEEKTEXT | 1475 | void |
1558 | || request == PTRACE_PEEKDATA | 1476 | user_disable_single_step (struct task_struct *child) |
1559 | || request == PTRACE_POKETEXT | 1477 | { |
1560 | || request == PTRACE_POKEDATA); | 1478 | struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child)); |
1561 | ret = -ESRCH; | ||
1562 | read_lock(&tasklist_lock); | ||
1563 | { | ||
1564 | child = find_task_by_pid(pid); | ||
1565 | if (child) { | ||
1566 | if (peek_or_poke) | ||
1567 | child = find_thread_for_addr(child, addr); | ||
1568 | get_task_struct(child); | ||
1569 | } | ||
1570 | } | ||
1571 | read_unlock(&tasklist_lock); | ||
1572 | if (!child) | ||
1573 | goto out; | ||
1574 | ret = -EPERM; | ||
1575 | if (pid == 1) /* no messing around with init! */ | ||
1576 | goto out_tsk; | ||
1577 | |||
1578 | if (request == PTRACE_ATTACH) { | ||
1579 | ret = ptrace_attach(child); | ||
1580 | if (!ret) | ||
1581 | arch_ptrace_attach(child); | ||
1582 | goto out_tsk; | ||
1583 | } | ||
1584 | 1479 | ||
1585 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | 1480 | /* make sure the single step/taken-branch trap bits are not set: */ |
1586 | if (ret < 0) | 1481 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); |
1587 | goto out_tsk; | 1482 | child_psr->ss = 0; |
1483 | child_psr->tb = 0; | ||
1484 | } | ||
1588 | 1485 | ||
1589 | pt = task_pt_regs(child); | 1486 | /* |
1590 | sw = (struct switch_stack *) (child->thread.ksp + 16); | 1487 | * Called by kernel/ptrace.c when detaching.. |
1488 | * | ||
1489 | * Make sure the single step bit is not set. | ||
1490 | */ | ||
1491 | void | ||
1492 | ptrace_disable (struct task_struct *child) | ||
1493 | { | ||
1494 | user_disable_single_step(child); | ||
1495 | } | ||
1591 | 1496 | ||
1497 | long | ||
1498 | arch_ptrace (struct task_struct *child, long request, long addr, long data) | ||
1499 | { | ||
1592 | switch (request) { | 1500 | switch (request) { |
1593 | case PTRACE_PEEKTEXT: | 1501 | case PTRACE_PEEKTEXT: |
1594 | case PTRACE_PEEKDATA: | 1502 | case PTRACE_PEEKDATA: |
1595 | /* read word at location addr */ | 1503 | /* read word at location addr */ |
1596 | urbs_end = ia64_get_user_rbs_end(child, pt, NULL); | 1504 | if (access_process_vm(child, addr, &data, sizeof(data), 0) |
1597 | ret = ia64_peek(child, sw, urbs_end, addr, &data); | 1505 | != sizeof(data)) |
1598 | if (ret == 0) { | 1506 | return -EIO; |
1599 | ret = data; | 1507 | /* ensure return value is not mistaken for error code */ |
1600 | /* ensure "ret" is not mistaken as an error code: */ | 1508 | force_successful_syscall_return(); |
1601 | force_successful_syscall_return(); | 1509 | return data; |
1602 | } | ||
1603 | goto out_tsk; | ||
1604 | |||
1605 | case PTRACE_POKETEXT: | ||
1606 | case PTRACE_POKEDATA: | ||
1607 | /* write the word at location addr */ | ||
1608 | urbs_end = ia64_get_user_rbs_end(child, pt, NULL); | ||
1609 | ret = ia64_poke(child, sw, urbs_end, addr, data); | ||
1610 | |||
1611 | /* Make sure user RBS has the latest data */ | ||
1612 | unw_init_from_blocked_task(&info, child); | ||
1613 | do_sync_rbs(&info, ia64_sync_user_rbs); | ||
1614 | 1510 | ||
1615 | goto out_tsk; | 1511 | /* PTRACE_POKETEXT and PTRACE_POKEDATA is handled |
1512 | * by the generic ptrace_request(). | ||
1513 | */ | ||
1616 | 1514 | ||
1617 | case PTRACE_PEEKUSR: | 1515 | case PTRACE_PEEKUSR: |
1618 | /* read the word at addr in the USER area */ | 1516 | /* read the word at addr in the USER area */ |
1619 | if (access_uarea(child, addr, &data, 0) < 0) { | 1517 | if (access_uarea(child, addr, &data, 0) < 0) |
1620 | ret = -EIO; | 1518 | return -EIO; |
1621 | goto out_tsk; | 1519 | /* ensure return value is not mistaken for error code */ |
1622 | } | ||
1623 | ret = data; | ||
1624 | /* ensure "ret" is not mistaken as an error code */ | ||
1625 | force_successful_syscall_return(); | 1520 | force_successful_syscall_return(); |
1626 | goto out_tsk; | 1521 | return data; |
1627 | 1522 | ||
1628 | case PTRACE_POKEUSR: | 1523 | case PTRACE_POKEUSR: |
1629 | /* write the word at addr in the USER area */ | 1524 | /* write the word at addr in the USER area */ |
1630 | if (access_uarea(child, addr, &data, 1) < 0) { | 1525 | if (access_uarea(child, addr, &data, 1) < 0) |
1631 | ret = -EIO; | 1526 | return -EIO; |
1632 | goto out_tsk; | 1527 | return 0; |
1633 | } | ||
1634 | ret = 0; | ||
1635 | goto out_tsk; | ||
1636 | 1528 | ||
1637 | case PTRACE_OLD_GETSIGINFO: | 1529 | case PTRACE_OLD_GETSIGINFO: |
1638 | /* for backwards-compatibility */ | 1530 | /* for backwards-compatibility */ |
1639 | ret = ptrace_request(child, PTRACE_GETSIGINFO, addr, data); | 1531 | return ptrace_request(child, PTRACE_GETSIGINFO, addr, data); |
1640 | goto out_tsk; | ||
1641 | 1532 | ||
1642 | case PTRACE_OLD_SETSIGINFO: | 1533 | case PTRACE_OLD_SETSIGINFO: |
1643 | /* for backwards-compatibility */ | 1534 | /* for backwards-compatibility */ |
1644 | ret = ptrace_request(child, PTRACE_SETSIGINFO, addr, data); | 1535 | return ptrace_request(child, PTRACE_SETSIGINFO, addr, data); |
1645 | goto out_tsk; | ||
1646 | |||
1647 | case PTRACE_SYSCALL: | ||
1648 | /* continue and stop at next (return from) syscall */ | ||
1649 | case PTRACE_CONT: | ||
1650 | /* restart after signal. */ | ||
1651 | ret = -EIO; | ||
1652 | if (!valid_signal(data)) | ||
1653 | goto out_tsk; | ||
1654 | if (request == PTRACE_SYSCALL) | ||
1655 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
1656 | else | ||
1657 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
1658 | child->exit_code = data; | ||
1659 | 1536 | ||
1660 | /* | 1537 | case PTRACE_GETREGS: |
1661 | * Make sure the single step/taken-branch trap bits | 1538 | return ptrace_getregs(child, |
1662 | * are not set: | 1539 | (struct pt_all_user_regs __user *) data); |
1663 | */ | ||
1664 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
1665 | ia64_psr(pt)->ss = 0; | ||
1666 | ia64_psr(pt)->tb = 0; | ||
1667 | 1540 | ||
1668 | wake_up_process(child); | 1541 | case PTRACE_SETREGS: |
1669 | ret = 0; | 1542 | return ptrace_setregs(child, |
1670 | goto out_tsk; | 1543 | (struct pt_all_user_regs __user *) data); |
1671 | 1544 | ||
1672 | case PTRACE_KILL: | 1545 | default: |
1673 | /* | 1546 | return ptrace_request(child, request, addr, data); |
1674 | * Make the child exit. Best I can do is send it a | ||
1675 | * sigkill. Perhaps it should be put in the status | ||
1676 | * that it wants to exit. | ||
1677 | */ | ||
1678 | if (child->exit_state == EXIT_ZOMBIE) | ||
1679 | /* already dead */ | ||
1680 | goto out_tsk; | ||
1681 | child->exit_code = SIGKILL; | ||
1682 | |||
1683 | ptrace_disable(child); | ||
1684 | wake_up_process(child); | ||
1685 | ret = 0; | ||
1686 | goto out_tsk; | ||
1687 | |||
1688 | case PTRACE_SINGLESTEP: | ||
1689 | /* let child execute for one instruction */ | ||
1690 | case PTRACE_SINGLEBLOCK: | ||
1691 | ret = -EIO; | ||
1692 | if (!valid_signal(data)) | ||
1693 | goto out_tsk; | ||
1694 | |||
1695 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
1696 | set_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
1697 | if (request == PTRACE_SINGLESTEP) { | ||
1698 | ia64_psr(pt)->ss = 1; | ||
1699 | } else { | ||
1700 | ia64_psr(pt)->tb = 1; | ||
1701 | } | ||
1702 | child->exit_code = data; | ||
1703 | |||
1704 | /* give it a chance to run. */ | ||
1705 | wake_up_process(child); | ||
1706 | ret = 0; | ||
1707 | goto out_tsk; | ||
1708 | |||
1709 | case PTRACE_DETACH: | ||
1710 | /* detach a process that was attached. */ | ||
1711 | ret = ptrace_detach(child, data); | ||
1712 | goto out_tsk; | ||
1713 | |||
1714 | case PTRACE_GETREGS: | ||
1715 | ret = ptrace_getregs(child, | ||
1716 | (struct pt_all_user_regs __user *) data); | ||
1717 | goto out_tsk; | ||
1718 | |||
1719 | case PTRACE_SETREGS: | ||
1720 | ret = ptrace_setregs(child, | ||
1721 | (struct pt_all_user_regs __user *) data); | ||
1722 | goto out_tsk; | ||
1723 | |||
1724 | default: | ||
1725 | ret = ptrace_request(child, request, addr, data); | ||
1726 | goto out_tsk; | ||
1727 | } | 1547 | } |
1728 | out_tsk: | ||
1729 | put_task_struct(child); | ||
1730 | out: | ||
1731 | unlock_kernel(); | ||
1732 | return ret; | ||
1733 | } | 1548 | } |
1734 | 1549 | ||
1735 | 1550 | ||