trace_intr.c

来自「TRACE的源代码,在LINUX调试程序要使用的.」· C语言 代码 · 共 179 行

C
179
字号
/*  This file (trace_intr.c) was created by Ron Rechenmacher <ron@fnal.gov> on    Dec 15, 1999. "TERMS AND CONDITIONS" governing this file are in the README    or COPYING file. If you do not have such a file, one can be obtained by    contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.*/#define __TRACE_INTR_C_REV	"\$RCSfile: trace_intr.c,v $(i386)\$Revision: 1.11 $\$Date: 2003/07/02 19:42:44 $"#include <linux/trace.h>	/* traceControl_sp */#include <asm/trace_intr.h>	/* TRACE_VECTOR, BUILD_TRACE_INTERRUPT *//*  NOTE: For some reason, if the definition is placed after the includes,    the EXPORT_SYMBOL macro and /sbin/genksyms functionality does not work */char *trace_intr_c_rev = __TRACE_INTR_C_REV __TRACE_H_REV __TRACE_PROCESSOR_H_REV __TRACE_INTR_H_REV;#include <linux/kernel.h>	/*  printk and includes linux/linkage.h for				    __ALIGN_STR */#include <asm/uaccess.h>	/* copy_from_user(to,from,n) */#include <asm/desc.h>		/* struct desc_struct */#include <linux/ptrace.h>	/* struct pt_regs needed by irq.h */#include <linux/sched.h>	/* NULL needed by smp_lock.h */#include <linux/smp.h>		/* NO_PROC_ID needed by smp_lock.h */#include <linux/smp_lock.h>	/* spinlock_t needed by irq.h */#include <linux/sched.h>	/* prof_buffer needed by irq.h */#include <linux/version.h>	/* LINUX_VERSION_CODE, KERNEL_VERSION */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)# include <asm/irq.h>#else# include "irq.h"		/* SAVE_ALL used in BUILD_TRACE_INTERRUPT */#endifBUILD_TRACE_INTERRUPT( trace_trace_interrupt );/****************************************************************************** * *//* declaration for compiler generated memcpy for structure argument passing */#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)#ifdef memcpy# undef memcpy#endifextern voidbcopy( void *src, void *dest, int n );static void *memcpy(  void		*dest       , const void	*src       , size_t		n ){   bcopy( (void *)src, dest, n );    return (dest);}voidtrace_link_in_static_memcpy( void ){    memcpy( (void *)0, (void *)1, 1 );}   /* trace_link_in_static_memcpy */#endifasmlinkage voidtrace_trace_interrupt(  struct timeval	*time		      , int		tid		      , va_list ap )    /* passed ap is ptr to stack location */{	char			msg[traceControl_sp->messageSize_bytes];	struct s_traceEntry	*ep;	struct	{   int		lvl;	    char	*msg;#	    if TRACE_COMPILER_DOES_DYNAMIC_ARRAYS == 1	    int		params[traceControl_sp->numberOfParameter_integers];#	    else	    int		params[TRACE_NUM_PARAMETER_INTS];#	    endif	}			kk;    copy_from_user( &kk, ap, sizeof(kk) );    /* COPYING MESSAGE TWICE!!! NEED TO WORK ON THIS */    copy_from_user( msg, kk.msg, traceControl_sp->messageSize_bytes );    kk.msg = msg; /* over write with kernel address */    ep = traceCircularQueuePut(  tid, kk );    copy_to_user( time, &ep->time, sizeof(struct timeval) );    return;}   /* trace_trace_interrupt *//* mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm *//* STOLEN FROM arch/i386/kernel/traps.c *//* dpl = Descriptor Privilege Level 3=kernel * type=> 5=Task Gate, 6=16bit Interrupt Gate, 14=32bit Interrupt Gate *        7=16bit Trap Gate, 15=32 bit Trap Gate * Ref. p.5-13 of "IA-32 Intel Architecture Software Developer's Manual * Volume 3: System Programming Guide" */#define _set_gate(gate_addr,type,dpl,addr) \do { \  int __d0, __d1; \  __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \	"movw %4,%%dx\n\t" \	"movl %%eax,%0\n\t" \	"movl %%edx,%1" \	:"=m" (*((long *) (gate_addr))), \	 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \	:"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \	 "3" ((char *) (addr)),"2" (__KERNEL_CS << 16)); \} while (0)/****************************************************************************** *  trace_interrupt_init * * NOTE: arch/i386/kernel/traps.c:trap_init and *       arch/i386/kernel/irq.c:init_IRQ are called from *       init/main.c (init_IRQ AFTER trap_init) *       SO, I need to modify irq.c OR I could patch (or just put code in) *       init/trace.c:trace_init() which is also called from init/main.c *       after trap_init and init_IRQ * In "IA-32 Intel Architecture Software Developer's Manual Volume 1: * Basic Architecture" the concepts of the interrupt descriptor table (IDT) * and interrupt gate vs call gate are discussed (ref. p.6-11). (ref. * http://www.intel.com/design/pentium/manuals/) */voidtrace_interrupt_init( void ){    _set_gate( idt_table+TRACE_VECTOR, 14, 3, trace_interrupt );    return;}   /* trace_interrupt_init *//* ######################################################################### *//*  EXPORT_SYMTAB get defined on the compile line for OX_OBJS make file    target */#include <linux/module.h>	/* has module code - effects alignment! *//* traceControl_sp export in kernel/ksyms.c */EXPORT_SYMBOL( idt_table );EXPORT_SYMBOL( traceCircularQueuePut );#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)EXPORT_SYMBOL( bcopy );#endif#ifdef MODULE/*  gcc -O -Wall -DMODULE -D__KERNEL__ -D__SMP__ -c trace_intr.c	OR    gcc -O -Wall -DMODULE -D__KERNEL__ -D__SMP__ -c trace_intr.c \-DMODVERSIONS -DEXPORT_SYMTAB \-include /usr/src/linux/include/linux/modversions.h*/intinit_module( void ){   printk( "init for trace_intr - configuring interrupt\n" );    trace_interrupt_init();    return (0);}voidcleanup_module( void ){   printk( "nothing to cleanup for trace_intr\n" );}#endif /* MODULE */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?