Skip to content

Commit 9224652

Browse files
committed
Pull utrace into release branch
2 parents 4d4230c + 680973e commit 9224652

11 files changed

Lines changed: 285 additions & 133 deletions

File tree

‎arch/ia64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config IA64
2121
select HAVE_KRETPROBES
2222
select HAVE_DMA_ATTRS
2323
select HAVE_KVM
24+
select HAVE_ARCH_TRACEHOOK
2425
default y
2526
help
2627
The Itanium Processor Family is Intel's 64-bit successor to

‎arch/ia64/ia32/ia32_entry.S‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ GLOBAL_ENTRY(ia32_trace_syscall)
108108
;;
109109
st8 [r2]=r3 // initialize return code to -ENOSYS
110110
br.call.sptk.few rp=syscall_trace_enter // give parent a chance to catch syscall args
111+
cmp.lt p6,p0=r8,r0 // check tracehook
112+
adds r2=IA64_PT_REGS_R8_OFFSET+16,sp // r2 = &pt_regs.r8
113+
;;
114+
(p6) st8.spill [r2]=r8 // store return value in slot for r8
115+
(p6) br.spnt.few .ret4
111116
.ret2: // Need to reload arguments (they may be changed by the tracing process)
112117
adds r2=IA64_PT_REGS_R1_OFFSET+16,sp // r2 = &pt_regs.r1
113118
adds r3=IA64_PT_REGS_R13_OFFSET+16,sp // r3 = &pt_regs.r13
@@ -199,7 +204,7 @@ ia32_syscall_table:
199204
data8 sys_setuid /* 16-bit version */
200205
data8 sys_getuid /* 16-bit version */
201206
data8 compat_sys_stime /* 25 */
202-
data8 sys32_ptrace
207+
data8 compat_sys_ptrace
203208
data8 sys32_alarm
204209
data8 sys_ni_syscall
205210
data8 sys_pause

‎arch/ia64/ia32/sys_ia32.c‎

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,25 +1194,6 @@ sys32_waitpid (int pid, unsigned int *stat_addr, int options)
11941194
return compat_sys_wait4(pid, stat_addr, options, NULL);
11951195
}
11961196

1197-
static unsigned int
1198-
ia32_peek (struct task_struct *child, unsigned long addr, unsigned int *val)
1199-
{
1200-
size_t copied;
1201-
unsigned int ret;
1202-
1203-
copied = access_process_vm(child, addr, val, sizeof(*val), 0);
1204-
return (copied != sizeof(ret)) ? -EIO : 0;
1205-
}
1206-
1207-
static unsigned int
1208-
ia32_poke (struct task_struct *child, unsigned long addr, unsigned int val)
1209-
{
1210-
1211-
if (access_process_vm(child, addr, &val, sizeof(val), 1) != sizeof(val))
1212-
return -EIO;
1213-
return 0;
1214-
}
1215-
12161197
/*
12171198
* The order in which registers are stored in the ptrace regs structure
12181199
*/
@@ -1510,49 +1491,15 @@ restore_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct __u
15101491
return 0;
15111492
}
15121493

1513-
asmlinkage long
1514-
sys32_ptrace (int request, pid_t pid, unsigned int addr, unsigned int data)
1494+
long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1495+
compat_ulong_t caddr, compat_ulong_t cdata)
15151496
{
1516-
struct task_struct *child;
1517-
unsigned int value, tmp;
1497+
unsigned long addr = caddr;
1498+
unsigned long data = cdata;
1499+
unsigned int tmp;
15181500
long i, ret;
15191501

1520-
lock_kernel();
1521-
if (request == PTRACE_TRACEME) {
1522-
ret = ptrace_traceme();
1523-
goto out;
1524-
}
1525-
1526-
child = ptrace_get_task_struct(pid);
1527-
if (IS_ERR(child)) {
1528-
ret = PTR_ERR(child);
1529-
goto out;
1530-
}
1531-
1532-
if (request == PTRACE_ATTACH) {
1533-
ret = sys_ptrace(request, pid, addr, data);
1534-
goto out_tsk;
1535-
}
1536-
1537-
ret = ptrace_check_attach(child, request == PTRACE_KILL);
1538-
if (ret < 0)
1539-
goto out_tsk;
1540-
15411502
switch (request) {
1542-
case PTRACE_PEEKTEXT:
1543-
case PTRACE_PEEKDATA: /* read word at location addr */
1544-
ret = ia32_peek(child, addr, &value);
1545-
if (ret == 0)
1546-
ret = put_user(value, (unsigned int __user *) compat_ptr(data));
1547-
else
1548-
ret = -EIO;
1549-
goto out_tsk;
1550-
1551-
case PTRACE_POKETEXT:
1552-
case PTRACE_POKEDATA: /* write the word at location addr */
1553-
ret = ia32_poke(child, addr, data);
1554-
goto out_tsk;
1555-
15561503
case PTRACE_PEEKUSR: /* read word at addr in USER area */
15571504
ret = -EIO;
15581505
if ((addr & 3) || addr > 17*sizeof(int))
@@ -1617,27 +1564,9 @@ sys32_ptrace (int request, pid_t pid, unsigned int addr, unsigned int data)
16171564
compat_ptr(data));
16181565
break;
16191566

1620-
case PTRACE_GETEVENTMSG:
1621-
ret = put_user(child->ptrace_message, (unsigned int __user *) compat_ptr(data));
1622-
break;
1623-
1624-
case PTRACE_SYSCALL: /* continue, stop after next syscall */
1625-
case PTRACE_CONT: /* restart after signal. */
1626-
case PTRACE_KILL:
1627-
case PTRACE_SINGLESTEP: /* execute chile for one instruction */
1628-
case PTRACE_DETACH: /* detach a process */
1629-
ret = sys_ptrace(request, pid, addr, data);
1630-
break;
1631-
16321567
default:
1633-
ret = ptrace_request(child, request, addr, data);
1634-
break;
1635-
1568+
return compat_ptrace_request(child, request, caddr, cdata);
16361569
}
1637-
out_tsk:
1638-
put_task_struct(child);
1639-
out:
1640-
unlock_kernel();
16411570
return ret;
16421571
}
16431572

