2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call implemented in this file:
|
2005-04-21 16:53:53 +02:00
|
|
|
* m_type: SYS_TRACE
|
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
* m2_i1: CTL_ENDPT process that is traced
|
2005-04-21 16:53:53 +02:00
|
|
|
* m2_i2: CTL_REQUEST trace request
|
|
|
|
* m2_l1: CTL_ADDRESS address at traced process' space
|
|
|
|
* m2_l2: CTL_DATA data to be written or returned here
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../system.h"
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#if USE_TRACE
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* do_trace *
|
|
|
|
*==========================================================================*/
|
|
|
|
#define TR_VLSIZE ((vir_bytes) sizeof(long))
|
|
|
|
|
|
|
|
PUBLIC int do_trace(m_ptr)
|
|
|
|
register message *m_ptr;
|
|
|
|
{
|
|
|
|
/* Handle the debugging commands supported by the ptrace system call
|
|
|
|
* The commands are:
|
|
|
|
* T_STOP stop the process
|
|
|
|
* T_OK enable tracing by parent for this process
|
|
|
|
* T_GETINS return value from instruction space
|
|
|
|
* T_GETDATA return value from data space
|
|
|
|
* T_GETUSER return value from user process table
|
|
|
|
* T_SETINS set value from instruction space
|
|
|
|
* T_SETDATA set value from data space
|
|
|
|
* T_SETUSER set value in user process table
|
|
|
|
* T_RESUME resume execution
|
|
|
|
* T_EXIT exit
|
|
|
|
* T_STEP set trace bit
|
|
|
|
*
|
2005-04-29 17:36:43 +02:00
|
|
|
* The T_OK and T_EXIT commands are handled completely by the process manager,
|
2005-04-21 16:53:53 +02:00
|
|
|
* all others come here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
register struct proc *rp;
|
|
|
|
phys_bytes src, dst;
|
|
|
|
vir_bytes tr_addr = (vir_bytes) m_ptr->CTL_ADDRESS;
|
|
|
|
long tr_data = m_ptr->CTL_DATA;
|
|
|
|
int tr_request = m_ptr->CTL_REQUEST;
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
int tr_proc_nr_e = m_ptr->CTL_ENDPT, tr_proc_nr;
|
2006-08-28 16:59:56 +02:00
|
|
|
unsigned char ub;
|
2005-04-21 16:53:53 +02:00
|
|
|
int i;
|
|
|
|
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
if(!isokendpt(tr_proc_nr_e, &tr_proc_nr)) return(EINVAL);
|
2005-07-29 17:26:23 +02:00
|
|
|
if (iskerneln(tr_proc_nr)) return(EPERM);
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
rp = proc_addr(tr_proc_nr);
|
|
|
|
if (isemptyp(rp)) return(EIO);
|
|
|
|
switch (tr_request) {
|
|
|
|
case T_STOP: /* stop process */
|
2005-08-19 18:43:28 +02:00
|
|
|
if (rp->p_rts_flags == 0) lock_dequeue(rp);
|
2005-06-30 17:55:19 +02:00
|
|
|
rp->p_rts_flags |= P_STOP;
|
2005-04-21 16:53:53 +02:00
|
|
|
rp->p_reg.psw &= ~TRACEBIT; /* clear trace bit */
|
|
|
|
return(OK);
|
|
|
|
|
|
|
|
case T_GETINS: /* return value from instruction space */
|
|
|
|
if (rp->p_memmap[T].mem_len != 0) {
|
|
|
|
if ((src = umap_local(rp, T, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
|
|
|
phys_copy(src, vir2phys(&tr_data), (phys_bytes) sizeof(long));
|
2005-07-26 14:48:34 +02:00
|
|
|
m_ptr->CTL_DATA = tr_data;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Text space is actually data space - fall through. */
|
|
|
|
|
|
|
|
case T_GETDATA: /* return value from data space */
|
|
|
|
if ((src = umap_local(rp, D, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
|
|
|
phys_copy(src, vir2phys(&tr_data), (phys_bytes) sizeof(long));
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA= tr_data;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_GETUSER: /* return value from process table */
|
|
|
|
if ((tr_addr & (sizeof(long) - 1)) != 0 ||
|
|
|
|
tr_addr > sizeof(struct proc) - sizeof(long))
|
|
|
|
return(EIO);
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = *(long *) ((char *) rp + (int) tr_addr);
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SETINS: /* set value in instruction space */
|
|
|
|
if (rp->p_memmap[T].mem_len != 0) {
|
|
|
|
if ((dst = umap_local(rp, T, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
|
|
|
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) sizeof(long));
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Text space is actually data space - fall through. */
|
|
|
|
|
|
|
|
case T_SETDATA: /* set value in data space */
|
|
|
|
if ((dst = umap_local(rp, D, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
|
|
|
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) sizeof(long));
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SETUSER: /* set value in process table */
|
|
|
|
if ((tr_addr & (sizeof(reg_t) - 1)) != 0 ||
|
|
|
|
tr_addr > sizeof(struct stackframe_s) - sizeof(reg_t))
|
|
|
|
return(EIO);
|
|
|
|
i = (int) tr_addr;
|
|
|
|
#if (CHIP == INTEL)
|
|
|
|
/* Altering segment registers might crash the kernel when it
|
|
|
|
* tries to load them prior to restarting a process, so do
|
|
|
|
* not allow it.
|
|
|
|
*/
|
|
|
|
if (i == (int) &((struct proc *) 0)->p_reg.cs ||
|
|
|
|
i == (int) &((struct proc *) 0)->p_reg.ds ||
|
|
|
|
i == (int) &((struct proc *) 0)->p_reg.es ||
|
|
|
|
#if _WORD_SIZE == 4
|
|
|
|
i == (int) &((struct proc *) 0)->p_reg.gs ||
|
|
|
|
i == (int) &((struct proc *) 0)->p_reg.fs ||
|
|
|
|
#endif
|
|
|
|
i == (int) &((struct proc *) 0)->p_reg.ss)
|
|
|
|
return(EIO);
|
|
|
|
#endif
|
|
|
|
if (i == (int) &((struct proc *) 0)->p_reg.psw)
|
|
|
|
/* only selected bits are changeable */
|
|
|
|
SETPSW(rp, tr_data);
|
|
|
|
else
|
|
|
|
*(reg_t *) ((char *) &rp->p_reg + i) = (reg_t) tr_data;
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_RESUME: /* resume execution */
|
2005-06-30 17:55:19 +02:00
|
|
|
rp->p_rts_flags &= ~P_STOP;
|
2005-08-19 18:43:28 +02:00
|
|
|
if (rp->p_rts_flags == 0) lock_enqueue(rp);
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STEP: /* set trace bit */
|
|
|
|
rp->p_reg.psw |= TRACEBIT;
|
2005-06-30 17:55:19 +02:00
|
|
|
rp->p_rts_flags &= ~P_STOP;
|
2005-08-19 18:43:28 +02:00
|
|
|
if (rp->p_rts_flags == 0) lock_enqueue(rp);
|
2005-07-25 14:15:05 +02:00
|
|
|
m_ptr->CTL_DATA = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
|
|
|
|
2006-08-28 16:59:56 +02:00
|
|
|
case T_READB_INS: /* get value from instruction space */
|
|
|
|
if (rp->p_memmap[T].mem_len != 0) {
|
|
|
|
if ((dst = umap_local(rp, T, tr_addr, 1)) == 0) return(EFAULT);
|
|
|
|
phys_copy(dst, vir2phys(&ub), (phys_bytes) 1);
|
|
|
|
m_ptr->CTL_DATA = ub;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dst = umap_local(rp, D, tr_addr, 1)) == 0) return(EFAULT);
|
|
|
|
phys_copy(dst, vir2phys(&ub), (phys_bytes) 1);
|
|
|
|
m_ptr->CTL_DATA = ub;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_WRITEB_INS: /* set value in instruction space */
|
|
|
|
if (rp->p_memmap[T].mem_len != 0) {
|
|
|
|
if ((dst = umap_local(rp, T, tr_addr, 1)) == 0) return(EFAULT);
|
|
|
|
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) 1);
|
|
|
|
m_ptr->CTL_DATA = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dst = umap_local(rp, D, tr_addr, 1)) == 0) return(EFAULT);
|
|
|
|
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) 1);
|
|
|
|
m_ptr->CTL_DATA = 0;
|
|
|
|
break;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
default:
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
#endif /* USE_TRACE */
|