patch-1.3.12 linux/arch/alpha/kernel/ptrace.c
Next file: linux/arch/alpha/kernel/setup.c
Previous file: linux/arch/alpha/kernel/osf_sys.c
Back to the patch index
Back to the overall index
- Lines: 307
- Date:
Mon Jul 24 17:38:25 1995
- Orig file:
v1.3.11/linux/arch/alpha/kernel/ptrace.c
- Orig date:
Tue Jul 18 16:28:56 1995
diff -u --recursive --new-file v1.3.11/linux/arch/alpha/kernel/ptrace.c linux/arch/alpha/kernel/ptrace.c
@@ -531,6 +531,12 @@
int i, nsaved = child->debugreg[4];
child->debugreg[4] = 0;
+
+ if (nsaved > 2) {
+ printk("ptrace_cancel_bpt: bogus nsaved: %d!\n", nsaved);
+ nsaved = 2;
+ }
+
for (i = 0; i < nsaved; ++i) {
write_int(child, child->debugreg[i], child->debugreg[i + 2]);
}
@@ -550,65 +556,65 @@
set_success(®s,0);
if (request == PTRACE_TRACEME) {
/* are we already being traced? */
- if (current->flags & PF_PTRACED) {
- set_failure(®s,-EPERM);
- return -EPERM;
- }
- /* set the ptrace bit in the process flags. */
- current->flags |= PF_PTRACED;
- return 0;
- }
- if (pid == 1) {
- set_failure(®s,-EPERM);
- return -EPERM;
+ if (current->flags & PF_PTRACED) {
+ set_failure(®s,-EPERM);
+ return -EPERM;
+ }
+ /* set the ptrace bit in the process flags. */
+ current->flags |= PF_PTRACED;
+ return 0;
+ }
+ if (pid == 1) { /* you may not mess with init */
+ set_failure(®s,-EPERM);
+ return -EPERM;
}
if (!(child = get_task(pid))) {
- set_failure(®s,-ESRCH);
- return -ESRCH;
+ set_failure(®s,-ESRCH);
+ return -ESRCH;
}
if (request == PTRACE_ATTACH) {
- if (child == current) {
- set_failure(®s,-EPERM);
- return -EPERM;
- }
- if ((!child->dumpable ||
- (current->uid != child->euid) ||
- (current->uid != child->uid) ||
- (current->gid != child->egid) ||
- (current->gid != child->gid)) && !suser()) {
- set_failure(®s,-EPERM);
- return -EPERM;
- }
- /* the same process cannot be attached many times */
- if (child->flags & PF_PTRACED) {
- set_failure(®s,-EPERM);
- return -EPERM;
- }
- child->flags |= PF_PTRACED;
- if (child->p_pptr != current) {
- REMOVE_LINKS(child);
- child->p_pptr = current;
- SET_LINKS(child);
- }
- send_sig(SIGSTOP, child, 1);
- return 0;
+ if (child == current) {
+ set_failure(®s,-EPERM);
+ return -EPERM;
+ }
+ if ((!child->dumpable ||
+ (current->uid != child->euid) ||
+ (current->uid != child->uid) ||
+ (current->gid != child->egid) ||
+ (current->gid != child->gid)) && !suser()) {
+ set_failure(®s,-EPERM);
+ return -EPERM;
+ }
+ /* the same process cannot be attached many times */
+ if (child->flags & PF_PTRACED) {
+ set_failure(®s,-EPERM);
+ return -EPERM;
+ }
+ child->flags |= PF_PTRACED;
+ if (child->p_pptr != current) {
+ REMOVE_LINKS(child);
+ child->p_pptr = current;
+ SET_LINKS(child);
+ }
+ send_sig(SIGSTOP, child, 1);
+ return 0;
}
if (!(child->flags & PF_PTRACED)) {
- DBG(DBG_MEM, ("child not traced\n"));
- set_failure(®s,-ESRCH);
- return -ESRCH;
+ DBG(DBG_MEM, ("child not traced\n"));
+ set_failure(®s,-ESRCH);
+ return -ESRCH;
}
if (child->state != TASK_STOPPED) {
- DBG(DBG_MEM, ("child process not stopped\n"));
- if (request != PTRACE_KILL) {
- set_failure(®s,-ESRCH);
- return -ESRCH;
- }
+ DBG(DBG_MEM, ("child process not stopped\n"));
+ if (request != PTRACE_KILL) {
+ set_failure(®s,-ESRCH);
+ return -ESRCH;
+ }
}
if (child->p_pptr != current) {
- DBG(DBG_MEM, ("child not parent of this process\n"));
- set_failure(®s,-ESRCH);
- return -ESRCH;
+ DBG(DBG_MEM, ("child not parent of this process\n"));
+ set_failure(®s,-ESRCH);
+ return -ESRCH;
}
switch (request) {
@@ -621,12 +627,11 @@
DBG(DBG_MEM, ("doing request at addr 0x%lx\n",addr));
res = read_long(child, addr, &tmp);
if (res < 0) {
- set_failure(®s,res);
- return res;
- }
- else {
- set_success(®s,tmp);
- return 0;
+ set_failure(®s,res);
+ return res;
+ } else {
+ set_success(®s,tmp);
+ return 0;
}
}
@@ -636,21 +641,20 @@
unsigned long tmp;
tmp = 0; /* Default return condition */
- if(addr==30) {
- /* stack pointer */
- tmp=child->tss.usp;
- }
- else {
+ if (addr == 30) {
+ /* stack pointer */
+ tmp=child->tss.usp;
+ } else {
#ifdef DEBUG
- int reg=addr;
+ int reg = addr;
#endif
- addr = offset_of_register(addr);
- if (addr < 0) {
- set_failure(®s, -EIO);
- return -EIO;
- }
- tmp = get_stack_long(child, addr);
- DBG(DBG_MEM, ("%d = reg 0x%lx=tmp\n",reg,tmp));
+ addr = offset_of_register(addr);
+ if (addr < 0) {
+ set_failure(®s, -EIO);
+ return -EIO;
+ }
+ tmp = get_stack_long(child, addr);
+ DBG(DBG_MEM, ("%d = reg 0x%lx=tmp\n",reg,tmp));
}
set_success(®s,tmp);
return 0;
@@ -659,34 +663,34 @@
/* when I and D space are separate, this will have to be fixed. */
case PTRACE_POKETEXT: /* write the word at location addr. */
case PTRACE_POKEDATA: {
- long res=write_long(child,addr,data);
- if(res) {
- set_failure(®s,res);
+ long res = write_long(child,addr,data);
+ if (res) {
+ set_failure(®s,res);
}
return res;
}
case PTRACE_POKEUSR: /* write the specified register */
- {
- long res;
- addr= offset_of_register(addr);
- if(addr < 0) {
- set_failure(®s,-EIO);
- return -EIO;
- }
- res=put_stack_long(child,addr,data);
- if(res) {
- set_failure(®s,res);
- }
- return res;
- }
+ {
+ long res;
+ addr = offset_of_register(addr);
+ if(addr < 0) {
+ set_failure(®s,-EIO);
+ return -EIO;
+ }
+ res = put_stack_long(child, addr, data);
+ if (res) {
+ set_failure(®s,res);
+ }
+ return res;
+ }
case PTRACE_SYSCALL: /* continue and stop at next
(return from) syscall */
case PTRACE_CONT: { /* restart after signal. */
if ((unsigned long) data > NSIG) {
- set_failure(®s,-EIO);
- return -EIO;
+ set_failure(®s,-EIO);
+ return -EIO;
}
if (request == PTRACE_SYSCALL)
child->flags |= PF_TRACESYS;
@@ -694,12 +698,13 @@
child->flags &= ~PF_TRACESYS;
child->exit_code = data;
wake_up_process(child);
+ /* make sure single-step breakpoint is gone. */
ptrace_cancel_bpt(child);
set_success(®s,data);
return 0;
}
- /*
+/*
* make the child exit. Best I can do is send it a sigkill.
* perhaps it should be put in the status that it wants to
* exit.
@@ -707,14 +712,15 @@
case PTRACE_KILL: {
wake_up_process(child);
child->exit_code = SIGKILL;
+ /* make sure single-step breakpoint is gone. */
ptrace_cancel_bpt(child);
return 0;
}
- case PTRACE_SINGLESTEP: { /* set the trap flag. */
+ case PTRACE_SINGLESTEP: { /* execute signle instruction. */
if ((unsigned long) data > NSIG) {
- set_failure(®s,-EIO);
- return -EIO;
+ set_failure(®s,-EIO);
+ return -EIO;
}
res = set_bpt(child);
if (res < 0) {
@@ -723,14 +729,14 @@
child->flags &= ~PF_TRACESYS;
wake_up_process(child);
child->exit_code = data;
- /* give it a chance to run. */
+ /* give it a chance to run. */
return 0;
}
case PTRACE_DETACH: { /* detach a process that was attached. */
if ((unsigned long) data > NSIG) {
- set_failure(®s,-EIO);
- return -EIO;
+ set_failure(®s,-EIO);
+ return -EIO;
}
child->flags &= ~(PF_PTRACED|PF_TRACESYS);
wake_up_process(child);
@@ -738,17 +744,15 @@
REMOVE_LINKS(child);
child->p_pptr = child->p_opptr;
SET_LINKS(child);
- /* make sure the single step bit is not set. */
+ /* make sure single-step breakpoint is gone. */
ptrace_cancel_bpt(child);
return 0;
}
default:
- {
- set_failure(®s,-EIO);
- return -EIO;
- }
- }
+ set_failure(®s,-EIO);
+ return -EIO;
+ }
}
asmlinkage void syscall_trace(void)
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov
with Sam's (original) version of this