‎arch/ia64/include/asm/ptrace.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ struct switch_stack {
240240
*/
241241
# define instruction_pointer(regs) ((regs)->cr_iip + ia64_psr(regs)->ri)
242242

243+
static inline unsigned long user_stack_pointer(struct pt_regs *regs)
244+
{
245+
/* FIXME: should this be bspstore + nr_dirty regs? */
246+
return regs->ar_bspstore;
247+
}
248+
243249
#define regs_return_value(regs) ((regs)->r8)
244250

245251
/* Conserve space in histogram by encoding slot bits in address
@@ -319,6 +325,8 @@ struct switch_stack {
319325
#define arch_has_block_step() (1)
320326
extern void user_enable_block_step(struct task_struct *);
321327

328+
#define __ARCH_WANT_COMPAT_SYS_PTRACE
329+
322330
#endif /* !__KERNEL__ */
323331

324332
/* pt_all_user_regs is used for PTRACE_GETREGS PTRACE_SETREGS */

‎arch/ia64/include/asm/syscall.h‎

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Access to user system call parameters and results
3+
*
4+
* Copyright (C) 2008 Intel Corp. Shaohua Li <shaohua.li@intel.com>
5+
*
6+
* This copyrighted material is made available to anyone wishing to use,
7+
* modify, copy, or redistribute it subject to the terms and conditions
8+
* of the GNU General Public License v.2.
9+
*
10+
* See asm-generic/syscall.h for descriptions of what we must do here.
11+
*/
12+
13+
#ifndef _ASM_SYSCALL_H
14+
#define _ASM_SYSCALL_H 1
15+
16+
#include <linux/sched.h>
17+
#include <linux/err.h>
18+
19+
static inline long syscall_get_nr(struct task_struct *task,
20+
struct pt_regs *regs)
21+
{
22+
if ((long)regs->cr_ifs < 0) /* Not a syscall */
23+
return -1;
24+
25+
#ifdef CONFIG_IA32_SUPPORT
26+
if (IS_IA32_PROCESS(regs))
27+
return regs->r1;
28+
#endif
29+
30+
return regs->r15;
31+
}
32+
33+
static inline void syscall_rollback(struct task_struct *task,
34+
struct pt_regs *regs)
35+
{
36+
#ifdef CONFIG_IA32_SUPPORT
37+
if (IS_IA32_PROCESS(regs))
38+
regs->r8 = regs->r1;
39+
#endif
40+
41+
/* do nothing */
42+
}
43+
44+
static inline long syscall_get_error(struct task_struct *task,
45+
struct pt_regs *regs)
46+
{
47+
#ifdef CONFIG_IA32_SUPPORT
48+
if (IS_IA32_PROCESS(regs))
49+
return regs->r8;
50+
#endif
51+
52+
return regs->r10 == -1 ? regs->r8:0;
53+
}
54+
55+
static inline long syscall_get_return_value(struct task_struct *task,
56+
struct pt_regs *regs)
57+
{
58+
return regs->r8;
59+
}
60+
61+
static inline void syscall_set_return_value(struct task_struct *task,
62+
struct pt_regs *regs,
63+
int error, long val)
64+
{
65+
#ifdef CONFIG_IA32_SUPPORT
66+
if (IS_IA32_PROCESS(regs)) {
67+
regs->r8 = (long) error ? error : val;
68+
return;
69+
}
70+
#endif
71+
72+
if (error) {
73+
/* error < 0, but ia64 uses > 0 return value */
74+
regs->r8 = -error;
75+
regs->r10 = -1;
76+
} else {
77+
regs->r8 = val;
78+
regs->r10 = 0;
79+
}
80+
}
81+
82+
extern void ia64_syscall_get_set_arguments(struct task_struct *task,
83+
struct pt_regs *regs, unsigned int i, unsigned int n,
84+
unsigned long *args, int rw);
85+
static inline void syscall_get_arguments(struct task_struct *task,
86+
struct pt_regs *regs,
87+
unsigned int i, unsigned int n,
88+
unsigned long *args)
89+
{
90+
BUG_ON(i + n > 6);
91+
92+
#ifdef CONFIG_IA32_SUPPORT
93+
if (IS_IA32_PROCESS(regs)) {
94+
switch (i + n) {
95+
case 6:
96+
if (!n--) break;
97+
*args++ = regs->r13;
98+
case 5:
99+
if (!n--) break;
100+
*args++ = regs->r15;
101+
case 4:
102+
if (!n--) break;
103+
*args++ = regs->r14;
104+
case 3:
105+
if (!n--) break;
106+
*args++ = regs->r10;
107+
case 2:
108+
if (!n--) break;
109+
*args++ = regs->r9;
110+
case 1:
111+
if (!n--) break;
112+
*args++ = regs->r11;
113+
case 0:
114+
if (!n--) break;
115+
default:
116+
BUG();
117+
break;
118+
}
119+
120+
return;
121+
}
122+
#endif
123+
ia64_syscall_get_set_arguments(task, regs, i, n, args, 0);
124+
}
125+
126+
static inline void syscall_set_arguments(struct task_struct *task,
127+
struct pt_regs *regs,
128+
unsigned int i, unsigned int n,
129+
unsigned long *args)
130+
{
131+
BUG_ON(i + n > 6);
132+
133+
#ifdef CONFIG_IA32_SUPPORT
134+
if (IS_IA32_PROCESS(regs)) {
135+
switch (i + n) {
136+
case 6:
137+
if (!n--) break;
138+
regs->r13 = *args++;
139+
case 5:
140+
if (!n--) break;
141+
regs->r15 = *args++;
142+
case 4:
143+
if (!n--) break;
144+
regs->r14 = *args++;
145+
case 3:
146+
if (!n--) break;
147+
regs->r10 = *args++;
148+
case 2:
149+
if (!n--) break;
150+
regs->r9 = *args++;
151+
case 1:
152+
if (!n--) break;
153+
regs->r11 = *args++;
154+
case 0:
155+
if (!n--) break;
156+
}
157+
158+
return;
159+
}
160+
#endif
161+
ia64_syscall_get_set_arguments(task, regs, i, n, args, 1);
162+
}
163+
#endif /* _ASM_SYSCALL_H */

‎arch/ia64/include/asm/thread_info.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ struct thread_info {
8787
#define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL | __GFP_COMP, KERNEL_STACK_SIZE_ORDER))
8888
#define free_task_struct(tsk) free_pages((unsigned long) (tsk), KERNEL_STACK_SIZE_ORDER)
8989

90-
#define tsk_set_notify_resume(tsk) \
91-
set_ti_thread_flag(task_thread_info(tsk), TIF_NOTIFY_RESUME)
92-
extern void tsk_clear_notify_resume(struct task_struct *tsk);
9390
#endif /* !__ASSEMBLY */
9491

9592
/*

‎arch/ia64/kernel/entry.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ GLOBAL_ENTRY(ia64_trace_syscall)
534534
stf.spill [r16]=f10
535535
stf.spill [r17]=f11
536536
br.call.sptk.many rp=syscall_trace_enter // give parent a chance to catch syscall args
537+
cmp.lt p6,p0=r8,r0 // check tracehook
538+
adds r2=PT(R8)+16,sp // r2 = &pt_regs.r8
539+
adds r3=PT(R10)+16,sp // r3 = &pt_regs.r10
540+
mov r10=0
541+
(p6) br.cond.sptk strace_error // syscall failed ->
537542
adds r16=PT(F6)+16,sp
538543
adds r17=PT(F7)+16,sp
539544
;;

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/capability.h>
4141
#include <linux/rcupdate.h>
4242
#include <linux/completion.h>
43+
#include <linux/tracehook.h>
4344

4445
#include <asm/errno.h>
4546
#include <asm/intrinsics.h>
@@ -3684,7 +3685,7 @@ pfm_restart(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs)
36843685

36853686
PFM_SET_WORK_PENDING(task, 1);
36863687

3687-
tsk_set_notify_resume(task);
3688+
set_notify_resume(task);
36883689

36893690
/*
36903691
* XXX: send reschedule if task runs on another CPU
@@ -5044,8 +5045,6 @@ pfm_handle_work(void)
50445045

50455046
PFM_SET_WORK_PENDING(current, 0);
50465047

5047-
tsk_clear_notify_resume(current);
5048-
50495048
regs = task_pt_regs(current);
50505049

50515050
/*
@@ -5414,7 +5413,7 @@ pfm_overflow_handler(struct task_struct *task, pfm_context_t *ctx, u64 pmc0, str
54145413
* when coming from ctxsw, current still points to the
54155414
* previous task, therefore we must work with task and not current.
54165415
*/
5417-
tsk_set_notify_resume(task);
5416+
set_notify_resume(task);
54185417
}
54195418
/*
54205419
* defer until state is changed (shorten spin window). the context is locked

0 commit comments

Comments
 (0)