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 /arch/x86/kernel/ptrace_32.c | |
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>
Diffstat (limited to 'arch/x86/kernel/ptrace_32.c')
-rw-r--r-- | arch/x86/kernel/ptrace_32.c | 125 |
1 files changed, 0 insertions, 125 deletions
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 | * |