diff options
author | Roland McGrath <roland@redhat.com> | 2008-01-30 07:30:50 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:30:50 -0500 |
commit | 7122ec8158b0f88befd94f4da8feae2c8d08d1b4 (patch) | |
tree | 17aa91add10e04cf27e93ba2b673fcb651ed39ba | |
parent | 5f76cb1f6c42e7575256595f85b8b97d84ec669e (diff) |
x86: single_step: share code
This removes the single-step code from ptrace_32.c and uses the step.c code
shared with the 64-bit kernel. The two versions of the code were nearly
identical already, so the shared code has only a couple of simple #ifdef's.
Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | arch/x86/kernel/Makefile_32 | 1 | ||||
-rw-r--r-- | arch/x86/kernel/ptrace_32.c | 125 | ||||
-rw-r--r-- | arch/x86/kernel/step.c | 14 |
3 files changed, 15 insertions, 125 deletions
diff --git a/arch/x86/kernel/Makefile_32 b/arch/x86/kernel/Makefile_32 index 9a6577a746ba..20e23c4c18b6 100644 --- a/arch/x86/kernel/Makefile_32 +++ b/arch/x86/kernel/Makefile_32 | |||
@@ -11,6 +11,7 @@ obj-y := process_32.o signal_32.o entry_32.o traps_32.o irq_32.o \ | |||
11 | quirks.o i8237.o topology.o alternative.o i8253.o tsc_32.o io_delay.o rtc.o | 11 | quirks.o i8237.o topology.o alternative.o i8253.o tsc_32.o io_delay.o rtc.o |
12 | 12 | ||
13 | obj-y += tls.o | 13 | obj-y += tls.o |
14 | obj-y += step.o | ||
14 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 15 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
15 | obj-y += cpu/ | 16 | obj-y += cpu/ |
16 | obj-y += acpi/ | 17 | obj-y += acpi/ |
diff --git a/arch/x86/kernel/ptrace_32.c b/arch/x86/kernel/ptrace_32.c index 1402a54ef61f..b73960885c3f 100644 --- a/arch/x86/kernel/ptrace_32.c +++ b/arch/x86/kernel/ptrace_32.c | |||
@@ -137,131 +137,6 @@ static unsigned long getreg(struct task_struct *child, | |||
137 | return retval; | 137 | return retval; |
138 | } | 138 | } |
139 | 139 | ||
140 | #define LDT_SEGMENT 4 | ||
141 | |||
142 | static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_regs *regs) | ||
143 | { | ||
144 | unsigned long addr, seg; | ||
145 | |||
146 | addr = regs->eip; | ||
147 | seg = regs->xcs & 0xffff; | ||
148 | if (regs->eflags & VM_MASK) { | ||
149 | addr = (addr & 0xffff) + (seg << 4); | ||
150 | return addr; | ||
151 | } | ||
152 | |||
153 | /* | ||
154 | * We'll assume that the code segments in the GDT | ||
155 | * are all zero-based. That is largely true: the | ||
156 | * TLS segments are used for data, and the PNPBIOS | ||
157 | * and APM bios ones we just ignore here. | ||
158 | */ | ||
159 | if (seg & LDT_SEGMENT) { | ||
160 | u32 *desc; | ||
161 | unsigned long base; | ||
162 | |||
163 | seg &= ~7UL; | ||
164 | |||
165 | mutex_lock(&child->mm->context.lock); | ||
166 | if (unlikely((seg >> 3) >= child->mm->context.size)) | ||
167 | addr = -1L; /* bogus selector, access would fault */ | ||
168 | else { | ||
169 | desc = child->mm->context.ldt + seg; | ||
170 | base = ((desc[0] >> 16) | | ||
171 | ((desc[1] & 0xff) << 16) | | ||
172 | (desc[1] & 0xff000000)); | ||
173 | |||
174 | /* 16-bit code segment? */ | ||
175 | if (!((desc[1] >> 22) & 1)) | ||
176 | addr &= 0xffff; | ||
177 | addr += base; | ||
178 | } | ||
179 | mutex_unlock(&child->mm->context.lock); | ||
180 | } | ||
181 | return addr; | ||
182 | } | ||
183 | |||
184 | static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs) | ||
185 | { | ||
186 | int i, copied; | ||
187 | unsigned char opcode[15]; | ||
188 | unsigned long addr = convert_eip_to_linear(child, regs); | ||
189 | |||
190 | copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0); | ||
191 | for (i = 0; i < copied; i++) { | ||
192 | switch (opcode[i]) { | ||
193 | /* popf and iret */ | ||
194 | case 0x9d: case 0xcf: | ||
195 | return 1; | ||
196 | /* opcode and address size prefixes */ | ||
197 | case 0x66: case 0x67: | ||
198 | continue; | ||
199 | /* irrelevant prefixes (segment overrides and repeats) */ | ||
200 | case 0x26: case 0x2e: | ||
201 | case 0x36: case 0x3e: | ||
202 | case 0x64: case 0x65: | ||
203 | case 0xf0: case 0xf2: case 0xf3: | ||
204 | continue; | ||
205 | |||
206 | /* | ||
207 | * pushf: NOTE! We should probably not let | ||
208 | * the user see the TF bit being set. But | ||
209 | * it's more pain than it's worth to avoid | ||
210 | * it, and a debugger could emulate this | ||
211 | * all in user space if it _really_ cares. | ||
212 | */ | ||
213 | case 0x9c: | ||
214 | default: | ||
215 | return 0; | ||
216 | } | ||
217 | } | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | void user_enable_single_step(struct task_struct *child) | ||
222 | { | ||
223 | struct pt_regs *regs = get_child_regs(child); | ||
224 | |||
225 | /* | ||
226 | * Always set TIF_SINGLESTEP - this guarantees that | ||
227 | * we single-step system calls etc.. This will also | ||
228 | * cause us to set TF when returning to user mode. | ||
229 | */ | ||
230 | set_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
231 | |||
232 | /* | ||
233 | * If TF was already set, don't do anything else | ||
234 | */ | ||
235 | if (regs->eflags & X86_EFLAGS_TF) | ||
236 | return; | ||
237 | |||
238 | /* Set TF on the kernel stack.. */ | ||
239 | regs->eflags |= X86_EFLAGS_TF; | ||
240 | |||
241 | /* | ||
242 | * ..but if TF is changed by the instruction we will trace, | ||
243 | * don't mark it as being "us" that set it, so that we | ||
244 | * won't clear it by hand later. | ||
245 | */ | ||
246 | if (is_setting_trap_flag(child, regs)) | ||
247 | return; | ||
248 | |||
249 | child->ptrace |= PT_DTRACE; | ||
250 | } | ||
251 | |||
252 | void user_disable_single_step(struct task_struct *child) | ||
253 | { | ||
254 | /* Always clear TIF_SINGLESTEP... */ | ||
255 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
256 | |||
257 | /* But touch TF only if it was set by us.. */ | ||
258 | if (child->ptrace & PT_DTRACE) { | ||
259 | struct pt_regs *regs = get_child_regs(child); | ||
260 | regs->eflags &= ~X86_EFLAGS_TF; | ||
261 | child->ptrace &= ~PT_DTRACE; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | /* | 140 | /* |
266 | * Called by kernel/ptrace.c when detaching.. | 141 | * Called by kernel/ptrace.c when detaching.. |
267 | * | 142 | * |
diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c index 6a93b93f91f1..6732272e3479 100644 --- a/arch/x86/kernel/step.c +++ b/arch/x86/kernel/step.c | |||
@@ -5,12 +5,24 @@ | |||
5 | #include <linux/mm.h> | 5 | #include <linux/mm.h> |
6 | #include <linux/ptrace.h> | 6 | #include <linux/ptrace.h> |
7 | 7 | ||
8 | #ifdef CONFIG_X86_32 | ||
9 | static | ||
10 | #endif | ||
8 | unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs) | 11 | unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs) |
9 | { | 12 | { |
10 | unsigned long addr, seg; | 13 | unsigned long addr, seg; |
11 | 14 | ||
15 | #ifdef CONFIG_X86_64 | ||
12 | addr = regs->rip; | 16 | addr = regs->rip; |
13 | seg = regs->cs & 0xffff; | 17 | seg = regs->cs & 0xffff; |
18 | #else | ||
19 | addr = regs->eip; | ||
20 | seg = regs->xcs & 0xffff; | ||
21 | if (regs->eflags & X86_EFLAGS_VM) { | ||
22 | addr = (addr & 0xffff) + (seg << 4); | ||
23 | return addr; | ||
24 | } | ||
25 | #endif | ||
14 | 26 | ||
15 | /* | 27 | /* |
16 | * We'll assume that the code segments in the GDT | 28 | * We'll assume that the code segments in the GDT |
@@ -69,12 +81,14 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs) | |||
69 | case 0xf0: case 0xf2: case 0xf3: | 81 | case 0xf0: case 0xf2: case 0xf3: |
70 | continue; | 82 | continue; |
71 | 83 | ||
84 | #ifdef CONFIG_X86_64 | ||
72 | case 0x40 ... 0x4f: | 85 | case 0x40 ... 0x4f: |
73 | if (regs->cs != __USER_CS) | 86 | if (regs->cs != __USER_CS) |
74 | /* 32-bit mode: register increment */ | 87 | /* 32-bit mode: register increment */ |
75 | return 0; | 88 | return 0; |
76 | /* 64-bit mode: REX prefix */ | 89 | /* 64-bit mode: REX prefix */ |
77 | continue; | 90 | continue; |
91 | #endif | ||
78 | 92 | ||
79 | /* CHECKME: f2, f3 */ | 93 | /* CHECKME: f2, f3 */ |
80 | 94 | ||