diff -Naru linux-2.4.19/Documentation/Configure.help linux-2.4.19-lkst/Documentation/Configure.help
--- linux-2.4.19/Documentation/Configure.help	2003-04-14 15:05:00.000000000 -0400
+++ linux-2.4.19-lkst/Documentation/Configure.help	2003-04-14 15:07:28.000000000 -0400
@@ -25297,6 +25297,59 @@
 
   If unsure, say N.
 
+Linux Kernel State Tracer
+CONFIG_DEBUG_KERNEL_STATE_TRACE
+  If you say Y or M here, LKST is enabled.
+  Linux Kernel State Tracer(LKST) records information as trace data
+  about events in the Linux Kernel. It records various events like
+  process context switch, send signal, exception, memory allocation,
+  send packet, and so on.
+  This program is a facility for analyzing trouble of the Linux Kernel.
+  It becomes possible that developers investigate troubles by this facility
+  without stopping important(used for Mission Critical purposes) server.
+  If unsure, say N.
+
+Enable trace into inline functions
+CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE
+  If you say Y here, all LKST events is will be recording.
+  If you say N here, LKST events in inline-functions are ignored.
+
+Hook one time in waiting lock
+CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME
+  If you say Y here, LKST records spinlock events just one time when
+  lock-waitng occurs. This will reduce an amount of logged entries 
+  related with the spinlock event.
+  If unsure, say N.
+
+Read from a different device file for each CPU
+CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+  If you say Y here, you can read from a different device file for each
+  CPU without ioctl(LKST_IOC_BUFFER_SETRMOD).
+  Those devices are represented as /dev/lkst0-31(char dev, major=231,
+  minor=1-32).
+  If unsure, say N.
+
+Static Event Buffer Size
+CONFIG_DEBUG_LKST_SBUF_TINY
+  You can choose the size of Static Shared Buffer. This buffer allow 
+  every CPU to read/write logs.
+  If you will build a kernel for embeded, choose small size(32KB).
+  
+  For normal, choose medium size(128KB).
+  
+  For enterprise, choose large size(512KB).
+
+Verify pointers in LKST (RECOMMENDED)
+CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION
+  If you say Y here, LKST verify the value of pointers strictly. It
+  rarely allow LKST to avoid crash by memory corruption and by bugs in 
+  other kernel modules.
+  This option is recommended for enterprise user, so say Y.
+  
+  If unsure, say N.
+#  But, IMHO, I will say N, since it is in very rare case that LKST can
+#  avoid crashes by this feature...
+
 #
 # A couple of things I keep forgetting:
 #   capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet,
diff -Naru linux-2.4.19/Makefile linux-2.4.19-lkst/Makefile
--- linux-2.4.19/Makefile	2003-04-14 15:02:46.000000000 -0400
+++ linux-2.4.19-lkst/Makefile	2003-04-14 15:05:05.000000000 -0400
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 19
-EXTRAVERSION =
+EXTRAVERSION = -lkst15
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
@@ -189,6 +189,7 @@
 DRIVERS-$(CONFIG_BLUEZ) += drivers/bluetooth/bluetooth.o
 DRIVERS-$(CONFIG_HOTPLUG_PCI) += drivers/hotplug/vmlinux-obj.o
 DRIVERS-$(CONFIG_ISDN_BOOL) += drivers/isdn/vmlinux-obj.o
+DRIVERS-$(CONFIG_DEBUG_KERNEL_STATE_TRACE) += drivers/lkst/lkst.o
 
 DRIVERS := $(DRIVERS-y)
 
diff -Naru linux-2.4.19/arch/i386/boot/compressed/misc.c linux-2.4.19-lkst/arch/i386/boot/compressed/misc.c
--- linux-2.4.19/arch/i386/boot/compressed/misc.c	2003-04-14 15:04:27.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/boot/compressed/misc.c	2003-04-14 15:06:56.000000000 -0400
@@ -9,6 +9,7 @@
  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  */
 
+#define LKST_SUPPRESS_PIO_TRACE
 #include <linux/linkage.h>
 #include <linux/vmalloc.h>
 #include <linux/tty.h>
diff -Naru linux-2.4.19/arch/i386/config.in linux-2.4.19-lkst/arch/i386/config.in
--- linux-2.4.19/arch/i386/config.in	2003-04-14 15:04:27.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/config.in	2003-04-21 11:20:04.000000000 -0400
@@ -431,6 +431,24 @@
    bool '  Debug memory allocations' CONFIG_DEBUG_SLAB
    bool '  Memory mapped I/O debugging' CONFIG_DEBUG_IOVIRT
    bool '  Magic SysRq key' CONFIG_MAGIC_SYSRQ
+   tristate '  Kernel State Tracing (LKST) Support' CONFIG_DEBUG_KERNEL_STATE_TRACE
+   if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE" = "y" ]; then
+  	 bool '    Enable in starting kernel' CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START
+   fi
+   if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE" != "n" ]; then
+       	define_bool CONFIG_HOOK y
+	bool '    Enable trace into inline functions' CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE  "y"
+	if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE" = "y" ]; then
+	   bool '      Hook one time in waiting lock' CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME
+	fi
+	bool '    Verify pointers in LKST' CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION
+	bool '    Do NOT expand bitwidth of arguments to 64bits' CONFIG_DEBUG_LKST_DONOT_EXPAND_ARGBITS
+	dep_mbool '    Read from per CPU devices(EXPERIMENTAL)' CONFIG_DEBUG_LKST_DEVICE_PER_CPU $CONFIG_DEBUG_KERNEL_STATE_TRACE $CONFIG_EXPERIMENTAL
+	choice 'Static Event Buffer Size' \
+		"32KB    CONFIG_DEBUG_LKST_SBUF_TINY \
+		128KB    CONFIG_DEBUG_LKST_SBUF_MIDIUM \
+		512KB    CONFIG_DEBUG_LKST_SBUF_LARGE" 128KB
+   fi
    bool '  Spinlock debugging' CONFIG_DEBUG_SPINLOCK
    bool '  Compile the kernel with frame pointers' CONFIG_FRAME_POINTER
 fi
diff -Naru linux-2.4.19/arch/i386/defconfig linux-2.4.19-lkst/arch/i386/defconfig
--- linux-2.4.19/arch/i386/defconfig	2003-04-14 15:04:27.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/defconfig	2003-04-14 15:06:56.000000000 -0400
@@ -878,3 +878,6 @@
 # Kernel hacking
 #
 # CONFIG_DEBUG_KERNEL is not set
+CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE=y
+CONFIG_DEBUG_LKST_SBUF_MEDIUM=y
+CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION=y
diff -Naru linux-2.4.19/arch/i386/kernel/entry.S linux-2.4.19-lkst/arch/i386/kernel/entry.S
--- linux-2.4.19/arch/i386/kernel/entry.S	2003-04-14 15:04:28.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/kernel/entry.S	2003-04-21 11:21:56.000000000 -0400
@@ -194,6 +194,29 @@
 ENTRY(system_call)
 	pushl %eax			# save orig_eax
 	SAVE_ALL
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+	.global LKST_ETYPE_SYSCALL_ENTRY_HEADER
+LKST_ETYPE_SYSCALL_ENTRY_HEADER:
+	movl $0, %eax
+	testl %eax, %eax
+	je .L_LKST11
+	movl $(LKST_ETYPE_SYSCALL_ENTRY_HEADER_head), %ecx
+	movl ORIG_EAX(%esp), %eax	# get syscall number
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl %eax	# push syscall number
+	pushl $48	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+ 	addl $40, %esp	# modify stack pointer
+.L_LKST11:
+        movl ORIG_EAX(%esp),%eax
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	GET_CURRENT(%ebx)
 	testb $0x02,tsk_ptrace(%ebx)	# PT_TRACESYS
 	jne tracesys
@@ -201,8 +224,38 @@
 	jae badsys
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+	.global LKST_ETYPE_SYSCALL_EXIT_HEADER
+LKST_ETYPE_SYSCALL_EXIT_HEADER:
+	movl $0, %eax
+	testl %eax, %eax
+	je .L_LKST21
+	movl ORIG_EAX(%esp),%ecx	# get syscall number
+	movl EAX(%esp),%eax		# get return value
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+#if defined(CONFIG_DEBUG_LKST_DONOT_EXPAND_ARGBITS)
+	pushl $0
+#else
+	cltd
+	pushl %edx	# push return value (high)
+#endif
+	pushl %eax	# push return value
+	pushl $0
+        pushl %ecx  	# push syscall number
+	pushl $49	# push event type
+	movl $(LKST_ETYPE_SYSCALL_EXIT_HEADER_head), %edx
+	pushl 8(%edx)
+	call *(%edx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST21:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
+
 ENTRY(ret_from_sys_call)
 	cli				# need_resched and signals atomic test
+	GET_CURRENT(%ebx)
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
@@ -286,9 +339,53 @@
 	movl $(__KERNEL_DS),%edx
 	movl %edx,%ds
 	movl %edx,%es
-	GET_CURRENT(%ebx)
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST31
+	movl $(LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head), %ebx
+	movl %esi, %eax
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl 60(%esp)	# exception address (60 = EIP + 20)
+#if defined(CONFIG_DEBUG_LKST_DONOT_EXPAND_ARGBITS)
+	pushl $0
+#else
+	cltd
+	pushl %edx	# push the error code (high)
+#endif
+	pushl %eax	# push the error code 
+	pushl $0
+	pushl %edi	# push the function address
+	pushl $32	# push event type
+	pushl 8(%ebx)
+	call *(%ebx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST31:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */	
+	GET_CURRENT(%ebx) 
 	call *%edi
 	addl $8,%esp
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&& defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_EXIT_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST41
+	movl $(LKST_ETYPE_EXCEPTION_EXIT_HEADER_head), %ecx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl %edi	# push the exception handler address
+	pushl $33	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+    addl $40, %esp	# modify stack pointer
+.L_LKST41:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	jmp ret_from_exception
 
 ENTRY(coprocessor_error)
@@ -304,16 +401,93 @@
 ENTRY(device_not_available)
 	pushl $-1		# mark this as an int
 	SAVE_ALL
-	GET_CURRENT(%ebx)
 	movl %cr0,%eax
 	testl $0x4,%eax			# EM (math emulation bit)
 	jne device_not_available_emulate
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )&& defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST51
+ 	movl $(LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head), %ecx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0	# push a dummy value
+	pushl $0
+	pushl $7	# push the exception No.7
+	pushl $0
+	pushl $math_state_restore	# push handler address
+	pushl $32	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST51:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
+	GET_CURRENT(%ebx) 
 	call SYMBOL_NAME(math_state_restore)
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_EXIT_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST81
+ 	movl $(LKST_ETYPE_EXCEPTION_EXIT_HEADER_head), %ecx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $math_state_restore	# push handler address
+	pushl $33	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+ 	addl $40, %esp	# modify stack pointer
+.L_LKST81:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	jmp ret_from_exception
 device_not_available_emulate:
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )&& defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST52
+ 	movl $(LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head), %ecx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0	# push a dummy value
+	pushl $0
+	pushl $7	# push the exception No.7
+	pushl $0
+	pushl $math_emulate	# push handler address
+	pushl $32	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST52:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
+	GET_CURRENT(%ebx) 
 	pushl $0		# temporary storage for ORIG_EIP
 	call  SYMBOL_NAME(math_emulate)
 	addl $4,%esp
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_EXIT_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST91
+ 	movl $(LKST_ETYPE_EXCEPTION_EXIT_HEADER_head), %ecx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $math_emulate	# push handler address
+	pushl $33	# push event type
+	pushl 8(%ecx)
+	call *(%ecx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST91:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	jmp ret_from_exception
 
 ENTRY(debug)
@@ -324,11 +498,49 @@
 ENTRY(nmi)
 	pushl %eax
 	SAVE_ALL
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&& defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST61
+	movl $(LKST_ETYPE_EXCEPTION_ENTRY_HEADER_head), %ebx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0	# push a dummy value
+	pushl $0
+	pushl $2	# push the exception No.2
+	pushl $0
+	pushl $do_nmi	# push handler address
+	pushl $32	# push event type
+	pushl 8(%ebx)
+	call *(%ebx)	# call handler
+	addl $40, %esp	# modify stack pointer
+.L_LKST61:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	movl %esp,%edx
 	pushl $0
 	pushl %edx
 	call SYMBOL_NAME(do_nmi)
 	addl $8,%esp
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+	movl LKST_ETYPE_EXCEPTION_EXIT_HEADER_head+16, %eax
+	testl %eax, %eax
+	jns .L_LKST71
+	movl $(LKST_ETYPE_EXCEPTION_EXIT_HEADER_head), %ebx
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $0
+	pushl $do_nmi	# push handler address
+	pushl $33	# push event type
+	pushl 8(%ebx)
+	call *(%ebx)	# call handler
+ 	addl $40, %esp	# modify stack pointer
+.L_LKST71:
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
 	RESTORE_ALL
 
 ENTRY(int3)
diff -Naru linux-2.4.19/arch/i386/kernel/irq.c linux-2.4.19-lkst/arch/i386/kernel/irq.c
--- linux-2.4.19/arch/i386/kernel/irq.c	2003-04-14 15:04:28.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/kernel/irq.c	2003-04-14 15:06:58.000000000 -0400
@@ -44,7 +44,7 @@
 #include <asm/desc.h>
 #include <asm/irq.h>
 
-
+#include <linux/lkst.h>
 
 /*
  * Linux has a controller-independent x86 interrupt architecture.
@@ -620,7 +620,11 @@
 	 * SMP environment.
 	 */
 	for (;;) {
-		spin_unlock(&desc->lock);
+        LKST_HOOK(LKST_ETYPE_INT_HARDWARE_ENTRY,
+			LKST_ARG(irq), LKST_ARG(status),
+			LKST_ARG(0),
+			LKST_ARG(0) );
+	        spin_unlock(&desc->lock);
 		handle_IRQ_event(irq, &regs, action);
 		spin_lock(&desc->lock);
 		
diff -Naru linux-2.4.19/arch/i386/kernel/nmi.c linux-2.4.19-lkst/arch/i386/kernel/nmi.c
--- linux-2.4.19/arch/i386/kernel/nmi.c	2003-04-14 15:04:28.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/kernel/nmi.c	2003-04-14 15:06:57.000000000 -0400
@@ -361,6 +361,8 @@
 		 */
 		alert_counter[cpu]++;
 		if (alert_counter[cpu] == 5*nmi_hz) {
+			LKST_HOOK(LKST_ETYPE_OOPS_NMIWDOG,
+				  regs->eip,0,0,0);
 			spin_lock(&nmi_print_lock);
 			/*
 			 * We are in trouble anyway, lets at least try
diff -Naru linux-2.4.19/arch/i386/kernel/process.c linux-2.4.19-lkst/arch/i386/kernel/process.c
--- linux-2.4.19/arch/i386/kernel/process.c	2003-04-14 15:04:28.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/kernel/process.c	2003-04-14 15:06:57.000000000 -0400
@@ -50,6 +50,8 @@
 
 #include <linux/irq.h>
 
+#include <linux/lkst.h>
+
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
 int hlt_counter;
@@ -489,6 +491,10 @@
 {
 	long retval, d0;
 
+	LKST_HOOK(LKST_ETYPE_PROCESS_LTHREADGEN,
+		LKST_ARGP(fn), LKST_ARGP(arg),
+		LKST_ARG(flags), LKST_ARG(0));
+
 	__asm__ __volatile__(
 		"movl %%esp,%%esi\n\t"
 		"int $0x80\n\t"		/* Linux/i386 system call */
diff -Naru linux-2.4.19/arch/i386/mm/fault.c linux-2.4.19-lkst/arch/i386/mm/fault.c
--- linux-2.4.19/arch/i386/mm/fault.c	2003-04-14 15:04:27.000000000 -0400
+++ linux-2.4.19-lkst/arch/i386/mm/fault.c	2003-04-14 15:06:56.000000000 -0400
@@ -25,6 +25,8 @@
 #include <asm/pgalloc.h>
 #include <asm/hardirq.h>
 
+#include <linux/lkst.h>
+
 extern void die(const char *,struct pt_regs *,long);
 
 /*
@@ -307,6 +309,9 @@
  * terminate things with extreme prejudice.
  */
 
+	LKST_HOOK(LKST_ETYPE_OOPS_PGFAULT,
+		LKST_ARG(address), LKST_ARG(regs->eip),
+		LKST_ARG(error_code), LKST_ARG(0));
 	bust_spinlocks(1);
 
 	if (address < PAGE_SIZE)
diff -Naru linux-2.4.19/arch/ia64/config.in linux-2.4.19-lkst/arch/ia64/config.in
--- linux-2.4.19/arch/ia64/config.in	2003-04-14 15:04:50.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/config.in	2003-04-14 15:07:19.000000000 -0400
@@ -283,6 +283,23 @@
 
    bool '  Early printk support (requires VGA!)' CONFIG_IA64_EARLY_PRINTK
    bool '  Debug memory allocations' CONFIG_DEBUG_SLAB
+   tristate '  Kernel State Tracing (LKST) Support' CONFIG_DEBUG_KERNEL_STATE_TRACE
+   if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE" = "y" ]; then
+  	 bool '    Enable in starting kernel' CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START
+   fi
+   if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE" != "n" ]; then
+       	define_bool CONFIG_HOOK y
+	bool '    Enable trace into inline functions' CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE  "y"
+	if [ "$CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE" = "y" ]; then
+	   bool '      Hook one time in waiting lock' CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME
+	fi
+	bool '    Verify pointers in LKST (RECOMMENDED)' CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION
+	dep_mbool '    Read from per CPU devices(EXPERIMENTAL)' CONFIG_DEBUG_LKST_DEVICE_PER_CPU $CONFIG_DEBUG_KERNEL_STATE_TRACE $CONFIG_EXPERIMENTAL
+	choice 'Static Event Buffer Size' \
+		"32KB    CONFIG_DEBUG_LKST_SBUF_TINY \
+		128KB    CONFIG_DEBUG_LKST_SBUF_MIDIUM \
+		512KB    CONFIG_DEBUG_LKST_SBUF_LARGE" 128KB
+   fi
    bool '  Spinlock debugging' CONFIG_DEBUG_SPINLOCK
    bool '  Turn on compare-and-exchange bug checking (slow!)' CONFIG_IA64_DEBUG_CMPXCHG
    bool '  Turn on irq debug checks (slow!)' CONFIG_IA64_DEBUG_IRQ
diff -Naru linux-2.4.19/arch/ia64/kernel/entry.S linux-2.4.19-lkst/arch/ia64/kernel/entry.S
--- linux-2.4.19/arch/ia64/kernel/entry.S	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/entry.S	2003-04-14 15:07:20.000000000 -0400
@@ -482,6 +482,87 @@
 	br.cond.sptk strace_save_retval
 END(ia64_trace_syscall)
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+GLOBAL_ENTRY(lkst_ia64_invoke_syscall_entry)
+	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8)
+	alloc loc1=ar.pfs,8,3,4,0
+	mov loc0=rp
+	.body
+	mov loc2=b6
+	mov out0=b6	// syscall entry point
+	mov out1=r3	// syscall number
+	mov out2=0
+	mov out3=0
+	;;
+	br.call.sptk.many rp=lkst_ia64_syscall_entry
+.ret_lkst_entry:
+	mov rp=loc0
+	mov ar.pfs=loc1
+	mov b6=loc2
+	br.ret.sptk.many rp
+END(lkst_ia64_invoke_syscall_entry)
+
+GLOBAL_ENTRY(lkst_ia64_invoke_syscall_exit)
+	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(8)
+	alloc loc1=ar.pfs,8,3,4,0
+	mov loc0=rp
+	.body
+	mov loc2=b6
+	mov out0=b6	// syscall entry point
+	mov out1=r8	// syscall return value
+	mov out2=0
+	mov out3=0
+	;;
+	br.call.sptk.many rp=lkst_ia64_syscall_exit
+.ret_lkst_exit:
+	mov rp=loc0
+	mov ar.pfs=loc1
+	mov b6=loc2
+	br.ret.sptk.many rp
+END(lkst_ia64_invoke_syscall_exit)
+
+GLOBAL_ENTRY(lkst_ia64_syscall)
+	PT_REGS_UNWIND_INFO(0)
+
+	// give parent a chance to catch syscall args
+	br.call.sptk.many rp=lkst_ia64_invoke_syscall_entry
+
+.ret_lkst_invoke_entry:
+	br.call.sptk.many rp=b6			// do the syscall
+
+lkst_ia64_syscall_check_retval:
+	cmp.lt p6,p0=r8,r0			// syscall failed?
+	adds r2=PT(R8)+16,sp			// r2 = &pt_regs.r8
+	adds r3=PT(R10)+16,sp			// r3 = &pt_regs.r10
+	mov r10=0
+(p6)	br.cond.sptk lkst_ia64_syscall_error	// syscall failed ->
+	;;					// avoid RAW on r10
+
+lkst_ia64_syscall_save_retval:
+.mem.offset 0,0;	st8.spill [r2]=r8	// store return value in slot for r8
+.mem.offset 8,0;	st8.spill [r3]=r10	// clear error indication in slot for r10
+
+lkst_ia64_syscall_leave_kernel:
+	// give parent a chance to catch return value
+	br.call.sptk.many rp=lkst_ia64_invoke_syscall_exit
+
+.ret_lkst_invoke_exit:
+	br.cond.sptk ia64_leave_kernel		// do the return
+
+lkst_ia64_syscall_error:
+	ld8 r3=[r2]				// load pt_regs.r8
+	sub r9=0,r8				// negate return value to get errno value
+	;;
+	cmp.ne p6,p0=r3,r0			// is pt_regs.r8!=0?
+	adds r3=16,r2				// r3=&pt_regs.r10
+	;;
+(p6)	mov r10=-1
+(p6)	mov r8=r9
+	br.cond.sptk lkst_ia64_syscall_save_retval
+END(lkst_ia64_syscall)
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 GLOBAL_ENTRY(ia64_ret_from_clone)
 	PT_REGS_UNWIND_INFO(0)
 	/*
@@ -885,7 +966,12 @@
 	mov r16=r0
 	.prologue
 	DO_SAVE_SWITCH_STACK
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	br.call.sptk.many rp=lkst_ia64_handle_unaligned
+#else  /* !(..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	br.call.sptk.many rp=ia64_handle_unaligned // stack frame setup in ivt
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 .ret21:	.body
 	DO_LOAD_SWITCH_STACK
 	br.cond.sptk.many rp			  // goes to ia64_leave_kernel
diff -Naru linux-2.4.19/arch/ia64/kernel/irq.c linux-2.4.19-lkst/arch/ia64/kernel/irq.c
--- linux-2.4.19/arch/ia64/kernel/irq.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/irq.c	2003-04-14 15:07:20.000000000 -0400
@@ -43,6 +43,7 @@
 #include <asm/delay.h>
 #include <asm/irq.h>
 
+#include <linux/lkst.h>
 
 
 /*
@@ -647,6 +648,12 @@
 		 * SMP environment.
 		 */
 		for (;;) {
+			LKST_HOOK(LKST_ETYPE_INT_HARDWARE_ENTRY,
+					LKST_ARG(irq),
+					LKST_ARG(status),
+					LKST_ARG(0),
+					LKST_ARG(0));
+
 			spin_unlock(&desc->lock);
 			handle_IRQ_event(irq, regs, action);
 			spin_lock(&desc->lock);
diff -Naru linux-2.4.19/arch/ia64/kernel/ivt.S linux-2.4.19-lkst/arch/ia64/kernel/ivt.S
--- linux-2.4.19/arch/ia64/kernel/ivt.S	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/ivt.S	2003-04-14 15:07:20.000000000 -0400
@@ -372,7 +372,12 @@
 	mov rp=r14
 	;;
 	adds out2=16,r12			// out2 = pointer to pt_regs
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	br.call.sptk.many b6=lkst_ia64_do_page_fault
+#else  /* !(..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	br.call.sptk.many b6=ia64_do_page_fault	// ignore return address
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 END(page_fault)
 
 	.align 1024
@@ -648,6 +653,7 @@
 	;;
 	cmp.geu p6,p7=r3,r15		// (syscall > 0 && syscall <= 1024+255) ?
 	movl r16=sys_call_table
+	adds r3=1024,r15			// store syscall number to r3
 	;;
 (p6)	shladd r16=r15,3,r16
 	movl r15=ia64_ret_from_syscall
@@ -681,7 +687,12 @@
 	;;
 	st8 [r16]=r18				// store new value for cr.isr
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+(p8)	br.cond.sptk lkst_ia64_syscall
+#else  /* !(..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 (p8)	br.call.sptk.many b6=b6			// ignore this return addr
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	br.cond.sptk ia64_trace_syscall
 	// NOT REACHED
 END(break_fault)
@@ -783,7 +794,12 @@
 	;;
 	SAVE_REST
 	;;
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	br.call.sptk.many rp=lkst_ia64_illegal_op_fault
+#else  /* !(..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	br.call.sptk.many rp=ia64_illegal_op_fault
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 .ret0:	;;
 	alloc r14=ar.pfs,0,0,3,0	// must be first in insn group
 	mov out0=r9
@@ -918,7 +934,12 @@
 	SAVE_REST
 	mov rp=r15
 	;;
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	br.call.sptk.many b6=lkst_ia64_bad_break
+#else  /* !(..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	br.call.sptk.many b6=ia64_bad_break	// avoid WAW on CFM and ignore return addr
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 END(non_syscall)
 
 	.align 1024
diff -Naru linux-2.4.19/arch/ia64/kernel/process.c linux-2.4.19-lkst/arch/ia64/kernel/process.c
--- linux-2.4.19/arch/ia64/kernel/process.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/process.c	2003-04-14 15:07:20.000000000 -0400
@@ -33,6 +33,8 @@
 #include <asm/sn/idle.h>
 #endif
 
+#include <linux/lkst.h>
+
 static void
 do_show_stack (struct unw_frame_info *info, void *arg)
 {
@@ -474,6 +476,12 @@
 	struct task_struct *parent = current;
 	int result, tid;
 
+	LKST_HOOK(LKST_ETYPE_PROCESS_LTHREADGEN,
+			LKST_ARG(fn),
+			LKST_ARG(arg),
+			LKST_ARG(flags),
+			LKST_ARG(0));
+
 	tid = clone(flags | CLONE_VM, 0);
 	if (parent != current) {
 		result = (*fn)(arg);
diff -Naru linux-2.4.19/arch/ia64/kernel/sys_ia64.c linux-2.4.19-lkst/arch/ia64/kernel/sys_ia64.c
--- linux-2.4.19/arch/ia64/kernel/sys_ia64.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/sys_ia64.c	2003-04-14 15:07:20.000000000 -0400
@@ -16,6 +16,8 @@
 #include <linux/smp_lock.h>
 #include <linux/highuid.h>
 
+#include <linux/lkst.h>
+
 #include <asm/shmparam.h>
 #include <asm/uaccess.h>
 
@@ -417,3 +419,29 @@
 }
 
 #endif /* CONFIG_PCI */
+
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+void
+lkst_ia64_syscall_entry(u_long entry, u_long arg2, u_long arg3, u_long arg4)
+{
+	LKST_HOOK(LKST_ETYPE_SYSCALL_ENTRY,
+			LKST_ARG(entry),
+			LKST_ARG(arg2),
+			LKST_ARG(arg3),
+			LKST_ARG(arg4));
+	return;
+}
+
+void
+lkst_ia64_syscall_exit(u_long entry, u_long retval, u_long arg3, u_long arg4)
+{
+	LKST_HOOK(LKST_ETYPE_SYSCALL_EXIT,
+			LKST_ARG(entry),
+			LKST_ARG(retval),
+			LKST_ARG(arg3),
+			LKST_ARG(arg4));
+	return;
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
diff -Naru linux-2.4.19/arch/ia64/kernel/traps.c linux-2.4.19-lkst/arch/ia64/kernel/traps.c
--- linux-2.4.19/arch/ia64/kernel/traps.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/traps.c	2003-04-14 15:07:20.000000000 -0400
@@ -42,6 +42,8 @@
 
 #include <asm/fpswa.h>
 
+#include <linux/lkst.h>
+
 extern spinlock_t timerlist_lock;
 
 static fpswa_interface_t *fpswa_interface;
@@ -203,6 +205,29 @@
 	force_sig_info(sig, &siginfo, current);
 }
 
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+void
+lkst_ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
+{
+	LKST_HOOK(LKST_ETYPE_EXCEPT_BADBRK_ENTRY,
+			LKST_ARG(break_num),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	ia64_bad_break(break_num, regs);
+
+	LKST_HOOK(LKST_ETYPE_EXCEPT_BADBRK_EXIT,
+			LKST_ARG(break_num),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
+
 /*
  * Unimplemented system calls.  This is called only for stuff that
  * we're supposed to implement but haven't done so yet.  Everything
@@ -422,11 +447,48 @@
 	return rv;
 }
 
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+struct illegal_op_return
+lkst_ia64_illegal_op_fault (unsigned long ec,   unsigned long arg1,
+			    unsigned long arg2, unsigned long arg3,
+			    unsigned long arg4, unsigned long arg5,
+			    unsigned long arg6, unsigned long arg7,
+			    unsigned long stack)
+{
+	struct pt_regs *regs = (struct pt_regs *) &stack;
+	struct illegal_op_return rv;
+
+	LKST_HOOK(LKST_ETYPE_EXCEPT_ILLOP_ENTRY,
+			LKST_ARG(ec),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	rv = ia64_illegal_op_fault(ec,arg1,arg2,arg3,arg4,arg5,arg6,arg7,stack);
+
+	LKST_HOOK(LKST_ETYPE_EXCEPT_ILLOP_EXIT,
+			LKST_ARG(ec),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	return rv;
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
+
 void
 ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
 	    unsigned long iim, unsigned long itir, unsigned long arg5,
 	    unsigned long arg6, unsigned long arg7, unsigned long stack)
 {
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	extern void lkst_ia64_fault_entry(ulong, ulong, ulong, ulong);
+	extern void lkst_ia64_fault_exit (ulong, ulong, ulong, ulong);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 	struct pt_regs *regs = (struct pt_regs *) &stack;
 	unsigned long code, error = isr;
 	struct siginfo siginfo;
@@ -442,6 +504,10 @@
 		"Unknown fault 9", "Unknown fault 10", "Unknown fault 11", "Unknown fault 12",
 		"Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
 	};
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	lkst_ia64_fault_entry (vector, isr, regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
 
 #if 0
 	/* this is for minimal trust debugging; yeah this kind of stuff is useful at times... */
@@ -478,6 +544,14 @@
 # ifdef CONFIG_IA64_PRINT_HAZARDS
 			printk("%016lx:possible hazard, pr = %016lx\n", regs->cr_iip, regs->pr);
 # endif
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
 		}
 		break;
@@ -485,6 +559,13 @@
 	      case 25: /* Disabled FP-Register */
 		if (isr & 2) {
 			disabled_fph_fault(regs);
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
 		}
 		sprintf(buf, "Disabled FPL fault---not supposed to happen!");
@@ -501,6 +582,13 @@
 			siginfo.si_flags = __ISR_VALID;
 			siginfo.si_isr = isr;
 			force_sig_info(SIGILL, &siginfo, current);
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
 		}
 		sprintf(buf, (vector == 26) ? "NaT consumption" : "Unsupported data reference");
@@ -532,6 +620,12 @@
 		siginfo.si_addr = 0;
 		siginfo.si_imm = 0;
 		force_sig_info(SIGTRAP, &siginfo, current);
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+		lkst_ia64_fault_exit(vector, isr, regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 		return;
 
 	      case 32: /* fp fault */
@@ -547,6 +641,12 @@
 			siginfo.si_imm = 0;
 			force_sig_info(SIGFPE, &siginfo, current);
 		}
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+		lkst_ia64_fault_exit(vector, isr, regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 		return;
 
 	      case 34:		/* Unimplemented Instruction Address Trap */
@@ -559,6 +659,13 @@
 			siginfo.si_imm = 0;
 			siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
 			force_sig_info(SIGILL, &siginfo, current);
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
 		}
 		sprintf(buf, "Unimplemented Instruction Address fault");
@@ -566,8 +673,16 @@
 
 	      case 45:
 #ifdef CONFIG_IA32_SUPPORT
-		if (ia32_exception(regs, isr) == 0)
+		if (ia32_exception(regs, isr) == 0) {
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
+		}
 #endif
 		printk("Unexpected IA-32 exception (Trap 45)\n");
 		printk("  iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx\n", regs->cr_iip, ifa, isr);
@@ -576,13 +691,27 @@
 
 	      case 46:
 #ifdef CONFIG_IA32_SUPPORT
-		if (ia32_intercept(regs, isr) == 0)
+		if (ia32_intercept(regs, isr) == 0) {
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+			lkst_ia64_fault_exit(vector, isr,
+						regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 			return;
+		}
 #endif
 		printk("Unexpected IA-32 intercept trap (Trap 46)\n");
 		printk("  iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx, iim - 0x%lx\n",
 		       regs->cr_iip, ifa, isr, iim);
 		force_sig(SIGSEGV, current);
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+		lkst_ia64_fault_exit(vector, isr, regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 		return;
 
 	      case 47:
@@ -593,6 +722,39 @@
 		sprintf(buf, "Fault %lu", vector);
 		break;
 	}
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+	lkst_ia64_fault_exit(vector, isr, regs->cr_ipsr, regs->cr_iip);
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
+
 	die_if_kernel(buf, regs, error);
 	force_sig(SIGILL, current);
 }
+
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+void
+lkst_ia64_fault_entry (unsigned long vector, unsigned long isr,
+		       unsigned long ipsr, unsigned long iip)
+{
+	LKST_HOOK(LKST_ETYPE_EXCEPT_FAULT_ENTRY,
+			LKST_ARG(vector),
+			LKST_ARG(isr),
+			LKST_ARG(ipsr),
+			LKST_ARG(iip));
+}
+
+
+void
+lkst_ia64_fault_exit (unsigned long vector, unsigned long isr,
+		      unsigned long ipsr, unsigned long iip)
+{
+	LKST_HOOK(LKST_ETYPE_EXCEPT_FAULT_EXIT,
+			LKST_ARG(vector),
+			LKST_ARG(isr),
+			LKST_ARG(ipsr),
+			LKST_ARG(iip));
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
diff -Naru linux-2.4.19/arch/ia64/kernel/unaligned.c linux-2.4.19-lkst/arch/ia64/kernel/unaligned.c
--- linux-2.4.19/arch/ia64/kernel/unaligned.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/kernel/unaligned.c	2003-04-14 15:07:20.000000000 -0400
@@ -18,6 +18,8 @@
 #include <asm/processor.h>
 #include <asm/unaligned.h>
 
+#include <linux/lkst.h>
+
 extern void die_if_kernel(char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
 
 #undef DEBUG_UNALIGNED_TRAP
@@ -1494,3 +1496,25 @@
 	force_sig_info(SIGBUS, &si, current);
 	goto done;
 }
+
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+void
+lkst_ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
+{
+	LKST_HOOK(LKST_ETYPE_EXCEPT_UNALIGN_ENTRY,
+			LKST_ARG(ifa),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	ia64_handle_unaligned(ifa, regs);
+
+	LKST_HOOK(LKST_ETYPE_EXCEPT_UNALIGN_EXIT,
+			LKST_ARG(ifa),
+			LKST_ARG(0),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
diff -Naru linux-2.4.19/arch/ia64/mm/fault.c linux-2.4.19-lkst/arch/ia64/mm/fault.c
--- linux-2.4.19/arch/ia64/mm/fault.c	2003-04-14 15:04:51.000000000 -0400
+++ linux-2.4.19-lkst/arch/ia64/mm/fault.c	2003-04-14 15:07:20.000000000 -0400
@@ -16,6 +16,8 @@
 #include <asm/uaccess.h>
 #include <asm/hardirq.h>
 
+#include <linux/lkst.h>
+
 extern void die (char *, struct pt_regs *, long);
 
 /*
@@ -181,6 +183,10 @@
 	 * Oops. The kernel tried to access some bad page. We'll have to terminate things
 	 * with extreme prejudice.
 	 */
+	LKST_HOOK(LKST_ETYPE_OOPS_PGFAULT,
+		LKST_ARG(address), LKST_ARG(regs->cr_iip + ia64_psr(regs)->ri),
+		LKST_ARG(isr), LKST_ARG(0));
+
 	bust_spinlocks(1);
 
 	if (address < PAGE_SIZE)
@@ -206,3 +212,26 @@
 		do_exit(SIGKILL);
 	goto no_context;
 }
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||	\
+			defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) )
+void
+lkst_ia64_do_page_fault(u_long address, u_long isr, struct pt_regs *regs)
+{
+	LKST_HOOK(LKST_ETYPE_EXCEPT_PGFLT_ENTRY,
+			LKST_ARG(address),
+			LKST_ARG(isr),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	ia64_do_page_fault(address, isr, regs);
+
+	LKST_HOOK(LKST_ETYPE_EXCEPT_PGFLT_EXIT,
+			LKST_ARG(address),
+			LKST_ARG(isr),
+			LKST_ARG(regs->cr_ipsr),
+			LKST_ARG(regs->cr_iip));
+
+	return;
+}
+#endif /*  (..._KERNEL_STATE_TRACE || ..._KERNEL_STATE_TRACE_MODULE) */
diff -Naru linux-2.4.19/drivers/Makefile linux-2.4.19-lkst/drivers/Makefile
--- linux-2.4.19/drivers/Makefile	2003-04-14 15:03:29.000000000 -0400
+++ linux-2.4.19-lkst/drivers/Makefile	2003-04-14 15:05:48.000000000 -0400
@@ -8,7 +8,7 @@
 
 mod-subdirs :=	dio mtd sbus video macintosh usb input telephony sgi ide \
 		message/i2o message/fusion scsi md ieee1394 pnp isdn dump atm \
-		fc4 net/hamradio i2c acpi bluetooth
+		fc4 net/hamradio i2c acpi bluetooth lkst
 
 subdir-y :=	parport char block net sound misc media cdrom hotplug
 subdir-m :=	$(subdir-y)
@@ -48,4 +48,6 @@
 
 subdir-$(CONFIG_BLUEZ)		+= bluetooth
 
+subdir-$(CONFIG_DEBUG_KERNEL_STATE_TRACE) += lkst
+
 include $(TOPDIR)/Rules.make
diff -Naru linux-2.4.19/drivers/block/ll_rw_blk.c linux-2.4.19-lkst/drivers/block/ll_rw_blk.c
--- linux-2.4.19/drivers/block/ll_rw_blk.c	2003-04-14 15:03:40.000000000 -0400
+++ linux-2.4.19-lkst/drivers/block/ll_rw_blk.c	2003-04-14 15:06:08.000000000 -0400
@@ -31,6 +31,8 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 
+#include <linux/lkst.h>
+
 /*
  * MAC Floppy IWM hooks
  */
@@ -1230,6 +1232,12 @@
 		}
 
 		submit_bh(rw, bh);
+
+		LKST_HOOK(LKST_ETYPE_FS_DEVRW,
+			       LKST_ARGP(bh),
+			       LKST_ARG(rw),
+			       LKST_ARG(nr),
+			       LKST_ARG(0));
 	}
 	return;
 
diff -Naru linux-2.4.19/drivers/char/sysrq.c linux-2.4.19-lkst/drivers/char/sysrq.c
--- linux-2.4.19/drivers/char/sysrq.c	2003-04-14 15:03:41.000000000 -0400
+++ linux-2.4.19-lkst/drivers/char/sysrq.c	2003-04-14 15:06:10.000000000 -0400
@@ -397,7 +397,7 @@
 /* s */	&sysrq_sync_op,
 /* t */	&sysrq_showstate_op,
 /* u */	&sysrq_mountro_op,
-/* v */	NULL,
+/* v */	NULL, /* This will often be registered as 'lkstView' at init time */
 /* w */	NULL,
 /* x */	NULL,
 /* w */	NULL,
diff -Naru linux-2.4.19/drivers/lkst/Makefile linux-2.4.19-lkst/drivers/lkst/Makefile
--- linux-2.4.19/drivers/lkst/Makefile	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/drivers/lkst/Makefile	2003-04-14 15:06:54.000000000 -0400
@@ -0,0 +1,16 @@
+#
+# Makefile for the linux kernel.
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+# Note 2! The CFLAGS definitions are now in the main makefile...
+
+O_TARGET := lkstdrv.o
+
+export-objs = lkst.o
+
+obj-$(CONFIG_DEBUG_KERNEL_STATE_TRACE) = lkst.o
+
+include $(TOPDIR)/Rules.make
diff -Naru linux-2.4.19/drivers/lkst/lkst.c linux-2.4.19-lkst/drivers/lkst/lkst.c
--- linux-2.4.19/drivers/lkst/lkst.c	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/drivers/lkst/lkst.c	2003-04-14 15:06:54.000000000 -0400
@@ -0,0 +1,4055 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2003 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.Serizawa <serizawa@sdl.hitachi.co.jp>
+ * Updated by M.Hiramatsu <hiramatu@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/sysrq.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/lkst_private.h>
+#include <linux/stat.h>
+#include <linux/devfs_fs_kernel.h>
+#include <linux/spinlock.h>
+#include <linux/utsname.h>
+// for registering notifier 
+#include <linux/notifier.h>
+#include <linux/dump.h>
+
+// TODO: check architecture independency
+#include <asm/uaccess.h>
+#include <asm/atomic.h>
+
+/* Array of mnemonics of event types */
+#define LKST_ETYPE_DEF_MNEMONICS
+
+#include <linux/lkst_events.h>
+
+				/* Array of descriptions of event types */
+#define LKST_ETYPE_DEF_DESCRIPTIONS
+
+#include <linux/lkst_events.h>
+
+#define cpu_khz (lkst_get_cpu_khz())
+
+/* this is just for backporting */
+#ifndef EXPORT_SYMBOL_GPL
+#define EXPORT_SYMBOL_GPL(sym) EXPORT_SYMBOL(sym)
+#endif
+
+/* trace control functions */
+EXPORT_SYMBOL(lkst_trc_status);	/* get status */
+EXPORT_SYMBOL(lkst_trc_start);	/* set maskset to saved one.*/
+EXPORT_SYMBOL(lkst_trc_stop);	/* set maskset RNOTHING and save current.*/
+
+/* maskset control functions */
+EXPORT_SYMBOL(lkst_maskset_xchg);	/* set and return previous maskset id*/
+EXPORT_SYMBOL(lkst_maskset_read);	/* read a maskset */
+EXPORT_SYMBOL(lkst_maskset_write);	/* write/create a maskset */
+EXPORT_SYMBOL(lkst_maskset_delete);	/* delete a maskset */
+EXPORT_SYMBOL(lkst_maskset_list);	/* list all maskset *id*s */
+EXPORT_SYMBOL(lkst_maskset_get_id);	/* get an id of maskset from name */
+
+/* evhandler control functions */
+EXPORT_SYMBOL(lkst_evhandler_list);	/* list all event-handler *id*s */
+EXPORT_SYMBOL_GPL(lkst_evhandler_ctrl);		/* send a control message to a event-handler (GPL ONLY)*/
+EXPORT_SYMBOL_GPL(lkst_evhandler_register);	/* register a event-hander(GPL ONLY)*/
+EXPORT_SYMBOL_GPL(lkst_evhandler_unregister);	/* unregister a event-hander(GPL ONLY)*/
+EXPORT_SYMBOL_GPL(lkst_evhandler_get_id);	/* get a event-hander id from name (GPL ONLY)*/
+
+/* buffer control functions */
+EXPORT_SYMBOL(lkst_buffer_create);	/* create a buffer */
+EXPORT_SYMBOL(lkst_buffer_delete);	/* delete a buffer */
+EXPORT_SYMBOL(lkst_buffer_read);	/* read a buffer */
+EXPORT_SYMBOL(lkst_buffer_shift);	/* shift(jump to a buffer specified by 
+					 * next field of event buffer 
+					 * structure) current writing buffer */
+EXPORT_SYMBOL(lkst_buffer_jump);	/* jump current writing buffer to 
+					 * another one */
+
+
+/* evhandler primitive functions */
+
+/* get a event buffer that has specified id. */
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_select_buffer_id);
+
+/* get a event buffer that is currently writing. */
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_select_buffer);
+
+/* set reading process to ready to read.(and wake up at next time scheduling)*/
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_owner_wakeup);
+
+/* log event to current writing buffer. */
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_entry_log);
+
+/* log event to static event buffer. */
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_entry_log_static);
+
+/* exchange current maskset for specified maskset */
+EXPORT_SYMBOL_GPL(lkst_evhandlerprim_maskset_xchg);
+
+
+/* SysRq function */
+EXPORT_SYMBOL(lkst_buffer_dump_current_txt);
+
+
+/* internal control functions (Not use without enough understanding.)*/
+EXPORT_SYMBOL(lkst_event_type_mnemonics);
+EXPORT_SYMBOL(lkst_event_type_descriptions);
+EXPORT_SYMBOL(lkst_hook_init_module);
+EXPORT_SYMBOL(lkst_hook_reset_all);
+
+/* default event handler control function (do nothing)*/
+EXPORT_SYMBOL(lkst_evhandler_default_ctrl);
+
+
+/* embeded event handlers */
+/* default event handler that log event to current writing buffer. */
+EXPORT_SYMBOL(lkst_evhandler_default);
+/* an event handler that jump to a buffer whose id is specified next 
+ * field of current writing buffer. */
+EXPORT_SYMBOL(lkst_evhandler_buffer_shift);
+/* an event handler that jump to a buffer whose id is specified next 
+ * field of current writing buffer, and then, awake reading process.*/
+EXPORT_SYMBOL(lkst_evhandler_buffer_shift_wakeup);
+/* an event handler that log event to static event buffer.*/
+EXPORT_SYMBOL(lkst_evhandler_log_static);
+
+#if DEBUG
+EXPORT_SYMBOL(lkst_evhandler_exception); /* To avoid infinit-loop*/
+#endif /* DEBUG */
+
+/*old-style hook function */
+EXPORT_SYMBOL(lkst_entry_log);
+
+
+/* disable messages for debug
+#undef LKST_DEBUG_MESSAGE
+*/
+
+#ifdef LKST_DEBUG_MESSAGE
+#define LKST_DPRINTK(fmt, args...)  \
+	printk(KERN_ERR "LKST(%s): " fmt, __FUNCTION__, ## args)
+/*for debugging*/
+		/* Error code for lkst_evhandlerprim_maskset_xchg_inline() */
+#define LKST_MASKSET_XCHG_ERRNO_SUCCESS	(0)
+#define LKST_MASKSET_XCHG_ERRNO_WCID	(-1)
+#define LKST_MASKSET_XCHG_ERRNO_WCPT	(-2)
+#define LKST_MASKSET_XCHG_ERRNO_ECPT	(-3)
+#define LKST_MASKSET_XCHG_ERRNO_ENID	(-4)
+#define LKST_MASKSET_XCHG_ERRNO_ENPT	(-5)
+#define LKST_MASKSET_XCHG_ERRNO_ESTAT	(-6)
+#define LKST_MASKSET_XCHG_ERRNO_ELOCK	(-7)
+#else
+#define LKST_DPRINTK(fmt, args...)
+#define LKST_MASKSET_XCHG_ERRNO_SUCCESS	0
+#define LKST_MASKSET_XCHG_ERRNO_WCID	0
+#define LKST_MASKSET_XCHG_ERRNO_WCPT	0
+#define LKST_MASKSET_XCHG_ERRNO_ECPT	(-EBUSY )
+#define LKST_MASKSET_XCHG_ERRNO_ENID	(-EINVAL)
+#define LKST_MASKSET_XCHG_ERRNO_ENPT	(-EINVAL)
+#define LKST_MASKSET_XCHG_ERRNO_ESTAT	(-EBUSY )
+#define LKST_MASKSET_XCHG_ERRNO_ELOCK	(-EAGAIN)
+#endif
+
+
+#define LKST_NOT_INIT 0 // not initialized
+#define LKST_INIT_LEVEL_0 1 // stage 0 init
+#define LKST_INIT_LEVEL_1 2 // stage 1 init
+
+static int lkst_init_flag = LKST_NOT_INIT; // TODO: Don't use
+static size_t lkst_init_buffer_size = LKST_BUFFER_SIZE_DEFAULT;
+int lkst_init_maskset = LKST_MASKSET_ID_RDEFAULT;
+
+spinlock_t lkst_evhandler_lock = SPIN_LOCK_UNLOCKED;
+spinlock_t lkst_maskset_lock = SPIN_LOCK_UNLOCKED;
+
+/* definitions of special masksets. */
+/*
+ * maskset_rnothing (id: 0(LKST_MASKSET_ID_RNOTHING))
+ * a maskset to record no events.
+ */
+static const lkst_evhandler_id maskset_rnothing[] = {
+	[0 ... LKST_ETYPE_MAX] = LKST_EVHANDLER_ID_VOID
+	    /* caution: LKST_ETYPE_MAX is significant
+	     *   to decide the size of this maskset.
+	     */
+};
+
+/*
+ * maskset_rall (id: 1(LKST_MASKSET_ID_RALL))
+ * a maskset to record all events.
+ */
+static lkst_evhandler_id maskset_rall[] = {
+	[0 ... LKST_ETYPE_LKST_BUFF_OVFLOW - 1] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_LKST_BUFF_OVFLOW] = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_LKST_BUFF_OVFLOW + 1 ... LKST_ETYPE_MAX] = LKST_EVHANDLER_ID_DEFAULT
+	    /* caution: LKST_ETYPE_MAX is significant, ditto. */
+};
+
+/*
+ * maskset_rdefault (id: 2(LKST_MASKSET_ID_RDEFAULT))
+ * a maskset selected initially.
+ */
+static const lkst_evhandler_id maskset_rdefault[] = {
+	/* Default Maskset omits lock operation events */
+
+	[0 ... LKST_ETYPE_MEM_DO_NOPAGE-1 ] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_MEM_DO_NOPAGE ... LKST_ETYPE_NET_PKTSENDI-1 ] = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_NET_PKTSENDI] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_NET_PKTRECV]  = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_NET_PKTRECV+1 ... LKST_ETYPE_LK_SPINLOCK -1] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_LK_SPINLOCK ... LKST_ETYPE_O_PORTOUT] = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_O_PORTOUT + 1 ... LKST_ETYPE_TIMER_ADD - 1 ] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_TIMER_ADD ... LKST_ETYPE_LKST_INIT - 1 ] = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_LKST_INIT ... LKST_ETYPE_LKST_BUFF_OVFLOW - 1] = LKST_EVHANDLER_ID_DEFAULT,
+	[LKST_ETYPE_LKST_BUFF_OVFLOW] = LKST_EVHANDLER_ID_VOID,
+	[LKST_ETYPE_LKST_BUFF_OVFLOW + 1 ... LKST_ETYPE_MAX] = LKST_EVHANDLER_ID_DEFAULT
+	    /* caution: LKST_ETYPE_MAX is significant, ditto. */
+};
+
+/* file operators */
+static int lkst_open(struct inode *inode, struct file *filp);
+static int lkst_close(struct inode *inode, struct file *filp);
+static ssize_t lkst_read(struct file *filp, char *buf, 
+			 size_t count, loff_t *ppos);
+static int lkst_ioctl(struct inode *inode, struct file *filp,
+		      unsigned int request, unsigned long arg);
+
+/* LKST device file_operations */
+static struct file_operations lkst_fops = {
+	.ioctl=		lkst_ioctl,
+	.open=		lkst_open,
+	.read=		lkst_read,
+	.release=	lkst_close,
+};
+
+
+#ifdef CONFIG_MAGIC_SYSRQ
+static void sysrq_handle_lkst_dump_buffer(int key, struct pt_regs *pt_regs,
+					  struct kbd_struct *kbd,
+					  struct tty_struct *tty) 
+{
+	lkst_buffer_dump_current_txt();
+}
+
+static struct sysrq_key_op sysrq_lkst_dump_buffer_op = {
+	.handler=		sysrq_handle_lkst_dump_buffer,
+	.help_msg=		"lkstView",
+	.action_msg=		"Dump Buffer\n",
+};
+#endif /* CONFIG_MAGIC_SYSRQ */
+
+/* for devfs support */
+#ifdef CONFIG_DEVFS_FS
+static devfs_handle_t lkst_devfs_handle = NULL;
+#ifdef CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+static devfs_handle_t lkst_devfs_handle_cpu[LKST_CPU_MAX] = NULL;
+#endif /*CONFIG_DEBUG_LKST_DEVICE_PER_CPU*/
+#endif	
+
+/*kernel dump notify handler */
+#if defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)
+static int lkst_dump_notify_handler(struct notifier_block *self, 
+				    unsigned long stat,
+				    void *dev);
+
+static struct notifier_block dump_nb = {
+	.notifier_call = lkst_dump_notify_handler,
+	.next = NULL,
+	.priority = 0
+};
+#endif /*defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)*/
+
+
+//TODO: call lkst_evhandlerprim_entry_log_static
+#define LKST_DEBUG_LOG(ty, a1, a2, a3, a4)
+
+
+void lkst_entry_log(void *phookrec, int event_type, 
+		    lkst_arg_t arg1, lkst_arg_t arg2, 
+		    lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	lkst_evhandler_id evhandler_id;
+	volatile lkst_maskset *maskset;
+	lkst_evhandler_func evhandler;
+
+	if (!LKST_ETYPE_VERIFY(event_type))
+		return;
+
+	/*get the maskset lock*/
+	if (!spin_trylock(&lkst_maskset_lock)) return;
+
+	if (!LKST_POINTER_LOAD(lkst.current_masksetp, maskset)) {
+		LKST_DEBUG_LOG(event_type + 0x200, arg1,
+			       (unsigned int) (lkst.current_masksetp),
+			       (unsigned int) (lkst.current_masksetp_check),
+			       (unsigned int) 0);
+		spin_unlock(&lkst_maskset_lock);
+		return ;
+	}
+
+	evhandler_id = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset, event_type);
+
+	/*release the maskset lock*/
+	spin_unlock(&lkst_maskset_lock);
+
+	if (evhandler_id > LKST_EVHANDLER_ID_MAX)
+		return ;
+
+	/*get the evhandler lock*/
+	if (!spin_trylock(&lkst_evhandler_lock)) return;
+
+	if (!LKST_POINTER_LOAD
+	    (lkst.evhandler_table[evhandler_id].evhandler, evhandler)) {
+		LKST_DEBUG_LOG(event_type + 0x400, evhandler_id,
+			       (unsigned int) (evhandler),
+			       (unsigned int) (lkst.evhandler_table[evhandler_id].evhandler_check),
+			       (unsigned int) 0);
+	} else { 
+		/* Avoid infinate loop. */
+		if (evhandler != lkst_entry_log)
+			(*evhandler) (NULL, event_type, arg1, arg2, arg3, arg4);
+	}
+	/*release the evhandler lock*/
+	spin_unlock(&lkst_evhandler_lock);
+	
+	return;
+}
+
+/*********************************************************************
+ *  Kernel hook functions
+ *********************************************************************/
+
+
+/*
+ *
+ *  GKHI hook function
+ * These functions must be used with corresponding locks. 
+ */
+
+extern void lkst_trc_hook_init(void);
+extern void lkst_trc_hook_cleanup(void);
+
+/* Exchange of hook exit */
+static __inline__ int lkst_hook_exit_xchg(lkst_event_type etype, 
+					  lkst_evhandler_id newid,
+					  lkst_evhandler_id oldid)
+{
+	int ret = 0;
+	hook_rec_t* phookrec = lkst_hook_info_table[etype].phookrec;
+	lkst_evhandler_func new_evhandler;
+
+	if (phookrec == NULL) return ERROR_HOOK_NOT_FOUND;
+
+	/* unregister old exit (if exist)*/
+	if (oldid <= LKST_EVHANDLER_ID_MAX) {
+		hook_exit_deregister(phookrec);
+		memset(phookrec, 0, sizeof(hook_rec_t));
+	}
+	if (newid == LKST_EVHANDLER_ID_VOID) return 0;
+
+	/* register new exit (if specified)*/
+	if (! LKST_POINTER_LOAD(lkst.evhandler_table[newid].evhandler, 
+				new_evhandler) ){
+		return ERROR_HOOK_NOT_FOUND;
+	}
+	
+	phookrec->hook_exit = new_evhandler;
+	/* phookrec->hook_exit_name = lkst.evhandler_table[newid].name; */
+	phookrec->hook_link = NULL;
+	ret = _hook_exit_register(lkst_hook_info_table[etype].hook_id,
+				  phookrec);
+	if ( ret == NO_ERROR ) {
+		ret = hook_exit_arm(phookrec);
+	}
+	return ret;
+}
+
+
+/* 
+ * Exchange maskset
+ *  Called from lkst_trc_init_stage0, lkst_evhandlerprim_maskset_xchg_inline,
+ *  lkst_trc_start_core and lkst_trc_stop_core.
+ */
+static int lkst_hook_maskset_xchg(lkst_maskset_id mask_id_new,
+				  lkst_maskset_id mask_id_old)
+{
+	int i;
+	lkst_maskset *maskset_old;
+	lkst_maskset *maskset_new;
+	lkst_evhandler_id evh_id_old;
+	lkst_evhandler_id evh_id_new;
+
+	if (mask_id_old > LKST_MASKSET_ID_MAX) {
+		mask_id_old = LKST_MASKSET_ID_RNOTHING;
+	}
+	if (mask_id_new > LKST_MASKSET_ID_MAX) {
+		mask_id_new = LKST_MASKSET_ID_RDEFAULT;
+	}
+
+	if(mask_id_old == mask_id_new) return 0;
+
+	if ( ! LKST_POINTER_LOAD(lkst.maskset_table[mask_id_old].masksetp,
+				 maskset_old) || 
+	     ! LKST_POINTER_LOAD(lkst.maskset_table[mask_id_new].masksetp,
+				 maskset_new) ) return -EINVAL;
+
+	for (i = 0; i < LKST_MASKSET_TABLE_LEN_MAX; i++) {
+		int ret;
+		if (!LKST_HOOK_EXIST(i)) continue;
+		evh_id_old = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset_old, i);
+		evh_id_new = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset_new, i);
+
+		if(evh_id_old != evh_id_new) {
+			ret = lkst_hook_exit_xchg(i, evh_id_new, evh_id_old);
+			if ( ret != 0 ) {
+				printk(KERN_ERR "LKST error(hook_maskset_xchg):"
+				       "lkst_hook_exit_xchg failed: %d\n", ret);
+				printk(KERN_ERR "Etype: %d, New handler ID: %d, Old Handler ID: %d\n",
+				       i, evh_id_new, evh_id_old);
+				return -EINVAL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+/* 
+ * Update hook exit
+ *  Called from lkst_evhandler_register/lkst_evhandler_unregister
+ * TODO: check error correctly
+ */
+static __inline__ int lkst_hook_exit_update(lkst_evhandler_id evh_id)
+{
+	lkst_evhandler_id evhandler_id;
+	lkst_maskset *maskset = NULL;
+	int i, ret = 0;
+
+	if ( evh_id > LKST_EVHANDLER_ID_MAX ) return -EINVAL;
+	if ( ! LKST_POINTER_LOAD(lkst.current_masksetp, maskset) )
+		return -EBUSY;/*Cause, current_masksetp is never set NULL*/
+
+	ret = 0;
+	for(i=0; i<LKST_MASKSET_TABLE_LEN_MAX; i++){
+		evhandler_id = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset, i);
+		if(evhandler_id == evh_id){
+			if ( lkst_hook_exit_xchg(i, evh_id, 0) ) {
+				printk(KERN_ERR "LKST error(hook_exit_update):"
+				       " hook_exit_update(%d, %d, 0) failed\n",
+				       i , evh_id);
+				ret = -EINVAL;
+			}
+		}
+	}
+
+	return ret;
+}
+
+/* 
+ * Initialize hook in the modules
+ */
+int lkst_hook_init_module(lkst_event_type etype)
+{
+	lkst_evhandler_id evhandler_id;
+	lkst_maskset *maskset = NULL;
+
+	if ((etype > LKST_ETYPE_MAX) || (etype < 0)) {
+		printk(KERN_ERR "LKST error(lkst_hook_init_module): invalid event id %u\n", etype);
+		return -EINVAL;
+	}
+
+	if ( ! LKST_POINTER_LOAD(lkst.current_masksetp, maskset) ) {
+		printk(KERN_ERR "LKST error(lkst_hook_init_module): currnet maskset temprary busy, or broken.\n");
+		return -EBUSY;
+	}
+
+	evhandler_id = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset, etype);
+	lkst_hook_exit_xchg(etype, evhandler_id, LKST_EVHANDLER_ID_MAX + 1);
+	return 0;
+}
+
+/* 
+ * Reload all hooks
+ */
+int lkst_hook_reset_all(void)
+{
+	while ( lkst_hook_maskset_xchg(LKST_MASKSET_ID_RNOTHING, 
+				       LKST_MASKSET_ID_RALL) );
+	return lkst_hook_maskset_xchg(lkst.current_maskset_id, 
+				      LKST_MASKSET_ID_RNOTHING);
+}
+
+/*********************************************************************
+ * evhandler primitive functions
+ *********************************************************************/
+
+
+
+/*
+ *  The buffer read queue mechanism :
+ * A buffer writing on is in a queue tail except for a spacial case that the 
+ * buffer is read and not shifted-in, while reading it. When the reading 
+ * process begin to read a buffer, the buffer should be dequeued. And 
+ * read_buf field of lkst_current.owner point it. When the writing process 
+ * begin to write (shift-in) a buffer, the buffer should be enqueued. 
+ * This mechanism is adopted instead of the old wcnt/rcnt mechanism.
+ * IOW, this is just a kind of LRU.(simple implementation:-) )
+ */
+
+
+/* this function is designed as fail-safe.
+  if you give dequeued buffer, rqueue will be cleanuped.*/
+static __inline__ \
+int lkst_buffer_dequeue_inline(struct lkst_event_buffer * buffer) {
+	/* ! Please check buffer != NULL !
+	   ! and check buffer is queued !*/
+	struct lkst_event_buffer *tmp;
+
+	if ( buffer->rq_next == LKST_BUFFER_ID_VOID ) {  /* buffer is tail */
+		lkst_current.rq_tail = buffer->rq_prev;
+	} else {  /* next != NULL */
+		if ( ! LKST_BUFFER_LOAD(buffer->rq_next, tmp)) 
+			return -EBUSY; //TODO
+		tmp->rq_prev = buffer->rq_prev;
+	}
+
+	if ( buffer->rq_prev == LKST_BUFFER_ID_VOID ) { /* buffer is head */
+		lkst_current.rq_head = buffer->rq_next;
+	} else { /* prev != NULL */
+		if ( ! LKST_BUFFER_LOAD(buffer->rq_prev, tmp)) 
+			LKST_ENCOUNTER_A_BUG; //TODO
+		tmp->rq_next = buffer->rq_next;
+	}
+	buffer->rq_next = buffer->rq_prev = LKST_BUFFER_ID_VOID;
+	return 0;
+}
+
+/*
+ * This enqueue a buffer in read queue.
+ */
+static __inline__ \
+int lkst_buffer_enqueue_inline(struct lkst_event_buffer * buffer) {
+	/* ! Please check buffer != NULL ! 
+	   ! and check buffer is dequeued !*/
+	if ( lkst_current.rq_tail != buffer->id ) { 
+		if ( buffer->rq_next == LKST_BUFFER_ID_VOID) {
+			if ( lkst_current.rq_tail == LKST_BUFFER_ID_VOID ) { 
+				/* then rqueue is empty.*/
+				lkst_current.rq_tail = buffer->id;
+				lkst_current.rq_head = buffer->id;
+			} else {
+				struct lkst_event_buffer * tail;
+				if ( ! LKST_BUFFER_LOAD(lkst_current.rq_tail,
+							tail) ) return -EBUSY;
+				tail->rq_next = buffer->id;
+				buffer->rq_prev = lkst_current.rq_tail;
+				lkst_current.rq_tail = buffer->id;
+			}
+		} else {
+			struct lkst_event_buffer *tmp, *tmp2, *tmp3;
+			/*dequeue*/
+			if (!LKST_BUFFER_LOAD(buffer->rq_next, tmp) ||
+			    !LKST_BUFFER_LOAD(lkst_current.rq_tail, tmp3)) /* if tail is null, buffer is dequeued. No, buffer is queued.*/
+				return -EBUSY;
+			if ( buffer->rq_prev != LKST_BUFFER_ID_VOID ) {
+				if (!LKST_BUFFER_LOAD(buffer->rq_prev, tmp2))
+					return -EBUSY;
+				tmp2->rq_next = buffer->rq_next;
+			} else {
+				lkst_current.rq_head = buffer->rq_next;
+			}
+			tmp->rq_prev = buffer->rq_prev;
+			/*enqueue*/
+			tmp3->rq_next = buffer->id;
+			buffer->rq_prev = lkst_current.rq_tail;
+			lkst_current.rq_tail = buffer->id;
+			buffer->rq_next = LKST_BUFFER_ID_VOID;
+		}
+	}
+	return 0;
+}
+
+/*
+ * lkst_buffer_jump_core:
+ * Jump to specified buffer from current buffer.
+ */
+static __inline__ int lkst_buffer_jump_core(lkst_buffer_id next) {
+	struct lkst_event_buffer *nxtp, *curp;
+	unsigned long flags;
+	register int ret;
+
+	local_irq_save(flags);
+	
+	if (next == lkst_current.write_buf ||
+	    next == LKST_BUFFER_ID_VOID ||
+	    !LKST_BUFFER_LOAD(next, nxtp)) {
+		/* Either next buffer does not exist, or same as current */
+		ret = -EINVAL;
+		goto endof_irq_saved_region;
+	}
+	if (!LKST_CURRENT_BUFFER_LOAD(curp)){
+		ret = -EBUSY;
+		goto endof_irq_saved_region;
+	}
+
+	/* LKST internal event */
+	LKST_HOOK_INLINE(LKST_ETYPE_LKST_BUFF_SHIFT,
+			 LKST_ARG(lkst_current.write_buf),
+			 LKST_ARG(next),
+			 LKST_ARGP(curp), 
+			 LKST_ARGP(nxtp));
+
+	if ( (ret = lkst_buffer_enqueue_inline(nxtp) ) == 0) {
+		/* success to enqueue, then initialize */
+		nxtp->write_offset = nxtp->baseid - LKST_BUFFER_INIT_POS;
+		lkst_current.write_buf = next;
+	}
+ endof_irq_saved_region:
+	local_irq_restore(flags);
+	return ret;
+}
+
+/*
+ * lkst_buffer_shift_core:
+ * Jump to next buffer from current buffer.
+ */
+static __inline__ int lkst_buffer_shift_core(void) {
+	struct lkst_event_buffer * tmp;
+	if ( ! LKST_CURRENT_BUFFER_LOAD(tmp) ) return -EBUSY;
+	return lkst_buffer_jump_core(tmp->next);
+}
+
+/*
+ * subfunctions for reading buffers
+ */
+
+/*
+ * fill header of the log buffer.
+ * that read from global header.
+ */
+static __inline__ void \
+lkst_log_header_read_inline(struct lkst_log_buffer * lbuffer) {
+	/* get buffer time stamp */
+	lbuffer->tsc = lkst.tsc;
+	lbuffer->xtime = lkst.xtime;
+	lbuffer->cpu_freq = lkst.cpu_freq;
+	lbuffer->buf_ver = lkst.buf_ver;
+	strncpy(lbuffer->arch, lkst.arch, LKST_ARCH_NAME_LEN);
+	lbuffer->endian_big = lkst.endian_big;
+}
+
+/*
+ * get the next buffer from read queue and dequeue current buffer(if the 
+ * next buffer differ from current)
+ */
+
+static __inline__ struct lkst_event_buffer * \
+lkst_buffer_get_next_readable(int overwritten ) {
+	struct lkst_event_buffer *buffer;
+	unsigned long flags;
+	local_irq_save(flags);
+
+	if ( lkst_current.rq_head != LKST_BUFFER_ID_VOID ) {
+		/* then dequeue new buffer */
+		if ( LKST_BUFFER_LOAD(lkst_current.rq_head, buffer) ) {
+			if ( lkst_buffer_dequeue_inline(buffer) == 0 ) {
+				goto  success;
+			}
+		}
+	} else if ( overwritten ) {
+		/* then load same buffer */
+		if ( lkst_current.owner.read_buf != LKST_BUFFER_ID_VOID &&
+		     LKST_BUFFER_LOAD(lkst_current.owner.read_buf, buffer) ) {
+			goto  success;
+		}
+	}
+	local_irq_restore(flags);
+	return NULL;
+ success:
+	lkst_current.owner.read_pos = LKST_BUFFER_INIT_POS - 1;
+	lkst_current.owner.read_baseid = 
+		LKST_BUFFER_BODY(buffer)[LKST_BUFFER_INIT_POS].log_recid - 1;
+	lkst_current.owner.read_buf = buffer->id;
+	local_irq_restore(flags);
+	return buffer;
+}
+
+/* 
+ * read entrys from a buffer less than log_num, until breaking 
+ * baseid incrementation 
+ */
+static int __inline__ \
+lkst_buffer_entry_read_core(struct lkst_log_record * log, int log_num,
+			    struct lkst_event_record * body, int size, 
+			    struct lkst_buffer_owner * owner,
+			    int * overwritten) { 
+	int read_pos;
+	int count, baseid, bufferid;
+	struct task_struct *task = NULL;
+	struct lkst_event_record *entry;
+	uid_t uid = 0;
+	gid_t gid = 0;
+	pid_t pid = PID_MAX + 1;
+	pid_t pgrp = 0;
+
+	*overwritten = 0;
+	read_pos = owner->read_pos;	/*CARE: read_pos might indicate negative value.*/
+	baseid = owner->read_baseid;
+	bufferid = owner->read_buf;
+	for ( count = 0; count < log_num; count++, log++) {
+		read_pos++; baseid++;
+		entry = &body[(unsigned)read_pos%size]; //TODO?
+		log->posix.log_pid = entry->log_pid;
+		log->posix.log_time.tv_sec = (time_t) ((entry->log_time) >> 32);
+		log->posix.log_time.tv_nsec = (unsigned long) entry->log_time;
+		log->posix.log_thread = -1;		// TODO: write after
+		log->posix.log_event_type = entry->log_event_type;
+		log->log_arg1 = entry->log_arg1;
+		log->log_arg2 = entry->log_arg2;
+		log->log_arg3 = entry->log_arg3;
+		log->log_arg4 = entry->log_arg4;
+		if ( entry->log_recid != baseid ) { 
+			baseid--; 
+			read_pos--;
+			if (body[(unsigned)read_pos%size].log_recid != baseid)
+				*overwritten = 1;
+			break;
+		}
+		log->posix.log_recid = LKST_BUFFER_RECID(bufferid, baseid);
+		read_pos = (unsigned)read_pos%size; //update read position
+		
+		/* Is the current (logged) pid same as the last?*/
+		if (pid != log->posix.log_pid) {
+			/*update uid, gid and pgrp.*/
+			pid = log->posix.log_pid;
+			read_lock(&tasklist_lock);
+			task = find_task_by_pid(pid);
+			if (task == NULL) {
+				/* write dummy value if task_struct was already deleted */
+				uid = -1;	// TODO: write after
+				gid = -1;	// TODO: write after
+				pgrp = -1;	// TODO: write after
+			} else {
+				uid = task->uid;
+				gid = task->gid;
+				pgrp = task->pgrp;
+			}
+			read_unlock(&tasklist_lock);
+		}
+		log->posix.log_magic = LKST_LOG_MAGIC_NUM;
+		log->posix.log_size = sizeof(lkst_arg_t) * 4;
+		log->posix.log_format = PXLOG_BINARY;
+		log->posix.log_facility = LOG_KERN;
+		log->posix.log_severity = LOG_DEBUG;
+		log->posix.log_uid = uid;
+		log->posix.log_gid = gid;
+		log->posix.log_pgrp = pgrp;
+		log->posix.log_flags = 0;
+		log->posix.log_processor = (posix_log_procid_t)(entry->processor);
+	}
+	owner->read_pos = read_pos;
+	owner->read_baseid = baseid;
+	return count;
+}
+
+/*
+ * function lkst_buffer_read_all_to_user_core
+ * Read from the buffers.
+ * This must be called from user space.
+ * 
+ *  Arguments
+ *    logbuffer:	specify user-space buffer.
+ *    count:		number of read entries, described as entry counts. not bytes.
+ *
+ *  returns
+ *    result read size:	the size of entries that was read.(counts)
+ *    -EAGAIN:		read queue is empty. please read again after a minuts.
+ *    -ENOMEM:		failed to allocate temporary buffer.
+ *    -EBUSY:		buffer is currently busy.(may be or there is a bug)
+ *  
+ */
+static __inline__ \
+int lkst_buffer_read_all_to_user_core(struct lkst_log_record * logbuffer,
+				      int count)
+{
+	struct lkst_event_buffer * buffer;
+	struct lkst_log_record * tmp_buf; //TODO: not vmalloc
+	int log_pos, read_cnt, log_num, overwritten = 0;
+
+	/* OK, this is *PRIVATE* function, save pointless argument check. */
+
+	/* allocate temprary buffer */
+	tmp_buf = (struct lkst_log_record *) vmalloc(LKST_TEMP_BUFFER_BYTE);
+	if ( tmp_buf == NULL ) return -ENOMEM;
+	log_num = LKST_TEMP_BUFFER_COUNT;
+	log_pos = 0;
+
+	/* get the oldest buffer*/
+	if ( lkst_current.owner.read_buf != LKST_BUFFER_ID_VOID ) {
+		if ( !LKST_BUFFER_LOAD(lkst_current.owner.read_buf, buffer)) {
+			log_pos = -EBUSY;
+			goto endof_temp_alloc_region;
+		}
+	} else {
+		/* first time, or the buffer before read is deleted */
+		if (! (buffer = lkst_buffer_get_next_readable(0))) {
+			log_pos = -EAGAIN;
+			goto endof_temp_alloc_region;
+		}
+	}
+	/* header is needless to read */
+	/* reading loop */
+	do {
+		if ( (count - log_pos) < log_num )
+			log_num = (count - log_pos);
+
+		read_cnt = lkst_buffer_entry_read_core(tmp_buf, log_num,
+						       LKST_BUFFER_BODY(buffer), 
+						       buffer->size, 
+						       &lkst_current.owner,
+						       &overwritten);
+		if ( read_cnt < log_num ) {	/* end of this buffer */
+			buffer = lkst_buffer_get_next_readable(overwritten);
+		}
+		if ( read_cnt > 0 ) {
+			/* temp buffer copy to user space */
+			if ( copy_to_user(
+				     &logbuffer[log_pos], tmp_buf,
+				     read_cnt*sizeof(struct lkst_log_record))){
+				printk(KERN_ERR "Failed to copy to user space:"
+				       "address %p, size " LKST_FMT_SZT "\n",
+				       &logbuffer[log_pos], 
+				       (size_t)read_cnt*sizeof(
+					       struct lkst_log_record));
+				break;//TODO : return correct error code.
+			}
+			log_pos += read_cnt;
+		}
+	} while ( buffer != NULL && log_num > 0 );
+
+ endof_temp_alloc_region:
+	vfree(tmp_buf);
+	return log_pos;
+}
+
+/*
+ * function lkst_buffer_read_one_to_user_core
+ * Read from specified buffer.
+ * This must be called from user space.
+ * 
+ *  Arguments
+ *    id:		If specify LKST_BUFFER_ID_VOID, then read static-shared
+ *                      buffer, otherwise read specified buffer.
+ *    logbuffer:	specify user-space buffer.
+ *    count:		number of read *entries*, described as entry counts. 
+ *          		Not bytes.
+ *
+ *  returns
+ *    result read size:	the size of entries that was read.(counts)
+ *    -EINVAL:		specified buffer can not use.
+ *    -ENOMEM:		failed to allocate temporary buffer.
+ *  
+ */
+static __inline__ \
+int lkst_buffer_read_one_to_user_core(lkst_buffer_id id, 
+				      struct lkst_log_record * logbuffer,
+				      int count)
+{
+	struct lkst_buffer_owner owner;
+	struct lkst_log_record * tmp_buf;
+	int log_pos, read_cnt, log_num, overwritten=0;
+	struct lkst_event_record *body;
+	int size;
+
+	/* allocate temprary buffer */
+	tmp_buf = (struct lkst_log_record *) vmalloc(LKST_TEMP_BUFFER_BYTE);
+	if ( tmp_buf == NULL ) return -ENOMEM;
+	log_num = LKST_TEMP_BUFFER_COUNT;
+	log_pos = 0;
+
+	/* get buffer body and size*/
+	if ( id == LKST_BUFFER_ID_VOID ) { // static shared buffer
+		unsigned int start_recid;
+		start_recid = (unsigned)(atomic_read(&lkst.static_buffer.recid) + 2);
+		if ( start_recid < LKST_STATIC_BUFFER_COUNT )
+			start_recid = 0;
+		else 
+			start_recid %= LKST_STATIC_BUFFER_COUNT;
+		body = LKST_STATIC_BUFFER_BODY();
+		size = LKST_STATIC_BUFFER_COUNT;
+		owner.read_pos = start_recid - 1;
+		owner.read_buf = 0;
+		owner.read_baseid = body[start_recid].log_recid - 1;
+	} else { /* get specified buffer */  // percpu buffer
+		struct lkst_event_buffer * buffer;
+		if (! LKST_BUFFER_LOAD(id, buffer) ) {
+			vfree(tmp_buf);
+			return -EINVAL;
+		}
+		body = LKST_BUFFER_BODY(buffer);
+		size = buffer->size;
+		owner.read_pos = LKST_BUFFER_INIT_POS - 1;
+		owner.read_buf = id;
+		owner.read_baseid = body[LKST_BUFFER_INIT_POS].log_recid - 1;
+	}
+	
+	/* reading loop */
+	do {
+		if ( (count - log_pos) < log_num )
+			log_num = (count - log_pos);
+
+		read_cnt = lkst_buffer_entry_read_core(tmp_buf, log_num, 
+						       body, size,
+						       &owner,
+						       &overwritten);
+		if ( read_cnt > 0 ) {
+			/* temp buffer copy to user space */
+			if ( copy_to_user(
+				     &logbuffer[log_pos], tmp_buf,
+				     read_cnt*sizeof(struct lkst_log_record))){
+				printk(KERN_ERR "Failed to copy to user space:"
+				       "address %p, size " LKST_FMT_SZT "\n",
+				       &logbuffer[log_pos], 
+				       (size_t)read_cnt*sizeof(
+					       struct lkst_log_record));
+				break;//TODO : return correct error code.
+			}
+			log_pos += read_cnt;
+		}
+	} while ( log_num > 0 && read_cnt == log_num);
+
+	vfree(tmp_buf);
+	return log_pos;
+}
+
+/*
+ * function lkst_buffer_read_core
+ * Read from the specified buffer.
+ * This is called from lkst_buffer_read
+ * 
+ *  Arguments
+ *    lbuffer:		the logging buffer.
+ *
+ *  returns
+ *    result read size:	the size of entries.(counts)
+ *    -EINVAL:		spacified buffer is not exist.
+ *  
+ *  !NOTE!: This must be called after CPU migration. 
+ * 
+ */
+static __inline__ \
+int lkst_buffer_read_core(struct lkst_log_buffer * lbuffer)
+{
+	struct lkst_event_buffer * buffer;
+	struct lkst_buffer_owner owner;
+	int ow;
+
+	if( lbuffer->id == LKST_BUFFER_ID_VOID || 
+	    ! LKST_BUFFER_LOAD(lbuffer->id, buffer) ) {
+		return -EINVAL;
+	}
+	lbuffer->cpu = smp_processor_id();
+	owner.read_pos = LKST_BUFFER_INIT_POS;
+	owner.read_buf = lbuffer->id;
+	owner.read_baseid = 
+		LKST_BUFFER_BODY(buffer)[LKST_BUFFER_INIT_POS].log_recid;
+	lkst_log_header_read_inline(lbuffer);
+	return lbuffer->result_read_size = 
+		lkst_buffer_entry_read_core(lbuffer->buffer, 
+					    lbuffer->read_size,
+					    LKST_BUFFER_BODY(buffer),
+					    buffer->size,
+					    &owner, &ow);
+}
+
+/*
+ * Event buffer selecting functions
+ */
+struct lkst_event_buffer * \
+lkst_evhandlerprim_select_buffer_id(lkst_buffer_id id)
+{
+	struct lkst_event_buffer * buffer;
+	if ( id != LKST_BUFFER_ID_VOID &&
+	     LKST_BUFFER_LOAD(id, buffer) )
+		return buffer;
+	else 
+		return NULL;
+}
+
+struct lkst_event_buffer * \
+lkst_evhandlerprim_select_buffer(void)
+{
+	struct lkst_event_buffer * buffer;
+	if ( LKST_CURRENT_BUFFER_LOAD(buffer) )
+		return buffer;
+	else 
+		return NULL;
+}
+
+/*
+ * Logging subfunctions are followings.
+ */
+
+/*
+ * function lkst_evhandlerprim_owner_wakeup_inline
+ * A primitive part of an Event-handler. This awake a owner process which
+ * is waiting to read a specified buffer list.
+ *
+ *  Arguments
+ *    NONE
+ *
+ *  returns
+ *    NONE
+ *
+ */
+static __inline__ void lkst_evhandlerprim_owner_wakeup_inline(void)
+{
+	lkst_current.owner.ready = 1; /* ready to read */
+}
+
+void lkst_evhandlerprim_owner_wakeup(void)
+{
+	lkst_evhandlerprim_owner_wakeup_inline();
+}
+
+/*
+ * function lkst_evhandlerprim_entry_log_inline
+ * A primitive part of an Event-handler. This function write specified record
+ * to specified entry.
+ * 
+ *  Caution: This function does not verify value of event_entry_p.
+ * TODO: remove cli ...
+ * Finally, I had chosen safety rather then speed.
+ * But, I would provide no-cli handler by addon-module.
+ * 
+ *  Arguments
+ *    event_type {IN}:	corresponding event type.
+ *    arg1-4 {IN}:	arguments acquired at a trace point
+ *
+ *  returns
+ *    NONE
+ * 
+ */
+static __inline__ void \
+lkst_evhandlerprim_entry_log_inline(int event_type,
+				    lkst_arg_t arg1, lkst_arg_t arg2,
+				    lkst_arg_t arg3, lkst_arg_t arg4) 
+{
+	struct lkst_event_buffer *buffer;
+	int pos, flags;
+	int baseid;
+	if (! LKST_CURRENT_BUFFER_LOAD(buffer)) return ;
+
+	local_irq_save(flags);/* local irq disabling for atomicity */
+	
+	/* get a entry position */ {
+		baseid = buffer->baseid++;
+	}
+	/* adjust the entry position */
+	if ( (pos = baseid - buffer->write_offset) >= buffer->size ) {
+		pos %= buffer->size;
+	}
+	/* logging */ {
+		register struct lkst_event_record * event_entry_p = 
+			&(LKST_BUFFER_BODY(buffer)[pos]);
+		event_entry_p->log_recid = baseid;
+		event_entry_p->log_time = lkst_evhandlerprim_mc();
+		event_entry_p->log_event_type = event_type;
+		event_entry_p->log_pid = current->pid; /* current pid */ ;
+		event_entry_p->log_arg1 = arg1;
+		event_entry_p->log_arg2 = arg2;
+		event_entry_p->log_arg3 = arg3;
+		event_entry_p->log_arg4 = arg4;
+	}
+	/* Check buffer wrapping. */
+	if ( pos == 0 ) {
+		/* notify current writing buffer overflowed, 
+		 * occurs LKST_ETYPE_LKST_BUFF_OVFLOW event, and 
+		 * set reading process to ready to read. */
+		buffer->write_offset += buffer->size;
+		/* Wrapped. */
+		/* Process buffer-over-flow event. */
+		LKST_HOOK_INLINE(LKST_ETYPE_LKST_BUFF_OVFLOW,
+				 LKST_ARG(smp_processor_id()),
+				 LKST_ARG(buffer->next),
+				 LKST_ARG(event_type),
+				 LKST_ARGP(buffer));
+		/* owner wakeup */
+		lkst_evhandlerprim_owner_wakeup_inline();
+	}
+	local_irq_restore(flags);
+}
+
+
+/*
+ * function lkst_evhandlerprim_entry_log_inline
+ * A primitive part of an Event-handler. This write an event log to 
+ * a currently selected buffer correspond to a cpu on which the event
+ * has occurred.
+ * 
+ *  Arguments
+ *    event_type {IN}:	corresponding event type.
+ *    arg1-4 {IN}:	arguments acquired at a trace point
+ *
+ *  returns
+ *    NONE
+ */
+void lkst_evhandlerprim_entry_log(int event_type,
+				  lkst_arg_t arg1, lkst_arg_t arg2,
+				  lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	lkst_evhandlerprim_entry_log_inline(event_type,
+					    arg1, arg2, arg3, arg4);
+}
+  
+  
+/*
+ * function lkst_evhandlerprim_entry_log_sbuf_inline
+ * A primitive part of an Event-handler. This write an event log to 
+ * a shared static buffer on which the event has occurred.
+ * 
+ *  Arguments
+ *    event_type {IN}:	corresponding event type.
+ *    arg1-4 {IN}:	arguments acquired at a trace point
+ *
+ *  returns
+ *    NONE
+ */
+static __inline__ void \
+lkst_evhandlerprim_entry_log_static_inline(int event_type,
+					   lkst_arg_t arg1, lkst_arg_t arg2,
+					   lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	struct lkst_event_record *event_entry_p;
+	__volatile__ int recid;
+	recid = atomic_read_and_add(1, &lkst.static_buffer.recid);
+	event_entry_p = &LKST_STATIC_BUFFER_BODY()[
+		((unsigned)recid & LKST_STATIC_BUFFER_MASK)];
+
+	/* logging */
+	event_entry_p->log_recid = recid;
+	event_entry_p->processor = smp_processor_id(); /*current processor*/
+	event_entry_p->log_time = lkst_evhandlerprim_mc(); /* current time */
+	event_entry_p->log_event_type = event_type;
+	event_entry_p->log_pid = current->pid; /* current pid */ ;
+	event_entry_p->log_arg1 = arg1;
+	event_entry_p->log_arg2 = arg2;
+	event_entry_p->log_arg3 = arg3;
+	event_entry_p->log_arg4 = arg4;
+}
+
+
+void lkst_evhandlerprim_entry_log_static(int event_type,
+					 lkst_arg_t arg1, lkst_arg_t arg2,
+					 lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	lkst_evhandlerprim_entry_log_static_inline(event_type,
+						   arg1, arg2, arg3, arg4);
+}
+
+
+/*
+ * function lkst_evhandlerprim_maskset_xchg_inline
+ * A primitive part of an Event-handler. This primitive
+ * change current selected maskset to a specified id.
+ * This primitive is for LKST internal use.
+ * 
+ *  Arguments
+ *    id {IN}:	An id of a maskset to be selected next.
+ *
+ *  returns
+ *    ret: 	error code (private).
+ */
+
+static __inline__ int
+lkst_evhandlerprim_maskset_xchg_inline(lkst_maskset_id * id)
+{
+	int	ret = LKST_MASKSET_XCHG_ERRNO_SUCCESS;
+	lkst_maskset_id old_id = lkst.current_maskset_id, new_id = *id;
+	volatile lkst_maskset *old_maskset = NULL, *new_maskset = NULL;
+
+	if (new_id > LKST_MASKSET_ID_MAX) {
+		/* Verify new maskset id. */
+		return LKST_MASKSET_XCHG_ERRNO_ENID;
+	}
+	/* if we can't get maskset lock, return an error. */
+	if (!spin_trylock(&lkst_maskset_lock) ) {
+		return LKST_MASKSET_XCHG_ERRNO_ELOCK;
+	}
+
+ /*start of locked region */
+	/* if new maskset has not been initialized, return as error. */
+	if (!LKST_POINTER_LOAD(lkst.maskset_table[new_id].masksetp, 
+			       new_maskset)) {
+		ret = LKST_MASKSET_XCHG_ERRNO_ENPT;
+		goto  endof_atomic_region;
+	}
+
+	/* Load current maskset pointer. */
+	if ( LKST_POINTER_LOAD(lkst.current_masksetp, old_maskset)) {
+		/* Verify old maskset id. */
+		if (old_maskset != lkst.maskset_table[old_id].masksetp) {
+			ret = LKST_MASKSET_XCHG_ERRNO_WCPT;
+			old_id = LKST_MASKSET_ID_RDEFAULT;
+		} else if (old_id > LKST_MASKSET_ID_MAX) {
+			ret = LKST_MASKSET_XCHG_ERRNO_WCID;
+			old_id = LKST_MASKSET_ID_RDEFAULT;
+		}
+	} else {
+		/*if current maskset == NULL*/
+		ret = LKST_MASKSET_XCHG_ERRNO_WCPT;
+		old_id = LKST_MASKSET_ID_RNOTHING;
+	}
+
+	/* if old maskset does not exist, return as error. */
+	if ( !LKST_POINTER_LOAD(lkst.maskset_table[old_id].masksetp,
+				old_maskset) ) {
+		ret = LKST_MASKSET_XCHG_ERRNO_ECPT;
+		goto  endof_atomic_region;
+	}
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_MSET_XCHG,
+		       LKST_ARG(old_id), LKST_ARG(new_id),
+		       LKST_ARGP(old_maskset), LKST_ARGP(new_maskset));
+
+	LKST_MASKSET_SET_CURRENT(new_id);
+
+	*id = old_id;
+
+	lkst_hook_maskset_xchg(new_id, old_id);
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_MSET_XCHG,
+		       LKST_ARG(old_id), LKST_ARG(new_id),
+		       LKST_ARGP(old_maskset), LKST_ARGP(new_maskset));
+
+ endof_atomic_region:
+	spin_unlock(&lkst_maskset_lock);
+	return ret;
+}
+
+
+int lkst_evhandlerprim_maskset_xchg(lkst_maskset_id * id)
+{
+#ifdef LKST_DEBUG_MESSAGE
+	switch(lkst_evhandlerprim_maskset_xchg_inline(id)) {
+	case LKST_MASKSET_XCHG_ERRNO_SUCCESS:
+	case LKST_MASKSET_XCHG_ERRNO_WCPT:
+	case LKST_MASKSET_XCHG_ERRNO_WCID:
+		return 0;
+	case LKST_MASKSET_XCHG_ERRNO_ECPT:
+	case LKST_MASKSET_XCHG_ERRNO_ESTAT:
+		return -EBUSY;
+	case LKST_MASKSET_XCHG_ERRNO_ELOCK:
+		return -EAGAIN;
+	case LKST_MASKSET_XCHG_ERRNO_ENID:
+	case LKST_MASKSET_XCHG_ERRNO_ENPT:
+	default:
+		return -EINVAL;	       
+	}
+#else /*LKST_DEBUG_MESSAGE*/
+	return lkst_evhandlerprim_maskset_xchg_inline(id);
+#endif
+}
+
+/*********************************************************************
+ * Event handle functions (embeded)
+ *********************************************************************/
+
+/* default event handler function */
+void lkst_evhandler_default(void *phookrec, int event_type,
+			    lkst_arg_t arg1,
+			    lkst_arg_t arg2,
+			    lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	lkst_evhandlerprim_entry_log_inline(event_type,
+					    arg1, arg2, arg3, arg4);
+}
+
+/* default event handler control function */
+int lkst_evhandler_default_ctrl(void *buf, size_t bufsize)
+{
+	return 0;
+}
+
+/* default event handler function */
+void lkst_evhandler_log_static(void *phookrec, int event_type,
+			       lkst_arg_t arg1,
+			       lkst_arg_t arg2,
+			       lkst_arg_t arg3, lkst_arg_t arg4)
+{
+	lkst_evhandlerprim_entry_log_static_inline(event_type,
+						 arg1, arg2, arg3, arg4);
+}
+
+/* Event handler for buffer shifting */
+void lkst_evhandler_buffer_shift(void *phookrec, int event_type,
+				 lkst_arg_t arg1,
+				 lkst_arg_t arg2,
+				 lkst_arg_t arg3,
+				 lkst_arg_t arg4)
+{
+	lkst_buffer_shift_core();
+}
+
+/* Event handler for shifting buffer and awaking read process */
+void lkst_evhandler_buffer_shift_wakeup(void *phookrec, int event_type,
+					lkst_arg_t arg1,
+					lkst_arg_t arg2,
+					lkst_arg_t arg3,
+					lkst_arg_t arg4)
+{
+	lkst_buffer_shift_core();
+	lkst_evhandlerprim_owner_wakeup_inline();
+}
+
+#if DEBUG
+/* 
+ * event-handler-function lkst_evhandler_exception
+ *
+ * This event handler is used for exception event.
+ * It can record multiple exception events, the first event is
+ * written to currently selected buffer, and after second events are
+ * written to static buffer.
+ *
+ * This event handler is used as not to crush linux kernel because of
+ * occurring multiple exception event.
+ * 
+ * "exhandler_addr" is an exception handler address.
+ *
+ */
+void lkst_evhandler_exception(void *phookrec,
+			      int event_type,
+			      lkst_arg_t arg1,
+			      lkst_arg_t arg2,
+			      lkst_arg_t arg3,
+			      lkst_arg_t arg4)
+{
+	static lkst_arg_t exhandler_addr = 0;
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	/* exception handler address check */
+	if (exhandler_addr != arg1) {
+		exhandler_addr = arg1;
+		lkst_evhandlerprim_entry_log_inline(event_type,
+						    arg1, arg2,
+						    arg3, arg4);
+	} else {
+		/* write to static buffer*/
+		lkst_evhandlerprim_entry_log_static_inline(event_type,
+							 arg1, arg2,
+							 arg3, arg4);
+		exhandler_addr = 0;
+	}
+
+
+	local_irq_restore(flags);
+
+	return;
+}
+#endif /* DEBUG */
+
+/* while dumping, stop logging.*/
+#if defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)
+static int lkst_dump_notify_handler(struct notifier_block *self, 
+				    unsigned long stat,
+				    void *dev)
+{
+	static lkst_maskset_id maskset_id_saved = 0;
+	if ( stat == DUMP_BEGIN ) {
+		maskset_id_saved = lkst.current_maskset_id;
+		lkst_hook_maskset_xchg(LKST_MASKSET_ID_RNOTHING, 
+				       lkst.current_maskset_id);
+		LKST_MASKSET_SET_CURRENT(LKST_MASKSET_ID_RNOTHING);
+	} else {
+		/* after dumping, recover previous maskset */
+		lkst_hook_maskset_xchg(maskset_id_saved, 
+				       LKST_MASKSET_ID_RNOTHING);
+		LKST_MASKSET_SET_CURRENT(maskset_id_saved);	
+	}	
+	lkst_evhandlerprim_entry_log_static_inline(LKST_ETYPE_LKST_KERNEL_DUMP,
+						   LKST_ARGP(dev), 
+						   LKST_ARG(stat),
+						   0, 0);
+	return NOTIFY_DONE;
+}
+#endif /*defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)*/
+
+/*********************************************************************
+ * Lkst core functions
+ *********************************************************************/
+/*
+ * This checks read mode of a specified buffer list.
+ * If the current process is set to read the buffer list,
+ * it returns 0. If not, it returns 1.
+ * When the process is not set, that is not allowed to 
+ * read, seek, create, delete buffers of the buffer list.
+ */
+static __inline__ int lkst_buffer_rmod_check(int cpu)
+{
+	if (lkst_cpu[cpu].owner.pid != current->pid) {
+		return 1 ;/*(lkst_cpu[cpu].buffer_owner != (PID_MAX + 1));*/
+	}
+	return 0;
+}
+
+static __inline__ int lkst_trc_status_core(struct lkst_status_param *param)
+{
+	int i;
+	lkst_maskset *maskset;
+	lkst_evhandler_func evhandler;
+
+	/* !NOTE!: please check (param != NULL) before calling this.*/
+	param->current_maskset_id = lkst.current_maskset_id;
+	param->online_cpu = cpu_online_map;
+
+	param->static_buffer_recid = atomic_read(&lkst.static_buffer.recid);
+	param->static_buffer_size = LKST_STATIC_BUFFER_BYTE;
+
+	for (i = 0; i < LKST_CPU_MAX; i++)
+		param->write_buffer_id[i] = lkst_cpu[i].write_buf;
+	for (i = 0; i < LKST_CPU_MAX; i++)
+		param->read_buffer_id[i] = lkst_cpu[i].owner.read_buf;
+
+	/*needless to get lock, just ignore to count modifying masksets*/
+	param->maskset_num = 0;
+	for (i = 0; i < LKST_MASKSET_TBL_MAX; i++) {
+		if (LKST_POINTER_LOAD(lkst.maskset_table[i].masksetp, maskset))
+			param->maskset_num++;
+	}
+	/*needless to get lock, just ignore to count modifying evhandler*/
+	param->evhandler_num = 0;
+	for (i = 0; i < LKST_EVHANDLER_TBL_MAX; i++) {
+		if (LKST_POINTER_LOAD(lkst.evhandler_table[i].evhandler,
+				      evhandler) ) param->evhandler_num++;
+	}
+	/* get version */
+	param->version.major    = LKST_VERSION_MAJOR;
+	param->version.minor    = LKST_VERSION_MINOR;
+	param->version.revision = LKST_VERSION_REVISION;
+	return 0;
+}
+
+/* lkst_trc_start* and lkst_trc_stop* functions are obsolete.*/
+static __inline__ int lkst_trc_start_core(void)
+{
+	lkst_maskset *maskset;
+	lkst_maskset_id current_id;
+
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+	
+	if (lkst.maskset_id_saved > LKST_MASKSET_ID_MAX) {
+		LKST_DPRINTK("Save maskset ID=%d is invalid!\n", lkst.maskset_id_saved);
+	        lkst.maskset_id_saved = LKST_MASKSET_ID_RDEFAULT;
+	}
+
+	if (!LKST_POINTER_LOAD(lkst.maskset_table[lkst.maskset_id_saved].masksetp, maskset)) {
+		LKST_DPRINTK("Saved maskset ID=%d has already been deleted!\n", lkst.maskset_id_saved);
+		lkst.maskset_id_saved = LKST_MASKSET_ID_RDEFAULT;
+	}
+
+	current_id = lkst.current_maskset_id;
+	if (current_id != lkst.maskset_id_saved){
+		LKST_MASKSET_SET_CURRENT(lkst.maskset_id_saved);
+		lkst_hook_maskset_xchg(lkst.current_maskset_id, current_id);
+	}
+
+	spin_unlock(&lkst_maskset_lock);
+	return 0;
+}
+
+
+static __inline__ int lkst_trc_stop_core(void)
+{
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+
+	lkst.maskset_id_saved = lkst.current_maskset_id;
+
+	lkst_hook_maskset_xchg(LKST_MASKSET_ID_RNOTHING, 
+			       lkst.current_maskset_id);
+	LKST_MASKSET_SET_CURRENT(LKST_MASKSET_ID_RNOTHING);
+
+	spin_unlock(&lkst_maskset_lock);
+	return 0;
+}
+
+static __inline__ int lkst_maskset_read_core(struct lkst_maskset_param *param)
+{
+	int i, retval;
+	lkst_maskset *maskset;
+	struct lkst_maskset_entry *entry;
+	lkst_evhandler_id id;
+	size_t size;
+
+	/* !NOTE!: please check (param != NULL) before calling this.*/
+	size = param->maskset_size;
+
+	if (param->id == LKST_MASKSET_ID_VOID)
+		param->id = lkst.current_maskset_id;
+
+	if (param->id > LKST_MASKSET_ID_MAX) {
+		LKST_DPRINTK("Invalid maskset ID=%d\n", param->id);
+		return -EINVAL;
+	}
+
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+ /*startof_atomic_region:*/
+	
+	if (!LKST_POINTER_LOAD(lkst.maskset_table[param->id].masksetp,
+			       maskset)) {
+		LKST_DPRINTK("Maskset(ID=%d) does not exist!\n", param->id);
+		retval = -EINVAL;
+		goto endof_atomic_region;
+	}
+
+	entry = param->maskset->entry;
+	param->maskset->len = LKST_MASKSET_TABLE_LEN_MAX;
+
+        size -= LKST_MASKSET_SIZE(0);
+
+	for (i = 0; i < LKST_MASKSET_TABLE_LEN_MAX; i++) {
+		id = LKST_MASKSET_QUERY_EVHANDLER_ID(maskset, i);
+		entry->event_type = i;
+		entry->id = id;
+                size -= sizeof(struct lkst_maskset_entry);
+                if (size < sizeof(struct lkst_maskset_entry)){
+			param->maskset->len = i + 1;
+			break;
+                }
+		entry++;
+	}
+
+	strncpy(param->maskset->name, lkst.maskset_table[param->id].name, (size_t) LKST_MASKSET_NAME_LEN);
+	param->maskset->name[LKST_MASKSET_NAME_LEN - 1] = '\0';
+	retval = 0;
+	
+ endof_atomic_region:
+	spin_unlock(&lkst_maskset_lock);
+
+	return retval;
+}
+
+/* no-lock operation: you must get maskset lock before calling this!*/
+static __inline__ lkst_maskset_id lkst_maskset_get_id_core_nl(const char *name)
+{
+	/* !NOTE!: please check name != NULL && name[0] != '\0'*/
+	lkst_maskset_id id;
+	volatile lkst_maskset *maskset;
+	for (id = 0; id <= LKST_MASKSET_ID_MAX; id++) {
+		if (LKST_POINTER_LOAD(lkst.maskset_table[id].masksetp,
+				      maskset)) {
+			if (strncmp(name, 
+				    lkst.maskset_table[id].name,
+				    LKST_MASKSET_NAME_LEN) == 0){
+				return id;
+			}
+		}
+	}
+	return LKST_MASKSET_ID_VOID;
+}
+
+static __inline__ \
+int lkst_maskset_validate_evhandler_nl(struct lkst_maskset_param *param)
+{
+	int i;
+	lkst_evhandler_id id;
+	lkst_evhandler_func evhandler;
+	for (i = 0; i < param->maskset->len; i++ ) {
+		int type = param->maskset->entry[i].event_type;
+		id = param->maskset->entry[i].id;
+
+		if (type > LKST_ETYPE_MAX || type < 0) {
+			LKST_DPRINTK("Invalid event_type=%d\n", type);
+			return -EINVAL;
+		}
+
+		if (id > LKST_EVHANDLER_ID_MAX &&
+		    id != LKST_EVHANDLER_ID_VOID) {
+			LKST_DPRINTK("Invalid handler ID=%d\n", id);
+			return -EINVAL;
+		}
+		if (!LKST_POINTER_LOAD(
+			    lkst.evhandler_table[id].evhandler,
+			    evhandler) &&
+		    id != LKST_EVHANDLER_ID_VOID) {
+	    		LKST_DPRINTK("Handler(ID=%d) does not exist!\n", id);
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
+static __inline__ \
+lkst_evhandler_id * lkst_maskset_create_table_inline(void)
+{
+	int i;
+	lkst_evhandler_id * table;
+	table = (lkst_evhandler_id *)vmalloc(LKST_MASKSET_TABLE_BYTE);
+	if (table == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory!\n");
+		return NULL;
+	}
+	
+	if (!LKST_LIMIT_ADDRESS_CHECK(table, LKST_MASKSET_TABLE_BYTE,
+				      lkst.limit_addr)) {
+		LKST_DPRINTK("Cannot allocate maskset area! Aloocation limit address:0x%p, "
+			     "new maskset needs to 0x%p\n", lkst.limit_addr, 
+			     (void *) ((char *) table + LKST_MASKSET_TABLE_BYTE));
+		vfree((void*)table);
+		return NULL;
+	}
+	for (i = 0; i <= LKST_ETYPE_MAX; i++)
+		table[i] = LKST_EVHANDLER_ID_VOID;
+
+	return table;
+}
+
+/* !NOTE!: please check (param != NULL && param->maskset != NULL) 
+ * before calling this.*/
+static int lkst_maskset_write_core(struct lkst_maskset_param *param)
+{
+	int i, ret;
+	lkst_maskset *maskset;
+
+	/*get the maskset lock*/
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+ /*startof_outer_region:*/
+	if ( param->maskset->name[0] == '\0' ) {
+		if( param->id == LKST_MASKSET_ID_VOID || 
+		    ! LKST_MASKSET_TABLE_LOAD(param->id, maskset)) {
+			ret = -EINVAL;
+			goto endof_outer_region;
+		}
+	} else {
+		lkst_maskset_id mid;
+		mid = lkst_maskset_get_id_core_nl(param->maskset->name);
+		if ( mid == LKST_MASKSET_ID_VOID ) {
+			/* name is unique */
+			if(param->id == LKST_MASKSET_ID_VOID) {
+				/* search empty entry */
+				for (i = 0; i < LKST_MASKSET_TBL_MAX; i++) {
+					if (!LKST_MASKSET_TABLE_LOAD(i, 
+								     maskset))
+						break;
+				}
+				if (i == LKST_MASKSET_TBL_MAX) {
+					LKST_DPRINTK("Cannot register "
+						     "maskset any more!\n");
+					ret = -ENOSPC;
+					goto endof_outer_region;
+				}
+				param->id = i;
+			}
+		} else {/* name is not unique */
+			if ( param->id == LKST_MASKSET_ID_VOID ) {
+				param->id = mid;
+			} else if ( mid != param->id ){
+				LKST_DPRINTK("Specified ID does not "
+					     "associate with %s!\n",
+					     param->maskset->name);
+				ret = -EINVAL;
+				goto endof_outer_region;
+			}/*mid == param->id*/
+		}
+	}
+
+	/* check whether specified id is reserved*/
+	if (param->id <= LKST_MASKSET_ID_RDEFAULT ||
+	    param->id > LKST_MASKSET_ID_MAX ) {
+		LKST_DPRINTK("Invalid number of maskset ID=%d\n", param->id);
+		ret = -EINVAL;
+		goto endof_outer_region;
+	}
+
+	if (!spin_trylock(&lkst_evhandler_lock)) {
+		LKST_DPRINTK("Cannot get evhandler lock.\n");
+		ret = -EAGAIN;
+		goto endof_outer_region;
+	}
+ /*startof_inner_region:*/
+	/* check whether all of specified evhandlers are valid*/
+	if ( (ret = lkst_maskset_validate_evhandler_nl(param)) < 0 ) {
+		goto endof_inner_region;
+	}
+	ret = 0;
+
+	if (lkst.maskset_table[param->id].masksetp == NULL) {
+		/* new maskset-table allocate */
+		maskset = (lkst_maskset *)lkst_maskset_create_table_inline();
+		if (!maskset) {
+			ret = -ENOMEM;
+			goto endof_inner_region;
+		}
+		LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table, param->id, 
+					     param->maskset->name, maskset);
+	} else {
+		/* table will be overwritten */
+		if (!LKST_MASKSET_TABLE_LOAD(param->id, maskset)) {
+			LKST_DPRINTK("Maskset(ID=%d) is collapsed!\n", param->id);
+			ret = -EBUSY;
+			goto endof_inner_region;
+		}
+		if (param->maskset->name[0] != '\0') {
+			LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table, 
+						     param->id, 
+						     param->maskset->name,
+						     maskset);
+		}
+	}
+
+	if(param->id == lkst.current_maskset_id) {
+		for (i = 0; i < param->maskset->len; i++){
+			lkst_event_type etype = 
+				param->maskset->entry[i].event_type;
+			if((LKST_MASKSET_QUERY_EVHANDLER_ID(maskset, etype) !=
+			    param->maskset->entry[i].id)&&
+			   (etype < LKST_MASKSET_TBL_MAX)) {
+				lkst_hook_exit_xchg(etype, 
+					param->maskset->entry[i].id,
+					LKST_MASKSET_QUERY_EVHANDLER_ID(
+							maskset, etype));
+			}
+		}
+	}
+
+	/* main */
+	for (i = 0; i < param->maskset->len; i++)
+		LKST_MASKSET_SET_EVHANDLER_ID(maskset, param->maskset->entry[i].event_type, param->maskset->entry[i].id);
+
+ endof_inner_region:
+	spin_unlock(&lkst_evhandler_lock);
+ endof_outer_region:
+	spin_unlock(&lkst_maskset_lock);
+	return ret;
+}
+
+
+static __inline__ int lkst_maskset_xchg_core(lkst_maskset_id * id)
+{
+	int	ret;
+	/* !NOTE!: please check (id != NULL) before calling this.*/
+#ifdef LKST_DEBUG_MESSAGE
+	lkst_maskset_id old_id = *id;
+#endif
+
+	ret = lkst_evhandlerprim_maskset_xchg_inline(id);
+
+#ifdef LKST_DEBUG_MESSAGE
+	switch (ret) {
+	case LKST_MASKSET_XCHG_ERRNO_SUCCESS:
+		return 0;
+	case LKST_MASKSET_XCHG_ERRNO_WCPT:
+		LKST_DPRINTK("Current maskset(ID=%d) is collapsed!\n", old_id);
+		return 0;
+	case LKST_MASKSET_XCHG_ERRNO_WCID:
+		LKST_DPRINTK("Invalid ID=%d of current maskset!\n", old_id);
+		return 0;
+	case LKST_MASKSET_XCHG_ERRNO_ECPT:
+		LKST_DPRINTK("Current maskset(id=%d) is collapsed!\n", old_id);
+		return -EBUSY;
+	case LKST_MASKSET_XCHG_ERRNO_ENID:
+		LKST_DPRINTK("Invalid maskset ID=%d\n", *id);
+		return -EINVAL;
+	case LKST_MASKSET_XCHG_ERRNO_ENPT:
+		LKST_DPRINTK("Specified maskset(ID=%d) does not exist!\n", *id);
+		return -EINVAL;
+	case LKST_MASKSET_XCHG_ERRNO_ESTAT:
+		LKST_DPRINTK("Cannot change maskset when LKST is not running!\n");
+		return -EBUSY;
+	case LKST_MASKSET_XCHG_ERRNO_ELOCK:
+		LKST_DPRINTK("Cannot get maskset lock!\n");
+		return -EAGAIN;
+	default:
+		LKST_DPRINTK("Unknown error occured, old/new maskset ID=%d/%d.\n", old_id, *id);
+		return -EINVAL;
+	}
+#else /*!LKST_DEBUG_MESSAGE*/
+	return ret;
+#endif
+}
+
+
+static __inline__ int lkst_maskset_list_core(struct lkst_maskset_listparam *lp)
+{
+	int i, cnt, cnt_max;
+	lkst_maskset *maskset;
+
+	/* !NOTE!: please check (lp != NULL) before calling this.*/
+	if(lp->listent_size < LKST_MASKSET_LISTENT_SIZE(1) ||
+	   lp->listent_size > LKST_MASKSET_LISTENT_SIZE(LKST_MASKSET_TBL_MAX)) {
+		LKST_DPRINTK("Invalid listent_size=%d\n", lp->listent_size);
+		return -EINVAL;
+	}
+
+	cnt = 0;
+	cnt_max = lp->listent_size / sizeof(struct lkst_maskset_listent);
+
+	for (i = 0; i < cnt_max; i++) {
+		lp->listent[i].id = LKST_MASKSET_ID_VOID;
+		lp->listent[i].name[0]='\0';
+		lp->listent[i].len = 0;
+	}
+		
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+ /*startof_atomic_region:*/
+	for (i = 0; i < LKST_MASKSET_TBL_MAX; i++) {
+		if (LKST_POINTER_LOAD(
+			    lkst.maskset_table[i].masksetp,
+			    maskset)) {
+			lp->listent[cnt].id = i;
+			strcpy(lp->listent[cnt].name, lkst.maskset_table[i].name);
+			
+			lp->listent[cnt].len = LKST_MASKSET_TABLE_LEN_MAX;
+			cnt++;
+			if(cnt >= cnt_max) break;
+		}
+	}
+
+	lp->current_id = lkst.current_maskset_id;
+
+ /*endof_atomic_region:*/
+	spin_unlock(&lkst_maskset_lock);
+
+	return 0;
+}
+
+
+static __inline__ int lkst_maskset_delete_core(lkst_maskset_id id)
+{
+	int ret;
+	lkst_maskset *maskset;
+
+	if (id == LKST_MASKSET_ID_RALL ||
+	    id == LKST_MASKSET_ID_RNOTHING ||
+	    id == LKST_MASKSET_ID_RDEFAULT) {
+		LKST_DPRINTK("Cannot delete special maskset!\n");
+		return -EINVAL;
+	}
+
+	if (id > LKST_MASKSET_ID_MAX) {
+		LKST_DPRINTK("Invalid maskset ID=%d\n", id);
+		return -EINVAL;
+	}
+	
+
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		LKST_DPRINTK("Cannot get maskset lock.\n");
+		return -EAGAIN;
+	}
+	ret = 0;
+ /*startof_atomic_region:*/
+	if (id == lkst.maskset_id_saved) {
+		LKST_DPRINTK("Specified maskset(ID=%d) is currently saved!\n Change to DEFAULT maskset.", id);
+		lkst.maskset_id_saved = LKST_MASKSET_ID_RDEFAULT;
+	}
+	if (id == lkst.current_maskset_id) {
+		LKST_DPRINTK("Specified maskset(ID=%d) is currently used!\n", id);
+		ret = -EBUSY;
+	} else {
+		if (!LKST_POINTER_LOAD(lkst.maskset_table[id].masksetp,
+				       maskset)) {
+			LKST_DPRINTK("Maskset(ID=%d) does not exist!\n", id);
+			ret = -EINVAL;
+		} else {
+			LKST_POINTER_STORE(lkst.maskset_table[id].masksetp,
+					   NULL);
+			vfree(maskset);
+		}
+	}
+ /*endof_atomic_region:*/
+	spin_unlock(&lkst_maskset_lock);
+
+	return ret;
+}
+
+static __inline__ int 
+lkst_evhandler_list_core(struct lkst_evhandler_listparam *lp)
+{
+	int i, cnt, cnt_max;
+	lkst_evhandler_func evhandler;
+
+	/* !NOTE!: please check (lp != NULL) before calling this.*/
+	if(lp->listent_size < sizeof(struct lkst_evhandler_listent) ||
+	   lp->listent_size > LKST_EVHANDLER_LISTENT_SIZE(LKST_EVHANDLER_TBL_MAX)) {
+		LKST_DPRINTK("Invalid listent_size=%d\n", lp->listent_size);
+		return -EINVAL;
+	}
+
+	cnt = 0;
+	cnt_max = lp->listent_size / sizeof(struct lkst_evhandler_listent);
+
+	for (i = 0; i < cnt_max; i++) {
+		lp->listent[i].id = LKST_EVHANDLER_ID_VOID;
+		lp->listent[i].name[0] = '\0';
+	}
+		
+	if (!spin_trylock(&lkst_evhandler_lock)) {
+		LKST_DPRINTK("Cannot get the evhandler lock.\n");
+		return -EAGAIN;
+	}
+	for (i = 0; i < LKST_EVHANDLER_TBL_MAX; i++) {
+		if (LKST_POINTER_LOAD(
+			    lkst.evhandler_table[i].evhandler,
+			    evhandler)) {
+			lp->listent[cnt].id = i;
+			strcpy(lp->listent[cnt].name, lkst.evhandler_table[i].name);
+			
+			cnt++;
+			if(cnt > cnt_max)
+				break;
+		}
+	}
+	spin_unlock(&lkst_evhandler_lock);
+
+	return 0;
+}
+
+static __inline__ int 
+lkst_evhandler_ctrl_core(lkst_evhandler_id id,
+			 void * buf, size_t bufsize, 
+			 int * retval)
+{
+	lkst_evhandler_ctrl_func evhandler_ctrl;
+	if (id > LKST_EVHANDLER_ID_MAX) {
+		LKST_DPRINTK("Invalid handler ID = %d\n", id);
+		return -EINVAL;
+	}
+
+	if (!LKST_POINTER_LOAD(lkst.evhandler_table[id].evhandler_ctrl,
+			       evhandler_ctrl)) {
+		LKST_DPRINTK("Ctrl-function(ID=%d) does not exist!\n", id);
+		return -EINVAL;
+	}
+
+	*retval = (*evhandler_ctrl) (buf, bufsize);
+	return 0;
+}
+
+/*
+ * lkst_evhandler_register_core_nl
+ * return value : 
+ * 	success 0
+ *	fail	errno
+ * Called from lkst_evhandler_register, lkst_evhandler_unregister_core, 
+ * lkst_init_stage0
+ * This function do !NOT! check which name is used. 
+ * please check it before call.
+ * execute without lock.
+ */
+static __inline__ int 
+lkst_evhandler_register_core_nl(lkst_evhandler_id id, const char *name,
+				lkst_evhandler_func evhandler,
+				lkst_evhandler_ctrl_func evhandler_ctrl)
+{
+	if ( name != NULL ) {
+		strncpy(lkst.evhandler_table[id].name, name,
+			(size_t) LKST_EVHANDLER_NAME_LEN);
+		lkst.evhandler_table[id].name[LKST_EVHANDLER_NAME_LEN - 1] = '\0';
+	} else
+		lkst.evhandler_table[id].name[0] = '\0';
+
+	/*register*/
+	LKST_POINTER_STORE(lkst.evhandler_table[id].evhandler_ctrl,
+			   evhandler_ctrl);
+	LKST_POINTER_STORE(lkst.evhandler_table[id].evhandler,
+			   evhandler);
+	return 0;
+}
+
+/*
+ * lkst_evhandler_unregister_core
+ * return value :
+ *	success	0
+ *	fail	errno
+ * Called from lkst_evhandler_unregister, lkst_trc_init_stage0, lkst_cleanup_module
+ */
+static __inline__ int lkst_evhandler_unregister_core_nl(lkst_evhandler_id id)
+{
+	return lkst_evhandler_register_core_nl(id, NULL, NULL, NULL);
+}
+
+/*
+ * lkst_evhandler_get_id_core_nl
+ * return value : evhandler_id
+ * Called from lkst_evhandler_register,lkst_evhandler_get_id, lkst_evhandler_get_id_ioctl(not implemented)
+ */
+static __inline__ lkst_evhandler_id
+lkst_evhandler_get_id_core_nl(const char *name)
+{
+	lkst_evhandler_id id;
+	/* !NOTE!: please check (name != NULL) && (strlen(name)!=0) before calling.*/
+	for ( id = 0; id <= LKST_EVHANDLER_ID_MAX; id++) {
+		if (lkst.evhandler_table[id].evhandler != NULL) {
+			if (strncmp(name, 
+				    lkst.evhandler_table[id].name,
+				    LKST_EVHANDLER_NAME_LEN) == 0){
+				return id;
+			}
+		}
+	}
+	return LKST_EVHANDLER_ID_VOID;
+}
+
+/*
+ * This function just makes a instance of a buffer.
+ * And never sets in the table of buffers.
+ */
+static __inline__ struct lkst_event_buffer * \
+lkst_buffer_create_instance_inline(size_t size, lkst_buffer_id next, int cpu_id) 
+{
+	struct lkst_event_buffer *buffer;
+	int i;
+	/* align to times of 4k */
+	if ( (size & ~LKST_BUFFER_PAGE_MASK) ) size += LKST_BUFFER_PAGE_BYTE;
+	size &= LKST_BUFFER_PAGE_MASK;
+	if (size < LKST_BUFFER_SIZE_MIN) {
+		size = LKST_BUFFER_SIZE_MIN;
+	} else if (size > LKST_BUFFER_SIZE_MAX) {
+		size = LKST_BUFFER_SIZE_MAX;
+	}
+
+	size += LKST_BUFFER_PAGE_BYTE; /* for margin and header */
+
+	/* create new buffer area */
+	buffer = (struct lkst_event_buffer *)vmalloc(size);
+	if (buffer == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory(size=%d)\n", size);
+		return NULL;
+	}
+	if (!LKST_LIMIT_ADDRESS_CHECK(buffer, size, lkst.limit_addr)) {
+		LKST_DPRINTK("Cannot allocate buffer area! "
+			     "Aloocation limit address:0x%p, "
+			     "new buffer needs to 0x%p\n", lkst.limit_addr, 
+			     (void *) ((char *) buffer + size));
+		vfree(buffer);
+		return NULL;
+	}
+
+	buffer->next = next;
+	buffer->rq_next = LKST_BUFFER_ID_VOID;
+	buffer->rq_prev = LKST_BUFFER_ID_VOID;
+
+	buffer->size = (size - LKST_BUFFER_HEADER_BYTE)/LKST_EVENT_RECORD_BYTE;
+	buffer->baseid = 0;
+	buffer->write_offset = -LKST_BUFFER_INIT_POS;
+	buffer->cpu = smp_processor_id();
+	buffer->cmos_time_flag = lkst.cmos_time_flag;
+	buffer->xtime.tv_sec = lkst.xtime.tv_sec;
+	buffer->xtime.tv_usec = lkst.xtime.tv_usec;
+	strncpy(buffer->eyecatcher, "LKBF", 4);
+	buffer->buf_ver = LKST_BUF_VER;
+
+	/* clear recid, cpu_id, and event_type */
+	for (i = 0; i < buffer->size; i++) {
+		LKST_BUFFER_BODY(buffer)[i].log_recid = 0;
+		LKST_BUFFER_BODY(buffer)[i].log_event_type = LKST_ETYPE_VOID;
+		LKST_BUFFER_BODY(buffer)[i].processor = cpu_id;
+	}
+	return buffer;
+}
+
+/*
+ * This makes a buffer and sets in the table of buffers.
+ */
+static __inline__ int 
+lkst_buffer_create_core(lkst_buffer_id id, size_t size, lkst_buffer_id next)
+{
+	struct lkst_event_buffer *buffer;
+	int i;
+
+	buffer = lkst_buffer_create_instance_inline(size, next, 
+						    smp_processor_id());
+	if ( buffer == NULL ) return -ENOMEM;
+
+	if (id == LKST_BUFFER_ID_VOID) {
+		/* search empty entry */
+		for (i = 0; i < LKST_BUFFER_TBL_MAX; i++) {
+			if (LKST_BUFFER_CHECK_NULL(i))
+				break;
+		}
+		if (i == LKST_BUFFER_TBL_MAX) {
+			LKST_DPRINTK("Cannot create buffer any more!\n");
+			vfree(buffer);
+			return -ENOSPC;
+		}
+		id = i;
+	}else if (! LKST_BUFFER_CHECK_NULL(id)) {
+		LKST_DPRINTK("Buffer(ID=%d) already exist!\n", id);
+		vfree(buffer);
+		return -EINVAL;
+	}
+
+	/* register to buffer_table */ {
+		unsigned long flags;
+		buffer->id = id;
+		local_irq_save(flags);
+		LKST_BUFFER_STORE(id, buffer);
+		local_irq_restore(flags);
+	}
+
+	return id;
+}
+
+static __inline__ int lkst_buffer_delete_core(lkst_buffer_id id)
+{
+	struct lkst_event_buffer *buffer = NULL;
+	unsigned long flags;
+	int ret = 0;
+	
+	if (id == LKST_BUFFER_ID_VOID) {
+		LKST_DPRINTK("Buffer(ID=%d) does not exist!\n", id);
+		return -EINVAL;
+	}
+	local_irq_save(flags);
+	if (lkst_current.write_buf == id) {
+		LKST_DPRINTK("Buffer(ID=%d) is currently writing!\n", id);
+		ret = -EBUSY;
+	} else if ( lkst_current.owner.read_buf == id && lkst_current.reading ){
+		LKST_DPRINTK("Buffer(ID=%d) is currently reading!\n", id);
+		ret = -EBUSY;
+	} else {
+		if (!LKST_BUFFER_LOAD(id, buffer)) {
+			LKST_DPRINTK("Buffer(ID=%d) does not exist!\n", id);
+			ret = -EINVAL;
+		} else {
+			/* unregister buffer pointer */
+			if(buffer->rq_next != LKST_BUFFER_ID_VOID ||
+			   lkst_current.rq_tail == id)
+				lkst_buffer_dequeue_inline(buffer);
+			/* Check whether this buffer is currently using. */
+			LKST_BUFFER_STORE(id, NULL);
+			if ( lkst_current.owner.read_buf == id ){
+				lkst_current.owner.read_buf = 
+					LKST_BUFFER_ID_VOID;
+			}
+		}
+	}
+	local_irq_restore(flags);
+
+	/* free buffer area */
+	if (ret == 0) vfree(buffer);
+
+	return ret;
+}
+
+static __inline__ \
+int lkst_buffer_list_core(struct lkst_buffer_listparam *lp)
+{
+	int i, cnt, cnt_max;
+	struct lkst_event_buffer *buffer;
+
+	/* !NOTE!: please check (lp != NULL) before calling this.*/
+	cnt = 0;
+	cnt_max = lp->listent_num;
+
+	/* list buffers */
+	for (i = 0; i < LKST_BUFFER_TBL_MAX; i++) {
+		if (!LKST_BUFFER_LOAD(i, buffer)) continue;
+		if (cnt < cnt_max) {
+			lp->listent[cnt].id = buffer->id;
+			lp->listent[cnt].next = buffer->next;
+			lp->listent[cnt].rq_prev = buffer->rq_prev;
+			lp->listent[cnt].rq_next = buffer->rq_next;
+			lp->listent[cnt].size = buffer->size*LKST_EVENT_RECORD_BYTE;
+			lp->listent[cnt].write_offset = buffer->write_offset;
+			lp->listent[cnt].baseid = buffer->baseid;
+		}
+		cnt++;
+	}
+	/* record percpu header */
+	lp->buffer_num = cnt;
+	lp->write_buf = lkst_current.write_buf;
+	lp->read_buf = lkst_current.owner.read_buf;
+	lp->rq_head = lkst_current.rq_head;
+	lp->rq_tail = lkst_current.rq_tail;
+	lp->owner = lkst_current.owner.pid;
+	lp->read_pos = lkst_current.owner.read_pos;
+
+	return cnt;
+}
+
+static int lkst_buffer_set_current_to_owner(int cpu)
+{
+	unsigned long allowed;
+	
+	/* !NOTE!: please check sp != NULL before calling this.*/
+	if (lkst_current.owner.pid == current->pid) {
+		LKST_DPRINTK("This process(pid=%d) is already "
+			     "set to read other buffer list.\n", current->pid);
+		return -EBUSY;
+	}
+
+	/* CPU binding */
+	if( lkst_cpu_migrate_save(&allowed, cpu) < 0) //TODO
+		return -EINVAL;
+
+	if (lkst_current.owner.pid != (PID_MAX + 1) && 
+	    lkst_current.owner.pid != current->pid) {
+		LKST_DPRINTK("Specified buffer list is already set "
+			     "reading mode by pid=%d\n",
+			lkst_current.owner.pid);
+		lkst_cpu_migrate_restore(allowed);
+		return -EBUSY;
+	}
+
+	/* Set owner pid to the buffer list of specified CPU */ 
+	lkst_current.owner.pid = current->pid;
+	return 0;
+}
+
+static int lkst_buffer_setrmod_core(struct lkst_buffer_srmodparam *sp)
+{
+	int retval;
+	retval = lkst_buffer_set_current_to_owner(sp->cpu);
+	if (retval < 0) {
+		return retval;
+	}
+	
+	/* get buffer time stamp */
+	sp->tsc = lkst.tsc;
+	sp->xtime.tv_sec = lkst.xtime.tv_sec;
+	sp->xtime.tv_usec = lkst.xtime.tv_usec;
+	sp->cpu_freq = lkst.cpu_freq;
+	sp->buf_ver = lkst.buf_ver;
+	strncpy(sp->arch, lkst.arch, LKST_ARCH_NAME_LEN);
+	sp->endian_big = lkst.endian_big;
+
+	return 0;
+}
+
+/*
+ * lkst_evhandler_register
+ * return value
+ *	success 0
+ *	fail	errno
+ * Called from external modules
+ */
+int lkst_evhandler_register(lkst_evhandler_id id, const char *name,
+			    lkst_evhandler_func evhandler,
+			    lkst_evhandler_ctrl_func evhandler_ctrl)
+{
+	int ret;
+	lkst_evhandler_func tmp;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (evhandler == NULL) {
+		return -EINVAL;
+	}
+
+	if (name == NULL || name[0] == '\0' ){
+		LKST_DPRINTK("Invalid evhandler name!\n");
+		return -EINVAL;
+	}
+	if (id <= LKST_EVHANDLER_ID_RESERVED) { 
+		LKST_DPRINTK("Reserved handler ID = %d\n", id);
+		return -EINVAL;
+	}
+	
+	if (!spin_trylock(&lkst_evhandler_lock)) {
+		LKST_DPRINTK("Cannot get the evhandler lock.\n");
+		return -EAGAIN;
+	}
+ /*startof_atomic_region:*/
+	/* check whether the name of event handler is unique.*/
+	if ( lkst_evhandler_get_id_core_nl(name) != LKST_EVHANDLER_ID_VOID) {
+		LKST_DPRINTK("The name <%s> is already used.\n",name);
+		ret = -EINVAL;
+		goto endof_atomic_region;
+	}
+	if (id == LKST_EVHANDLER_ID_VOID) {
+		/* Get an unused ID. */
+		for (id = LKST_EVHANDLER_ID_RESERVED + 1 ; 
+		     LKST_POINTER_LOAD(lkst.evhandler_table[id].evhandler,tmp);
+		     id++ ) { 
+			if (id > LKST_EVHANDLER_ID_MAX) {
+				LKST_DPRINTK("No handler ID is available.\n");
+				ret = -ENOSPC;
+				goto endof_atomic_region;
+			}
+		}
+	} else if (LKST_POINTER_LOAD(lkst.evhandler_table[id].evhandler,tmp)) {
+		LKST_DPRINTK("Specified handler ID is already used.\n");
+		ret = -EINVAL;
+		goto endof_atomic_region;
+	}
+	
+	lkst_evhandler_register_core_nl(id, name, 
+					evhandler,
+					evhandler_ctrl);
+	ret = lkst_hook_exit_update(id);
+
+ endof_atomic_region:
+	spin_unlock(&lkst_evhandler_lock);
+	return ret == 0 ? id : ret;
+}
+
+int lkst_evhandler_unregister(lkst_evhandler_id id)
+{
+	int ret;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	if (id <= LKST_EVHANDLER_ID_RESERVED) { 
+		LKST_DPRINTK("Reserved handler ID = %d\n", id);
+		return -EINVAL;
+	}
+
+	if (!spin_trylock(&lkst_evhandler_lock)) {
+		LKST_DPRINTK("Cannot get the evhandler lock.\n");
+		return -EAGAIN;
+	}
+	if ( lkst.evhandler_table[id].evhandler == NULL) {
+		LKST_DPRINTK("Specified handler(ID:%d) does not exist.\n",id);
+		ret = -EINVAL;
+	} else {
+		lkst_evhandler_unregister_core_nl(id);
+		ret = lkst_hook_exit_update(id);
+	}
+	spin_unlock(&lkst_evhandler_lock);
+	return ret;
+}
+
+
+/* kernel trc_status wrap function */
+int lkst_trc_status(struct lkst_status_param *param)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (param == NULL) { 
+		printk(KERN_ERR "Warning : argument param is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_trc_status_core(param);
+}
+
+/* kernel trc_start wrap function */
+int lkst_trc_start()
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_trc_start_core();
+}
+
+/* kernel trc_stop wrap function */
+int lkst_trc_stop()
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_trc_stop_core();
+}
+
+/* kernel maskset_read wrap function */
+int lkst_maskset_read(struct lkst_maskset_param *param)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (param == NULL) { 
+		printk(KERN_ERR "Warning : argument param is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_maskset_read_core(param);
+}
+
+/* kernel maskset_write wrap function */
+int lkst_maskset_write(struct lkst_maskset_param *param)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (param == NULL ) { 
+		printk(KERN_ERR "Warning : argument param is NULL!\n");
+		return -EINVAL;
+	}
+	if (param->maskset == NULL ) { 
+		printk(KERN_ERR "Warning : argument param->maskset is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_maskset_write_core(param);
+}
+
+/* kernel maskset_get_id wrap function */
+int lkst_maskset_get_id(const char *name)
+{
+	int ret;
+	/* this might be called from evhandler.
+	 * thus don't check whether caller process has admin-privilege.*/
+	if (name == NULL || name[0] == '\0') {
+		return -EINVAL;
+	}
+	if (!spin_trylock(&lkst_maskset_lock)) {
+		return -EAGAIN;
+	} else {
+		ret = lkst_maskset_get_id_core_nl(name);
+		spin_unlock(&lkst_maskset_lock);
+	}
+	return ret;
+}
+
+/* kernel maskset_xchg wrap function */
+int lkst_maskset_xchg(lkst_maskset_id * id)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (id == NULL) { 
+		printk(KERN_ERR "Warning : argument id is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_maskset_xchg_core(id);
+}
+
+/* kernel maskset_list wrap function */
+int lkst_maskset_list(struct lkst_maskset_listparam *lp)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (lp == NULL) { 
+		printk(KERN_ERR "Warning : argument lp is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_maskset_list_core(lp);
+}
+
+/* kernel maskset_delete wrap function */
+int lkst_maskset_delete(lkst_maskset_id id)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_maskset_delete_core(id);
+}
+
+/* kernel evhandler_list wrap function */
+int lkst_evhandler_list(struct lkst_evhandler_listparam *lp)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (lp == NULL) { 
+		printk(KERN_ERR "Warning : argument lp is NULL!\n");
+		return -EINVAL;
+	}
+
+	return lkst_evhandler_list_core(lp);
+}
+
+/* kernel evhandler_ctrl wrap function */
+int lkst_evhandler_ctrl(struct lkst_evhandler_ctrl_param *param)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (param == NULL)
+		return -EINVAL;
+
+	return lkst_evhandler_ctrl_core(param->id, param->buf, param->bufsize,
+					&param->ret);
+}
+
+/* kernel evhandler_get_id wrap function */
+int lkst_evhandler_get_id(const char *name)
+{
+	int ret;
+	/* this might be called from evhandler.
+	 * thus don't check whether caller process has admin-privilege.*/
+	
+	if ( name == NULL || name[0] == '\0' ) {
+		return -EINVAL;
+	}
+	if (!spin_trylock(&lkst_evhandler_lock)) {
+		return -EAGAIN;
+	} else {
+		ret =lkst_evhandler_get_id_core_nl(name);
+		spin_unlock(&lkst_evhandler_lock);
+		return ret;
+	}
+}
+
+/*
+ * function lkst_buffer_jump
+ * A primitive part of an Event-handler. This shift the writing buffer to 
+ * the specified buffer.
+ * 
+ *  Arguments
+ *    next:		ID of the distination buffer.
+ *
+ *  returns
+ *    errno:		error code
+ * 
+ *  This will be called from event handlers those are invoked by any processes.
+ *  So, we can't restrict any unpermitted accesses.
+ */
+int lkst_buffer_jump(lkst_buffer_id next)
+{
+	return lkst_buffer_jump_core(next);
+}
+
+/*
+ * function lkst_evhandlerprim_buffer_shift
+ * A primitive part of an Event-handler. This shift the writing buffer to 
+ * the next buffer.
+ * 
+ *  Arguments
+ *    NONE
+ *
+ *  returns
+ *    errno:		error code
+ * 
+ *  This will be called from event handlers those are invoked by any processes.
+ *  So, we can't restrict any unpermitted accesses.
+ */
+int lkst_buffer_shift(void)
+{
+	return lkst_buffer_shift_core();
+}
+
+/* kernel buffer_read wrap function */
+int lkst_buffer_read(struct lkst_log_buffer *lbuffer)
+{
+	int ret;
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (lbuffer == NULL) { 
+		printk(KERN_ERR "Warning : argument lbuffer is NULL!\n");
+		return -EINVAL;
+	}
+
+	lkst_current.reading++; /*read flag up*/
+	ret = lkst_buffer_read_core(lbuffer);
+	lkst_current.reading--; /*read flag down*/
+	return ret ;
+}
+
+/* kernel buffer_create wrap function */
+int lkst_buffer_create(lkst_buffer_id id, size_t size, lkst_buffer_id next)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_buffer_create_core(id, size, next);
+}
+
+/* kernel buffer_delete wrap function */
+int lkst_buffer_delete(lkst_buffer_id id)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_buffer_delete_core(id);
+}
+
+/* dump to printk (It might failed to read all dumped text ... TOO LONG!)*/
+void lkst_buffer_dump_current_txt(void)
+{
+	int i;
+	int cpu;
+	lkst_maskset_id id;
+	int err_f;
+	struct lkst_event_record *buff_body;
+	unsigned int *pArgs;
+	lkst_buffer_id buffer_id;
+	struct lkst_event_buffer *buffer;
+	int	event_type;
+	char	*event_type_name;
+
+	/* stop tracing */
+	id = LKST_MASKSET_ID_RNOTHING;
+	err_f = lkst_evhandlerprim_maskset_xchg(&id);
+
+/* TODO */
+	for (cpu = 0; cpu < LKST_CPU_MAX; cpu++) {
+		if (!lkst_cpu_is_online(cpu)) continue;
+		buffer_id =lkst_cpu[cpu].write_buf;
+		if (!((buffer_id <= LKST_BUFFER_ID_MAX) &&
+		      (LKST_CURRENT_BUFFER_LOAD(buffer)) )) 
+			continue;
+
+		for (i = 0; i < buffer->size; i++) {
+			buff_body = &(LKST_BUFFER_BODY(buffer)[i]);
+			event_type = buff_body->log_event_type;
+			
+			/* Stop dump if buffer pointer 
+			 *  reaches unused entry. */
+			if (!LKST_ETYPE_VERIFY(event_type)) continue;
+			
+			event_type_name = lkst_event_type_descriptions[
+				event_type];
+			
+			printk("0x%08x: " LKST_FMT_TSC " [mc], \\\n"
+			       " type: %25s(0x%04x), pid: %010u, "
+			       "cpu: %03u \\\n",
+			       buff_body->log_recid,
+			       buff_body->log_time,
+			       event_type_name, event_type,
+			       buff_body->log_pid,
+			       cpu);
+			
+			pArgs = (unsigned int *) &buff_body->log_arg1;
+			printk("  0x%08x 0x%08x 0x%08x 0x%08x \\\n"
+			       "  0x%08x 0x%08x 0x%08x 0x%08x \\\n\n",
+			       pArgs[0], pArgs[1], pArgs[2], pArgs[3], 
+			       pArgs[4], pArgs[5], pArgs[6], pArgs[7]);
+			
+		}	/* i */
+	}		/* cpu */
+
+	/* restart tracing */
+	printk("id: %010u\n", id);
+	if (!err_f)
+		lkst_evhandlerprim_maskset_xchg(&id);
+
+	return ;
+}
+
+/*********************************************************************
+ * ioctl functions (static *CLOSED* functions)
+ ********************************************************************/
+
+/* ioctl trc_status wrap function */
+static int lkst_trc_status_ioctl(struct lkst_status_param *param_user)
+{
+	int retval = 0;
+	struct lkst_status_param param;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	retval = lkst_trc_status_core(&param);
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_status_param))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n", 
+			     param_user);
+		return -EINVAL;
+	}
+
+	return retval;
+}
+
+/* ioctl trc_start wrap function */
+static int lkst_trc_start_ioctl(void)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_trc_start_core();
+}
+
+/* ioctl trc_stop wrap function */
+static int lkst_trc_stop_ioctl(void)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_trc_stop_core();
+}
+
+/* ioctl maskset_read wrap function */
+static int lkst_maskset_read_ioctl(struct lkst_maskset_param *param_user)
+{
+	int retval = 0;
+	struct lkst_maskset_param param;
+	struct lkst_maskset_body *maskset;
+	struct lkst_maskset_body *user_maskset;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user,
+			   sizeof(struct lkst_maskset_param))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	if (param.maskset_size <= 0 ||
+	    verify_area(VERIFY_WRITE, param.maskset, param.maskset_size)) {
+		LKST_DPRINTK("Invalid argument(maskset/maskset_size)\n");
+		return -EINVAL;
+	}
+
+	user_maskset = param.maskset;
+	maskset = vmalloc(param.maskset_size);
+	if (maskset == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory : size=%d\n", 
+			     param.maskset_size);
+		return -ENOMEM;
+	}
+
+	param.maskset = maskset;
+	retval = lkst_maskset_read_core(&param);
+
+	if (copy_to_user(user_maskset, param.maskset, param.maskset_size)) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     user_maskset);
+		return -EINVAL;
+	}
+
+	param.maskset = user_maskset;
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_maskset_param))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	vfree(maskset);
+
+	return retval;
+}
+
+/* ioctl maskset_write wrap function */
+static int lkst_maskset_write_ioctl(struct lkst_maskset_param *param_user)
+{
+	int retval = 0;
+	struct lkst_maskset_param param;
+	struct lkst_maskset_body *maskset, *save_user_maskset;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user, 
+			   sizeof(struct lkst_maskset_param))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	if (param.maskset_size <= 0 ||
+	    verify_area(VERIFY_READ, param.maskset, param.maskset_size)) {
+		LKST_DPRINTK("Ibvalid argument(maskset/maskset_size)\n");
+		return -EINVAL;
+	}
+
+	maskset = vmalloc(param.maskset_size);
+	if (maskset == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory : size=%d\n",
+			     param.maskset_size);
+		return -ENOMEM;
+	}
+
+	if (copy_from_user(maskset, param.maskset, param.maskset_size)) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param.maskset);
+		return -EINVAL;
+	}
+
+	save_user_maskset = param.maskset;
+	param.maskset = maskset;
+
+	retval = lkst_maskset_write_core(&param);
+
+	param.maskset = save_user_maskset;
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_maskset_param))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	vfree(maskset);
+
+	return retval;
+}
+
+/* ioctl maskset_set wrap function */
+static int lkst_maskset_set_ioctl(lkst_maskset_id id)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_maskset_xchg_core(&id);
+}
+
+/* ioctl maskset_list wrap function */
+static int lkst_maskset_list_ioctl(struct lkst_maskset_listparam *param_user)
+{
+	int retval = 0;
+	struct lkst_maskset_listparam param;
+	struct lkst_maskset_listent *listent;
+	struct lkst_maskset_listent *user_listent;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user, 
+			   sizeof(struct lkst_maskset_listparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+
+	if (param.listent_size <= 0 || 
+	    verify_area(VERIFY_WRITE, param.listent, param.listent_size)) {
+		LKST_DPRINTK("Invalid argument(listent/listent_size)\n");
+		return -EINVAL;
+	}
+	
+	user_listent = param.listent;
+	listent = vmalloc(param.listent_size);
+	if (listent == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory : size=%d\n",
+			     param.listent_size);
+		return -ENOMEM;
+	}
+
+	param.listent = listent;
+
+	retval = lkst_maskset_list_core(&param);
+
+	if (copy_to_user(user_listent, param.listent, param.listent_size)) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     user_listent);
+		return -EINVAL;
+	}
+
+	param.listent = user_listent;
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_maskset_listparam))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	vfree(listent);
+
+	return retval;
+}
+
+/* ioctl maskset_delete wrap function */
+static int lkst_maskset_delete_ioctl(lkst_maskset_id id)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return lkst_maskset_delete_core(id);
+}
+
+/* ioctl maskset_get_id wrap function */
+static int lkst_maskset_get_id_ioctl(struct lkst_maskset_getparam *param_user)
+{
+	struct lkst_maskset_getparam param;
+	int ret;
+	
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	
+	if (copy_from_user(&param, param_user, 
+			   sizeof(struct lkst_maskset_getparam))) {
+		DPRINTK("Reading fail at user memory address %p\n", param_user);
+		return -EINVAL;
+	}
+	
+	if (param.name[0] == '\0') {
+		return -EINVAL;
+	}
+	
+	ret = lkst_maskset_get_id(param.name);
+	if ( ret < 0 ) 
+		return ret;
+
+	param.id = ret;
+	if (copy_to_user(param_user, &param, 
+			 sizeof(struct lkst_maskset_getparam))) {
+		DPRINTK("Writing fail at user memory address %p\n", param_user);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* ioctl evhandler_list wrap function */
+static int lkst_evhandler_list_ioctl(struct lkst_evhandler_listparam *param_user)
+{
+	int retval = 0;
+	struct lkst_evhandler_listparam param;
+	struct lkst_evhandler_listent *listent;
+	struct lkst_evhandler_listent *user_listent;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user, 
+			   sizeof(struct lkst_evhandler_listparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+
+	if (param.listent_size <= 0 ||
+	    verify_area(VERIFY_WRITE, param.listent, param.listent_size)) {
+		LKST_DPRINTK("Invalid argument(listent/listent_size)\n");
+		return -EINVAL;
+	}
+	
+	user_listent = param.listent;
+	listent = vmalloc(param.listent_size);
+	if (listent == NULL) {
+		LKST_DPRINTK("Cannot allocate kernel memory : size=%d\n",
+			     param.listent_size);
+		return -ENOMEM;
+	}
+
+	param.listent = listent;
+
+	retval = lkst_evhandler_list_core(&param);
+
+	if (copy_to_user(user_listent, param.listent, param.listent_size)) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     user_listent);
+		return -EINVAL;
+	}
+
+	vfree(listent);
+
+	return retval;
+}
+
+/* ioctl evhandler_ctrl wrap function */
+static int lkst_evhandler_ctrl_ioctl(struct lkst_evhandler_ctrl_param *param_user)
+{
+	int retval = 0;
+	struct lkst_evhandler_ctrl_param param;
+	char *buf = NULL;
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user,
+			   sizeof(struct lkst_evhandler_ctrl_param))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+
+	if (param.bufsize < 0 ||
+	    verify_area(VERIFY_READ, param.buf, param.bufsize)) {
+		LKST_DPRINTK("Invalid argument(buf/bufsize)\n");
+		return -EINVAL;
+	}
+
+	if (param.bufsize != 0) {
+		buf = vmalloc(param.bufsize);
+		if (buf == NULL) {
+			LKST_DPRINTK("Cannot allocate kernel memory : "
+				     "size=%d\n", param.bufsize);
+			return -ENOMEM;
+		}
+
+		if (copy_from_user(buf, param.buf, param.bufsize)) {
+			LKST_DPRINTK("Reading fail at user memory address %p\n"
+				     , param.buf);
+			vfree(buf);
+			return -EINVAL;
+		}
+	}else 
+		buf = param.buf;
+
+	retval = lkst_evhandler_ctrl_core(param.id, buf, param.bufsize,
+					  &param.ret);
+
+	/* copy return value */
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_evhandler_ctrl_param))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		vfree(buf);
+		return -EINVAL;
+	}
+	/* copy contents of arguments */
+	if (param.bufsize != 0) {
+		if (copy_to_user(param.buf, buf, param.bufsize) ) {
+			LKST_DPRINTK("Writing fail at user memory address %p\n",
+				     param.buf);
+			retval = -EINVAL;
+		}
+		vfree(buf);
+	}
+	return retval;
+}
+
+/* ioctl evhandler_get_id wrap function */
+static int lkst_evhandler_get_id_ioctl(struct lkst_evhandler_getparam *param_user)
+{
+	struct lkst_evhandler_getparam param;
+	
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	
+	if (copy_from_user(&param, param_user, 
+			   sizeof(struct lkst_evhandler_getparam))) {
+		DPRINTK("Reading fail at user memory address %p\n", param_user);
+		return -EINVAL;
+	}
+	
+	if (param.name[0] == '\0') {
+		return -EINVAL;
+	}
+	
+	param.id = lkst_evhandler_get_id(param.name);
+	
+	if (copy_to_user(param_user, &param, 
+			 sizeof(struct lkst_evhandler_getparam))) {
+		DPRINTK("Writing fail at user memory address %p\n", param_user);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/* ioctl buffer_read wrap function */
+static int lkst_buffer_read_ioctl(struct lkst_log_buffer *lbuffer_user)
+{
+	int retval = 0;
+	struct lkst_log_buffer lbuffer;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&lbuffer, lbuffer_user,
+			   sizeof(struct lkst_log_buffer))) {
+	  	LKST_DPRINTK("Reading fail at user memory address %p\n", 
+			     lbuffer_user);
+		return -EINVAL;
+	}
+	if (lbuffer.read_size <= 0 ||
+	    verify_area(VERIFY_WRITE, lbuffer.buffer, lbuffer.read_size )) {
+		LKST_DPRINTK("Invalid argument(buffer/read_size)\n");
+		return -EINVAL;
+	}
+	
+	if ( lbuffer.id == LKST_BUFFER_ID_VOID && lbuffer.cpu != -1 ){
+		LKST_DPRINTK("Invalid argument(buffer id)\n");
+		return -EINVAL;
+	}
+	/*cpu migration*/{
+		unsigned long allowed;
+		if( lbuffer.id != LKST_BUFFER_ID_VOID ) {
+			if ( lkst_cpu_migrate_save(&allowed, lbuffer.cpu) < 0)
+				return -EINVAL;
+		}
+
+		lkst_current.reading++;/*read flag up*/
+		retval = lkst_buffer_read_one_to_user_core(
+				lbuffer.id, lbuffer.buffer, 
+				lbuffer.read_size/LKST_LOG_RECORD_BYTE);
+		if (retval >= 0) 
+			lbuffer.result_read_size = retval*LKST_LOG_RECORD_BYTE;
+		lkst_current.reading--;/*read flag down*/
+
+		if( lbuffer.id != LKST_BUFFER_ID_VOID ) {
+			lkst_cpu_migrate_restore(allowed);
+		}
+	}
+	lkst_log_header_read_inline(&lbuffer);
+	if (copy_to_user(lbuffer_user, &lbuffer,
+			 sizeof(struct lkst_log_buffer))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     lbuffer_user);
+		return -EINVAL;
+	}
+	return retval;
+}
+
+/* ioctl buffer_create wrap function */
+static int lkst_buffer_create_ioctl(struct lkst_buffer_param *param_user)
+{
+	int retval = 0;
+	struct lkst_buffer_param param;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user,
+			   sizeof(struct lkst_buffer_param))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	/*migrate cpu*/{
+		unsigned long allowed;
+	
+		if ( lkst_cpu_migrate_save(&allowed, param.cpu) < 0)
+			return -EINVAL;
+
+		retval = lkst_buffer_create_core(param.id, param.size, 
+						 param.next);
+		if (retval >= 0 && retval <= LKST_BUFFER_ID_MAX) {
+			struct lkst_event_buffer * buffer;
+			if (!LKST_BUFFER_LOAD(retval, buffer))
+				LKST_ENCOUNTER_A_BUG;//TODO
+			param.id = (lkst_buffer_id)retval;
+			param.result_size= buffer->size*LKST_EVENT_RECORD_BYTE;
+		}
+		lkst_cpu_migrate_restore(allowed);
+	}
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_buffer_param))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	return retval;
+}
+
+/* ioctl buffer_delete wrap function */
+static int lkst_buffer_delete_ioctl(struct lkst_buffer_delparam *user_param)
+{
+	struct lkst_buffer_delparam param;
+	int retval;
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	if (copy_from_user(&param, user_param, 
+			   sizeof(struct lkst_buffer_delparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     user_param);
+		return -EINVAL;
+	}
+	/*cpu migration*/{
+		unsigned long allowed;
+		if(lkst_cpu_migrate_save(&allowed,param.cpu)<0)
+			return -EINVAL;
+		retval = lkst_buffer_delete_core(param.id);
+		lkst_cpu_migrate_restore(allowed);
+	}
+	return retval;
+}
+
+/* ioctl buffer_shift wrap function */
+static int lkst_buffer_shift_ioctl(int cpu)
+{
+	int retval;
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	/*cpu migration*/{
+		unsigned long allowed;
+		if(lkst_cpu_migrate_save(&allowed, cpu)<0)
+			return -EINVAL;
+		retval = lkst_buffer_shift_core();
+		lkst_cpu_migrate_restore(allowed);
+	}
+	return retval;
+}
+
+/* ioctl buffer_jump wrap function */
+static int lkst_buffer_jump_ioctl(struct lkst_buffer_jumpparam *user_param)
+{
+	struct lkst_buffer_jumpparam param;
+	int retval;
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	if (copy_from_user(&param, user_param,
+			   sizeof(struct lkst_buffer_jumpparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     user_param);
+		return -EINVAL;
+	}
+	/*cpu migration*/{
+		unsigned long allowed;
+		if(lkst_cpu_migrate_save(&allowed, param.cpu)<0)
+			return -EINVAL;
+		retval = lkst_buffer_jump_core(param.dest);
+		lkst_cpu_migrate_restore(allowed);
+	}
+	return retval;
+}
+
+/* ioctl buffer_list wrap function */
+static int lkst_buffer_list_ioctl(struct lkst_buffer_listparam *user_param)
+{
+	int retval = 0;
+	struct lkst_buffer_listparam param;
+	struct lkst_buffer_listent *listent;
+	struct lkst_buffer_listent *user_listent;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, user_param,
+			   sizeof(struct lkst_buffer_listparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     user_param);
+		return -EINVAL;
+	}
+	if (param.listent_num < 0 ){
+		LKST_DPRINTK("Invalid argument(listent_num)\n");
+		return -EINVAL;
+	}
+	
+	if (param.listent_num > 0) {
+		if ( verify_area(VERIFY_WRITE, param.listent, 
+				 param.listent_num*
+				 sizeof(struct lkst_buffer_listent)) ){
+			LKST_DPRINTK("Invalid argument(listent)\n");
+			return -EINVAL;
+		}
+		user_listent = param.listent;
+		listent = vmalloc(param.listent_num*sizeof(struct lkst_buffer_listent));
+		if (listent == NULL) {
+			LKST_DPRINTK("Cannot allocate kernel memory : size=%d\n", 
+				     param.listent_num*sizeof(struct lkst_buffer_listent));
+			return -ENOMEM;
+		}
+	} else {
+		user_listent = NULL;
+		listent = NULL;
+	}
+	
+	/*migrate cpu*/{
+		unsigned long allowed;
+		if(lkst_cpu_migrate_save(&allowed, param.cpu)<0)
+			return -EINVAL;
+
+		param.listent = listent;
+		retval = lkst_buffer_list_core(&param);
+		
+		lkst_cpu_migrate_restore(allowed);
+	}
+	param.listent = user_listent;
+	if (copy_to_user(user_param, &param,
+			 sizeof(struct lkst_buffer_listparam))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     user_param);
+		return -EINVAL;
+	}
+	if (param.listent_num > 0) {
+		if (param.listent_num < param.buffer_num)
+			param.buffer_num = param.listent_num;
+		if (copy_to_user(user_listent, listent,
+				 param.buffer_num*sizeof(struct lkst_buffer_listent))){
+			LKST_DPRINTK("Writing fail at user memory address %p\n",
+				     user_listent);
+			return -EINVAL;
+		}
+		vfree(listent);
+	}
+
+	return retval;
+}
+
+/* ioctl buffer_link function */
+static int lkst_buffer_link_ioctl(struct lkst_buffer_linkparam *user_param)
+{
+	struct lkst_buffer_linkparam param;
+	int ret = 0;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	/* get user parameter */
+	if (copy_from_user(&param, user_param,
+			   sizeof(struct lkst_buffer_linkparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     user_param);
+		return -EINVAL;
+	}
+
+	if (param.id == param.next) {
+		LKST_DPRINTK("Source and Distinaion are same buffer.\n");
+		return -EINVAL;
+	}
+	
+	/*cpu migration*/{
+		unsigned long allowed;
+		struct lkst_event_buffer * buffer;
+		if(lkst_cpu_migrate_save(&allowed, param.cpu)<0)
+			return -EINVAL;
+		if ( LKST_BUFFER_LOAD(param.id, buffer)) {
+			buffer->next = param.next;
+		} else {
+			ret = -EINVAL;
+		}
+		lkst_cpu_migrate_restore(allowed);
+	}
+	return ret;
+}
+
+/* ioctl buffer_setrmod wrap function */
+static int lkst_buffer_setrmod_ioctl(struct lkst_buffer_srmodparam *param_user)
+{
+	int retval = 0;
+	struct lkst_buffer_srmodparam param;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&param, param_user,
+			   sizeof(struct lkst_buffer_srmodparam))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	retval = lkst_buffer_setrmod_core(&param);
+
+	if (copy_to_user(param_user, &param,
+			 sizeof(struct lkst_buffer_srmodparam))) {
+		LKST_DPRINTK("Writing fail at user memory address %p\n",
+			     param_user);
+		return -EINVAL;
+	}
+
+	return retval;
+}
+
+/* ioctl entry_log wrap function */
+static int lkst_entry_log_ioctl(struct lkst_entry_args *arg_user)
+{
+	struct lkst_entry_args arg;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&arg, arg_user, sizeof(struct lkst_entry_args))) {
+		LKST_DPRINTK("Reading fail at user memory address %p\n",
+			     arg_user);
+		return -EINVAL;
+	}
+
+	(void) lkst_entry_log(NULL, arg.event_type,
+			      arg.arg1, arg.arg2, arg.arg3, arg.arg4);
+
+	return (0);
+}
+
+/* LKST device open function */
+static int lkst_open(struct inode *inode, struct file *filp)
+{
+#ifdef CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+	int cpu = MINOR(inode->i_rdev) - 1;
+	int retval;
+	/* Instead of using setrmod, you can open /dev/lkst0-31 
+	 * those minor numbers are from 1 to 32, to read buffers
+	 * of each cpus.*/
+	/* But /dev/lkst remains for backward-compatibility and
+	 * general interface (for masksets/event-handlers)*/
+	if (cpu != -1 ) {
+		if (!lkst_cpu_is_online(cpu))
+			return -ENODEV;
+		retval = lkst_buffer_set_current_to_owner(cpu);
+		if (retval < 0)
+			return retval;
+
+		filp->private_data = (void *)((lkst_ptr_t)cpu);
+	}else 
+		filp->private_data = (void *)-1;
+		
+#endif /*CONFIG_DEBUG_LKST_DEVICE_PER_CPU*/
+
+
+#ifdef MODULE
+	/* Increment module reference count */
+	MOD_INC_USE_COUNT;
+#endif /* MODULE */
+	
+	return (0);
+}
+
+
+/* LKST device close function */
+static int lkst_close(struct inode *inode, struct file *filp)
+{
+
+	int i;
+#ifdef MODULE
+	/* Decrement module reference count */
+	MOD_DEC_USE_COUNT;
+#endif /* MODULE */
+
+	/* Clear owner pid of buffer list */
+	for (i = 0; i < LKST_CPU_MAX; i++) {
+		if (lkst_cpu[i].owner.pid == current->pid) {
+			lkst_cpu[i].owner.pid = PID_MAX + 1;
+			/* CPU unbinding */
+			lkst_cpu_migrate_restore(~0UL);
+			break;
+		}
+	}
+
+	return 0;
+}
+
+
+/* LKST device read function */
+static ssize_t lkst_read(struct file *filp, char *buf, 
+			 size_t count, loff_t *ppos)
+{
+	ssize_t read_count;
+	int retval;
+	
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (lkst_current.owner.pid != current->pid ) 
+		return -EBUSY;
+
+#ifdef CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+	if ( filp->private_data != (void *)-1 ) {
+		struct lkst_log_buffer_header *head;
+		
+		head = (struct lkst_log_buffer_header *) kmalloc (
+				sizeof(struct lkst_log_buffer_header),
+				GFP_KERNEL);
+		if (!head) return -ENOMEM;
+
+		/* setting up the header of log buffer*/
+		head->header.log_magic = LOGFILE_MAGIC;
+		head->header.log_version = 0;
+
+		head->entry.log_size =  2*sizeof(int) + 
+			sizeof(char)*LKST_ARCH_NAME_LEN;
+		head->entry.log_format = PXLOG_BINARY;
+
+		head->endian_big = lkst.endian_big;
+		head->buf_ver = lkst.buf_ver;
+		strncpy(head->arch, lkst.arch, LKST_ARCH_NAME_LEN);
+
+		/* copy to user space (header only) */
+		copy_to_user(buf, head, sizeof(struct lkst_log_buffer_header));
+		kfree(head);
+		
+		filp->private_data = (void *)-1;
+		return sizeof(head);
+	}
+#endif /*CONFIG_DEBUG_LKST_DEVICE_PER_CPU*/
+	
+	if (count < sizeof(struct lkst_log_record) || 
+	    verify_area(VERIFY_WRITE, buf, count)) {
+		LKST_DPRINTK("Invalid argument(buf/count)\n");
+		return -EINVAL;
+	}
+	count /= sizeof(struct lkst_log_record);
+	read_count = 0;
+
+	lkst_current.reading++;/*read flag up*/
+ read_retry:
+	retval = lkst_buffer_read_all_to_user_core(
+			(struct lkst_log_record *)buf,
+			(int)count);
+	if (retval > 0) read_count += retval;
+	if ((retval > 0 && retval < (int)count) || retval == -EAGAIN) {
+		if(!(filp->f_flags & O_NONBLOCK)){
+			lkst_current.owner.ready = 0;
+			interruptible_sleep_on(&lkst_current.owner.wait);
+			if (!signal_pending(current)) {
+				buf += retval*sizeof(struct lkst_log_record);
+				count -= retval;
+				goto read_retry;
+			}else {
+				/* We cannot rewind the read process.
+				 * But, at least, we can send read size
+				 * back to user process, instead of -EINTR.*/
+			}
+		}
+	} else if ( retval < 0 ){
+		lkst_current.reading--;/*read flag down*/
+		return retval;
+	}
+	lkst_current.reading--;/*read flag down*/
+	
+	read_count *= sizeof(struct lkst_log_record);
+	return read_count; /* we must return in byte*/
+}
+
+/* LKST device ioctl function */
+static int lkst_ioctl(struct inode *inode, struct file *filp,
+	       unsigned int request, unsigned long arg)
+{
+	int retval = 0;		/* return value */
+
+	switch (request) {
+	case LKST_IOC_TRC_STATUS:
+		retval = 
+		    lkst_trc_status_ioctl((struct lkst_status_param *) arg);
+		break;
+	case LKST_IOC_TRC_START:
+		retval = lkst_trc_start_ioctl();
+		break;
+	case LKST_IOC_TRC_STOP:
+		retval = lkst_trc_stop_ioctl();
+		break;
+	case LKST_IOC_MASKSET_READ:
+		retval =
+		    lkst_maskset_read_ioctl((struct lkst_maskset_param *) arg);
+		break;
+	case LKST_IOC_MASKSET_WRITE:
+		retval =
+		   lkst_maskset_write_ioctl((struct lkst_maskset_param *) arg);
+		break;
+	case LKST_IOC_MASKSET_SET:
+		retval = lkst_maskset_set_ioctl((lkst_maskset_id) arg);
+		break;
+	case LKST_IOC_MASKSET_LIST:
+		retval =
+		    lkst_maskset_list_ioctl((struct lkst_maskset_listparam *) arg);
+		break;
+	case LKST_IOC_MASKSET_DELETE:
+		retval = lkst_maskset_delete_ioctl((lkst_maskset_id) arg);
+		break;
+	case LKST_IOC_EVHANDLER_LIST:
+		retval =
+		    lkst_evhandler_list_ioctl((struct lkst_evhandler_listparam *) arg);
+		break;
+	case LKST_IOC_EVHANDLER_CTRL:
+		retval =
+		    lkst_evhandler_ctrl_ioctl((struct lkst_evhandler_ctrl_param *) arg);
+		break;
+
+	case LKST_IOC_BUFFER_READ:
+		retval = 
+		    lkst_buffer_read_ioctl((struct lkst_log_buffer *) arg);
+		break;
+	case LKST_IOC_BUFFER_CREATE:
+		retval =
+		    lkst_buffer_create_ioctl((struct lkst_buffer_param *) arg);
+		break;
+	case LKST_IOC_BUFFER_SHIFT:
+		retval = lkst_buffer_shift_ioctl((int)arg);
+		break;
+	case LKST_IOC_BUFFER_JUMP:
+		retval = lkst_buffer_jump_ioctl((struct lkst_buffer_jumpparam *)arg);
+		break;
+	case LKST_IOC_BUFFER_DELETE:
+		retval = lkst_buffer_delete_ioctl((struct lkst_buffer_delparam*) arg);
+		break;
+	case LKST_IOC_BUFFER_LIST:
+		retval = lkst_buffer_list_ioctl((struct lkst_buffer_listparam *) arg);
+		break;
+	case LKST_IOC_BUFFER_LINK:
+		retval = lkst_buffer_link_ioctl((struct lkst_buffer_linkparam *) arg);
+		break;
+	case LKST_IOC_BUFFER_SETRMOD:
+		retval = lkst_buffer_setrmod_ioctl((struct lkst_buffer_srmodparam *) arg);
+		break;
+
+	case LKST_IOC_ENTRY_LOG:
+		retval =
+		    lkst_entry_log_ioctl((struct lkst_entry_args *) arg);
+		break;
+	case LKST_IOC_MASKSET_GETID:
+		retval = lkst_maskset_get_id_ioctl(
+				(struct lkst_maskset_getparam *) arg);
+		break;
+	case LKST_IOC_EVHANDLER_GETID:
+		retval = lkst_evhandler_get_id_ioctl(
+				(struct lkst_evhandler_getparam *) arg);
+		break;
+	default:
+		LKST_DPRINTK("Invalid command no.%d\n", request);
+		return -EINVAL;
+	}
+
+	return retval;
+}
+
+/*********************************************************************
+ * Initialize/cleanup functions
+ *********************************************************************/
+/*
+ * function lkst_trc_init_stage0
+ * Initialize the first part of Kernel State Tracer.
+ * This function initializes data not concerned with SMP.
+ * 
+ *  Arguments
+ *    NONE
+ *  returns
+ *    NONE
+ * 
+ */
+void lkst_trc_init_stage0()
+{
+	int i;
+
+	if ( lkst_init_flag != LKST_NOT_INIT) LKST_ENCOUNTER_A_BUG; 
+
+	/* The following values are initialized when kernel was loaded,
+	 *   lkst_cpu[...].recid = 1;
+	 *   maskset_rnothing[], maskset_rall[], maskset_rdefault[]
+	 */
+
+	printk("LKST: Starting initialization stage0\n");
+
+	/* initialize global header */{
+
+		/* Initialize LKST header time stamp */
+		lkst_time_set(0);
+		
+		spin_lock_init(&lkst_maskset_lock);
+		spin_lock_init(&lkst_evhandler_lock);
+
+		/* Clean up maskset table */
+		LKST_POINTER_STORE(lkst.current_masksetp, NULL);
+		lkst.current_maskset_id = 0;
+		lkst.maskset_id_saved = LKST_MASKSET_ID_RDEFAULT;
+		for ( i = 0 ;i < LKST_MASKSET_TBL_MAX ; i++) {
+			lkst.maskset_table[i].name[0] = '\0';
+			LKST_POINTER_STORE(
+				lkst.maskset_table[i].masksetp, NULL);
+		}
+		
+		/* Clean up evhandler table */
+		for ( i = 0 ;i < LKST_EVHANDLER_TBL_MAX ; i++) {
+			lkst.evhandler_table[i].name[0] = '\0';
+			LKST_POINTER_STORE(
+				lkst.evhandler_table[i].evhandler, NULL);
+			LKST_POINTER_STORE(
+				lkst.evhandler_table[i].evhandler_ctrl, NULL);
+		}
+		
+		/* set current buffer */
+		atomic_set(&lkst.static_buffer.recid, 0);
+		/* clear recid, event_type */
+		for (i = 0; i < LKST_STATIC_BUFFER_COUNT; i++) {
+			LKST_STATIC_BUFFER_BODY()[i].log_recid = 0;
+			LKST_STATIC_BUFFER_BODY()[i].log_event_type = 
+				LKST_ETYPE_VOID;
+		}
+	}
+	
+	/* initialize percpu header */
+	for (i = 0; i < LKST_CPU_MAX; i++) {
+		lkst_cpu[i].cpu = i;
+		lkst_cpu[i].owner.pid = PID_MAX + 1;
+		lkst_cpu[i].owner.wait = (wait_queue_head_t)
+			__WAIT_QUEUE_HEAD_INITIALIZER(lkst_cpu[i].owner.wait);
+		lkst_cpu[i].owner.read_buf = LKST_BUFFER_ID_VOID;
+		lkst_cpu[i].rq_head = LKST_BUFFER_ID_VOID;
+		lkst_cpu[i].rq_tail = LKST_BUFFER_ID_VOID;
+		lkst_cpu[i].write_buf = LKST_BUFFER_ID_VOID;
+	}
+#if DEBUG
+	if (LKST_SIZEOF_LKST_EVENT_RECORD == sizeof(struct lkst_event_record)) {
+		/* Verification of LKST_SIZEOF_LKST_EVENT_RECORD is failed. */
+		printk(KERN_ERR "LKST error(init):"
+		       " sizeof(struct lkst_event_record) is not equal to LKST_SIZEOF_LKST_EVENT_RECORD.\n");
+		return;
+	}
+#endif /* DEBUG */
+
+	/* registering masksets & evhandlers */{
+		spin_lock(&lkst_evhandler_lock);
+		spin_lock(&lkst_maskset_lock);
+		
+		/* Setup nothing recording maskset */
+		LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+					     LKST_MASKSET_ID_RNOTHING,
+					     LKST_MASKSET_NAME_RNOTHING,
+					     maskset_rnothing);
+		/* And set that currently using maskset */
+		LKST_MASKSET_SET_CURRENT(LKST_MASKSET_ID_RNOTHING);
+		
+		
+		/* Initialize Default Event Handler */
+		lkst_evhandler_register_core_nl(LKST_EVHANDLER_ID_DEFAULT,
+						LKST_EVHANDLER_NAME_DEFAULT,
+						lkst_evhandler_default,
+						lkst_evhandler_default_ctrl);
+		
+		/* Initialize Buffer Shift Event Handler */
+		lkst_evhandler_register_core_nl(LKST_EVHANDLER_ID_BUFFER_SHIFT,
+						LKST_EVHANDLER_NAME_BUFFER_SHIFT,
+						lkst_evhandler_buffer_shift,
+						NULL);
+		
+#if DEBUG
+		/* Initialize Exception Event Handler */
+		lkst_evhandler_register_core_nl(LKST_EVHANDLER_ID_EXCEPTION,
+						LKST_EVHANDLER_NAME_EXCEPTION,
+						lkst_evhandler_exception,
+						NULL);
+#endif /* DEBUG */
+		/* Initialize Shifting buffer And Awaking Daemon Event Handler 
+		 This remains for backward compatibility */
+		lkst_evhandler_register_core_nl(LKST_EVHANDLER_ID_BUFFER_SHIFT_DW,
+						LKST_EVHANDLER_NAME_BUFFER_SHIFT_DW,
+						lkst_evhandler_buffer_shift_wakeup,
+						NULL);
+		
+		/* Initialize Logging static buffer Event Handler */
+		lkst_evhandler_register_core_nl(LKST_EVHANDLER_ID_LOG_STATIC,
+						LKST_EVHANDLER_NAME_LOG_STATIC,
+						lkst_evhandler_log_static,
+						NULL);
+		
+		/* Setup other special masksets */
+		LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+					     LKST_MASKSET_ID_RALL,
+					     LKST_MASKSET_NAME_RALL,
+					     maskset_rall);
+		LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+					     LKST_MASKSET_ID_RDEFAULT,
+					     LKST_MASKSET_NAME_RDEFAULT,
+					     maskset_rdefault);
+		
+		/* Clear entries for other masksets */
+		for (i = 3; i < LKST_MASKSET_TBL_MAX; i++) {
+			LKST_POINTER_STORE(lkst.maskset_table[i].masksetp,
+					   NULL);
+		}
+		/* Temporarily modify MASKSET_RALL to a maskset log to static buffer*/
+		for (i = 0; i < LKST_ETYPE_MAX; i++) {
+			if (maskset_rall[i] != LKST_EVHANDLER_ID_VOID)
+				maskset_rall[i] = LKST_EVHANDLER_ID_LOG_STATIC;
+		}
+		
+		/* GKHI initialization will invoked automatically now. */
+		/* Initialize hook table used by lkst */
+		lkst_trc_hook_init();
+
+		/* Setup current maskset pointer (stage0 special maskset)*/
+		lkst_hook_maskset_xchg(LKST_MASKSET_ID_RALL,
+				       lkst.current_maskset_id);
+		LKST_MASKSET_SET_CURRENT(LKST_MASKSET_ID_RALL);
+
+		spin_unlock(&lkst_maskset_lock);		
+		spin_unlock(&lkst_evhandler_lock);
+	}
+
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_INIT, 
+		       LKST_ARG(0x0001), 0, 0, 0);
+
+	/* SysRq key bind */
+#ifdef CONFIG_MAGIC_SYSRQ
+	register_sysrq_key('v', &sysrq_lkst_dump_buffer_op);
+#endif /* CONFIG_MAGIC_SYSRQ */
+
+	/* register Dump notifier (if available)*/
+#if defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)
+	register_dump_notifier(&dump_nb);
+#endif /*defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)*/
+
+	/* LKST initialize flag on */
+	lkst_init_flag = LKST_INIT_LEVEL_0;
+
+	printk("LKST: Initialization stage0 finished\n");
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_INIT, 
+		       LKST_ARG(0x00ff), 0, 0, 0);
+}
+
+
+/*
+ * function lkst_trc_init_stage1
+ * Initialize the second part of Kernel State Tracer.
+ * This function initializes buffers, pointers and
+ * data concernd with SMP. Therefore, this should be
+ * called after all of the CPUs are initialized.
+ * 
+ *  Arguments
+ *    NONE
+ *  returns
+ *    NONE
+ * 
+ */
+void lkst_trc_init_stage1()
+{
+	int i;
+	struct lkst_event_buffer *buffer;
+
+	if ( lkst_init_flag != LKST_INIT_LEVEL_0) LKST_ENCOUNTER_A_BUG;
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_INIT, LKST_ARG(0x0101), 0, 0, 0);
+
+	printk("LKST: Starting initialization stage1\n");
+
+	/* Set architecture name */
+	strncpy(lkst.arch, system_utsname.machine, 65); 
+
+	/* Set cpu frequency */
+	lkst.cpu_freq = cpu_khz;
+	lkst_time_set(0);
+
+	/* */
+	
+	/* allocate event buffer for all CPUs */
+	for (i = 0; i < smp_num_cpus; i++) {
+		printk("LKST: event buffer allocation CPU=%d\n", i);
+
+		buffer = lkst_buffer_create_instance_inline(lkst_init_buffer_size,
+							    LKST_BUFFER_ID_VOID,
+							    i);
+		buffer->id = 0;
+		LKST_POINTER_STORE(lkst_cpu[i].buffer_table[0].ptr,buffer);
+
+		/* set current buffer */
+		lkst_cpu[i].write_buf = 0;
+		/* enqueue current buffer */
+		lkst_cpu[i].rq_head = 0;
+		lkst_cpu[i].rq_tail = 0;
+	}
+	
+	/* get locks */ {
+		spin_lock(&lkst_evhandler_lock);
+		spin_lock(&lkst_maskset_lock);
+		
+
+		/* Switch to default maskset from log-static-buffer maskset */
+		if (lkst_init_maskset != lkst.current_maskset_id) {
+			/* Reset current maskset pointer */
+			lkst_hook_maskset_xchg((lkst_maskset_id)lkst_init_maskset,
+					       lkst.current_maskset_id);
+			LKST_MASKSET_SET_CURRENT((lkst_maskset_id)lkst_init_maskset);
+		}
+
+		/* Recovery MASKSET_RALL */
+		for (i = 0; i < LKST_ETYPE_MAX; i++) {
+			maskset_rall[i] = LKST_EVHANDLER_ID_DEFAULT;
+		}
+		maskset_rall[LKST_ETYPE_LKST_BUFF_OVFLOW] = LKST_EVHANDLER_ID_VOID;
+		
+		if (lkst_init_maskset == lkst.current_maskset_id) {
+			lkst_hook_reset_all();
+		}
+		
+		/*release locks*/
+		spin_unlock(&lkst_maskset_lock);
+		spin_unlock(&lkst_evhandler_lock);
+	}
+	// TODO: device special file must be created automatically.
+	/* register LKST device file_operations */
+#ifdef CONFIG_DEVFS_FS
+	if (devfs_register_chrdev(LKST_DEV_MAJOR, LKST_DEV_NAME, &lkst_fops))
+		printk(KERN_ERR "LKST warning(init):cannot register LKST *conventional* device!\n");
+#else
+	if (register_chrdev(LKST_DEV_MAJOR, LKST_DEV_NAME, &lkst_fops))
+		printk(KERN_ERR "LKST error(init):cannot register LKST device!\n");
+#endif
+
+#ifdef CONFIG_DEVFS_FS
+        lkst_devfs_handle = devfs_register (NULL, LKST_DEV_NAME,
+					    DEVFS_FL_DEFAULT,
+					    LKST_DEV_MAJOR, LKST_DEV_MINOR,
+					    S_IFCHR | S_IRUSR | S_IWUSR,
+					    &lkst_fops, NULL);
+	if ( lkst_devfs_handle == NULL )
+		printk(KERN_ERR "LKST error(init):cannot register LKST devfs device!\n");
+#ifdef CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+	for ( i=0; i<LKST_CPU_MAX; i++) {/* for Hotplug CPU...*/
+		char devname[32];
+		sprintf(devname, "%s%d", LKST_DEV_NAME, i);
+		lkst_devfs_handle_cpu[i] = devfs_register (NULL, devname,
+							   DEVFS_FL_DEFAULT,
+							   LKST_DEV_MAJOR, i+1,
+							   S_IFCHR | S_IRUSR | S_IWUSR,
+							   &lkst_fops, NULL);
+		if ( lkst_devfs_handle_cpu[i] == NULL )
+			printk(KERN_ERR "LKST error(init):cannot register LKST devfs device!\n");		
+	}
+#endif /*CONFIG_DEBUG_LKST_DEVICE_PER_CPU*/
+#endif
+
+	/* LKST initialize flag on */
+	lkst_init_flag = LKST_INIT_LEVEL_1;
+
+	printk("LKST: initialization stage1 finished\n");
+
+	/* LKST internal event */
+	lkst_entry_log(NULL, LKST_ETYPE_LKST_INIT, LKST_ARG(0x10ff), 0, 0, 0);
+}
+
+
+/*
+ * function lkst_trc_init_main
+ * Initialize basic part of Kernel State Tracer.
+ * This function is called from /init/main.c. and lkst_init_module
+ */
+void lkst_trc_init_main()
+{
+#ifndef	CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START
+	lkst_trc_init_stage0();
+#endif /* !CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START */
+	lkst_trc_init_stage1();
+}
+
+#ifdef MODULE
+static int __init lkst_init_module(void)
+{
+	size_t size;
+
+	printk("LKST: start LKST module.\n");
+
+	/* buffer size check */
+	printk("LKST: initial event buffer size=" LKST_FMT_SZT "\n", (size_t)lkst_init_buffer_size);
+	if (lkst_init_buffer_size < LKST_BUFFER_SIZE_MIN) {
+		printk(KERN_ERR "LKST warning(init): buffer size(=" LKST_FMT_SZT ") is too small, changed to " LKST_FMT_SZT "\n", (size_t)lkst_init_buffer_size, (size_t)LKST_BUFFER_SIZE_MIN);
+		lkst_init_buffer_size = LKST_BUFFER_SIZE_MIN;
+	} else if (lkst_init_buffer_size > LKST_BUFFER_SIZE_MAX) {
+		printk(KERN_ERR "LKST warning(init): buffer size(=" LKST_FMT_SZT ") is too large, changed to " LKST_FMT_SZT "\n", (size_t)lkst_init_buffer_size, (size_t)LKST_BUFFER_SIZE_MAX);
+		lkst_init_buffer_size = LKST_BUFFER_SIZE_MAX;
+	}
+	size = lkst_init_buffer_size;
+	if ( size & ~LKST_BUFFER_PAGE_MASK ) size+=LKST_BUFFER_PAGE_BYTE;
+	size &= LKST_BUFFER_PAGE_MASK;
+	if (lkst_init_buffer_size != size)
+		printk(KERN_ERR "LKST warning(init): buffer size must be times of page size, changed to " LKST_FMT_SZT "\n", (size_t)size);
+	lkst_init_buffer_size = size;
+
+	/* maskset id check */
+	printk("LKST: initial maskset id = %d\n", lkst_init_maskset);
+	if (lkst_init_maskset < 0 || lkst_init_maskset > 3){
+		printk(KERN_ERR "LKST warning(init): initial maskset id is off limited. set default value\n");
+		lkst_init_maskset = LKST_MASKSET_ID_RDEFAULT;
+	}
+	lkst_trc_init_main();
+	return 0;
+}
+
+static void __exit lkst_cleanup_module(void)
+{
+	int i,j;
+
+	/* unregister LKST device file_operations */
+#ifdef CONFIG_DEVFS_FS
+	if (devfs_unregister_chrdev(LKST_DEV_MAJOR, LKST_DEV_NAME))
+#else
+	if (unregister_chrdev(LKST_DEV_MAJOR, LKST_DEV_NAME))
+#endif
+		printk(KERN_ERR "LKST error :cannot unregister LKST device!\n");
+
+#ifdef CONFIG_DEVFS_FS
+        devfs_unregister ( lkst_devfs_handle );
+#ifdef CONFIG_DEBUG_LKST_DEVICE_PER_CPU
+	for ( i=0; i<LKST_CPU_MAX; i++) {/* for Hotplug CPU...*/
+		devfs_unregister ( lkst_devfs_handle_cpu[i] );
+	}
+#endif /*CONFIG_DEBUG_LKST_DEVICE_PER_CPU*/
+#endif
+
+	/* deregister Dump notifier (if available)*/
+#if defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)
+	unregister_dump_notifier(&dump_nb);
+#endif /*defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)*/
+
+#ifdef CONFIG_MAGIC_SYSRQ
+	unregister_sysrq_key('v', &sysrq_lkst_dump_buffer_op);
+#endif /* CONFIG_MAGIC_SYSRQ */
+
+	spin_lock(&lkst_evhandler_lock);
+	spin_lock(&lkst_maskset_lock);
+	
+	/* Setup current maskset pointer to RNOTHING */
+	lkst_hook_maskset_xchg(LKST_MASKSET_ID_RNOTHING,
+			       lkst.current_maskset_id);
+	LKST_MASKSET_SET_CURRENT(LKST_MASKSET_ID_RNOTHING);
+	
+	/* GKHI hook cleanup */
+	lkst_trc_hook_cleanup();
+
+	/* Cleanup additional maskset pointer & Free */
+	for (i = 3; i < LKST_MASKSET_TBL_MAX; i++) {
+		lkst_maskset * masksetp;
+		if (LKST_POINTER_LOAD(lkst.maskset_table[i].masksetp,
+				      masksetp)) {
+			vfree(masksetp);
+			LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table, i,
+						     "", NULL);
+		}
+	}
+	/* Cleanup default maskset pointer (except RNOTHING)*/
+	LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+				     LKST_MASKSET_ID_RALL, "", NULL);
+	LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+				     LKST_MASKSET_ID_RDEFAULT, "", NULL);
+
+	/* Cleanup event handler */
+	for (i = 0; i < LKST_EVHANDLER_TBL_MAX; i++) {
+		lkst_evhandler_unregister_core_nl(i);
+	}
+
+	/* Cleanup RNOTHING maskset pointer */
+	LKST_MASKSET_TABLE_ENTRY_SET(lkst.maskset_table,
+				     LKST_MASKSET_ID_RNOTHING, "", NULL);
+	LKST_POINTER_STORE(lkst.current_masksetp, NULL);
+
+	spin_unlock(&lkst_maskset_lock);
+	spin_unlock(&lkst_evhandler_lock);
+
+	/* Cleanup event buffer_table & Deallcation event buffer */
+	for (i = 0; i < LKST_BUFFER_TBL_MAX; i++) {
+		struct lkst_event_buffer * bufferp;
+		for ( j = 0 ; j < LKST_CPU_MAX; j++) {
+			if (LKST_POINTER_LOAD(lkst_cpu[j].buffer_table[i].ptr,
+					      bufferp) ) {
+				vfree(bufferp);
+				LKST_POINTER_STORE(lkst_cpu[j].buffer_table[i].ptr,
+						   NULL);
+			}
+		}
+	}
+
+	atomic_set(&lkst.static_buffer.recid, 0);
+
+	/* Cleanup current buffer */
+	for (i = 0; i < LKST_CPU_MAX; i++) {
+		lkst_cpu[i].rq_head = LKST_BUFFER_ID_VOID;
+		lkst_cpu[i].rq_tail = LKST_BUFFER_ID_VOID;
+		lkst_cpu[i].write_buf = LKST_BUFFER_ID_VOID;
+	}
+
+	/* LKST initialize flag off */
+	lkst_init_flag = LKST_NOT_INIT;
+
+	/* deallocation complete */
+}
+
+module_init(lkst_init_module);
+module_exit(lkst_cleanup_module);
+MODULE_AUTHOR("LKST project");
+MODULE_DESCRIPTION("Linux Kernel State Trace driver");
+MODULE_LICENSE("GPL");
+MODULE_PARM(lkst_init_buffer_size, "i");
+MODULE_PARM_DESC(lkst_init_buffer_size, "Default size of each buffer(4096-0x200000, in times of 4k)");
+MODULE_PARM(lkst_init_maskset, "i");
+MODULE_PARM_DESC(lkst_init_maskset, "a maskset id used in starting up.[0-2]");
+#endif /* MODULE */
diff -Naru linux-2.4.19/fs/buffer.c linux-2.4.19-lkst/fs/buffer.c
--- linux-2.4.19/fs/buffer.c	2003-04-14 15:02:47.000000000 -0400
+++ linux-2.4.19-lkst/fs/buffer.c	2003-04-14 15:05:06.000000000 -0400
@@ -54,6 +54,8 @@
 #include <asm/bitops.h>
 #include <asm/mmu_context.h>
 
+#include <linux/lkst.h>
+
 #define NR_RESERVED (10*MAX_BUF_PER_PAGE)
 #define MAX_UNUSED_BUFFERS NR_RESERVED+20 /* don't ever have more than this 
 					     number of unused buffer heads */
@@ -151,6 +153,12 @@
 	struct task_struct *tsk = current;
 	DECLARE_WAITQUEUE(wait, tsk);
 
+	LKST_HOOK(LKST_ETYPE_FS_BUFBUSY,
+		       LKST_ARGP(bh),
+		       LKST_ARG(0),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	get_bh(bh);
 	add_wait_queue(&bh->b_wait, &wait);
 	do {
@@ -171,6 +179,12 @@
  */
 void end_buffer_io_sync(struct buffer_head *bh, int uptodate)
 {
+	LKST_HOOK(LKST_ETYPE_FS_DEVEND,
+		       LKST_ARGP(bh),
+		       LKST_ARG(uptodate),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	mark_buffer_uptodate(bh, uptodate);
 	unlock_buffer(bh);
 	put_bh(bh);
diff -Naru linux-2.4.19/include/asm-i386/io.h linux-2.4.19-lkst/include/asm-i386/io.h
--- linux-2.4.19/include/asm-i386/io.h	2003-04-14 15:03:03.000000000 -0400
+++ linux-2.4.19-lkst/include/asm-i386/io.h	2003-04-14 15:05:22.000000000 -0400
@@ -3,6 +3,8 @@
 
 #include <linux/config.h>
 
+#include <linux/lkst.h>
+
 /*
  * This file contains the definitions for the x86 IO instructions
  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
diff -Naru linux-2.4.19/include/asm-i386/lkst.h linux-2.4.19-lkst/include/asm-i386/lkst.h
--- linux-2.4.19/include/asm-i386/lkst.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-i386/lkst.h	2003-04-14 15:05:22.000000000 -0400
@@ -0,0 +1,56 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by T.Nakamura <tetsu@crl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _ARCH_I386_LKST_H
+#define _ARCH_I386_LKST_H
+
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else /*!__KERNEL__*/
+# include <sys/types.h>
+#endif /*!__KERNEL__*/
+
+#define LKST_BIG_ENDIAN	0
+
+typedef unsigned int lkst_ptr_t;
+#define LKST_ARGP(ptr)							\
+	((lkst_arg_t) ((lkst_ptr_t)(ptr)))
+
+/* buffer size -- must be times of 4k */
+#define LKST_BUFFER_SIZE_DEFAULT	(64*1024)		/* 64kBytes*/
+#define LKST_BUFFER_SIZE_MAX		(64*1024*1024)		/* 64MBytes*/
+#define LKST_BUFFER_SIZE_MIN		(8192)			/* 8kBytes */
+
+typedef	unsigned long	lkst_cpu_freq_t;
+typedef	u_int64_t 	lkst_tsc_t;
+
+
+#ifdef __KERNEL__
+
+	/* This is ugly fix for arch/i386/boot/compressed/misc.c */
+#ifdef LKST_SUPPRESS_PIO_TRACE
+
+#define LKST_ENTRY_LOG_PIO_OUT(portaddr,bw,val,calladdr)
+#define LKST_ENTRY_LOG_PIO_IN(portaddr,bw,val,calladdr)
+
+#else  /* i.e., !ifdef LKST_SUPPRESS_PIO_TRACE */
+
+#define LKST_ENTRY_LOG_PIO_OUT(portaddr,bw,val,calladdr)\
+  LKST_HOOK_INLINE(LKST_ETYPE_O_PORTOUT, LKST_ARG(portaddr),\
+		LKST_ARG(bw), LKST_ARG(val), LKST_ARGP(calladdr));
+#define LKST_ENTRY_LOG_PIO_IN(portaddr,bw,val,calladdr)\
+  LKST_HOOK_INLINE(LKST_ETYPE_O_PORTIN, LKST_ARG(portaddr),\
+		LKST_ARG(bw), LKST_ARG(val,0), LKST_ARGP(calladdr));
+
+#endif /* ifdef LKST_SUPPRESS_PIO_TRACE */
+
+#endif /*__KERNEL__*/
+
+#endif /* _ARCH_I386_LKST_H */
diff -Naru linux-2.4.19/include/asm-i386/lkst_events.h linux-2.4.19-lkst/include/asm-i386/lkst_events.h
--- linux-2.4.19/include/asm-i386/lkst_events.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-i386/lkst_events.h	2003-04-14 15:05:22.000000000 -0400
@@ -0,0 +1,67 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by M.Hiramatsu <hiramatu@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+/* i386 architecture dependant events */
+/* Do not check double (or more) including.
+ This file will be included many times.*/
+
+LKST_ETYPE_DEF(0x030, 0x03, NORMAL, SYSCALL_ENTRY, SYSCALL_ENTRY,                   \
+        //0x030 event
+        "system_call_entry",                                                        \
+         0,                                                                         \
+        "call number",                                                              \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x031, 0x03, NORMAL, SYSCALL_EXIT, SYSCALL_EXIT,                     \
+        //0x031 event
+        "system_call_exit",                                                         \
+         0,                                                                         \
+        "call number",                                                              \
+        "return value(errno)",                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0x020, 0x02, INLINE, EXCEPTION_ENTRY, EXCEPTION_ENTRY,               \
+        //0x020 event
+        "exception_entry",                                                          \
+         0,                                                                         \
+        "exception-handler address(edi)",                                           \
+        "error code(esi)",                                                          \
+        "exception address(if exist)",                                              \
+         NULL)
+LKST_ETYPE_DEF(0x021, 0x02, INLINE, EXCEPTION_EXIT, EXCEPTION_EXIT,                 \
+        //0x021 event
+        "exception_exit",                                                           \
+         0,                                                                         \
+        "exception-handler address(edi)",                                           \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x0b0, 0x0a, NORMAL, OOPS_PGFAULT, OOPS_PGFAULT,                     \
+        //0x0b0 event
+        "page_fault_oops",                                                          \
+         0,                                                                         \
+        "accessed virtual address",                                                 \
+        "fault code address",                                                       \
+        "error code",                                                               \
+         NULL)
+#ifdef CONFIG_X86_LOCAL_APIC
+LKST_ETYPE_DEF(0x0b1, 0x0a, NORMAL, OOPS_NMIWDOG, OOPS_NMIWDOG,                     \
+        //0x0b1 event
+        "nmi_watchdog_oops",                                                        \
+         0,                                                                         \
+        "current lockup address",                                                   \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+#endif /*CONFIG_X86_LOCAL_APIC*/
+
+
diff -Naru linux-2.4.19/include/asm-i386/lkst_private.h linux-2.4.19-lkst/include/asm-i386/lkst_private.h
--- linux-2.4.19/include/asm-i386/lkst_private.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-i386/lkst_private.h	2003-04-14 15:05:22.000000000 -0400
@@ -0,0 +1,91 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by T.Nakamura <tetsu@crl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _ARCH_I386_LKST_PRIVATE_H
+#define _ARCH_I386_LKST_PRIVATE_H
+
+#include <asm/lkst.h>
+
+/* This must be compatible with "void *" */
+typedef lkst_ptr_t lkst_pointer_check_digit;
+#define LKST_POINTER_CHECK_MAGIC	((lkst_pointer_check_digit)0x3c695a0f)
+
+#define LKST_AVAILABLE_MEMORY_MAX	(1024*1024*1024)	/* dummy */
+
+#ifdef __KERNEL__
+#include <asm/msr.h>
+#include <asm/atomic.h>
+#include <asm/timex.h>		/* for cpu_khz */
+
+/* format strings for printk() */
+#define LKST_FMT_TSC	"%016llu"	/* lkst_tsc_t */
+#define LKST_FMT_SZT	"%u"		/* size_t */
+
+/**
+ * atomic_read_and_inc - read and increment atomic variable
+ * @v: pointer of type atomic_t
+ * 
+ * Atomically increments @v by 1.  Note that the guaranteed
+ * useful range of an atomic_t is only 24 bits.
+ */
+
+static __inline__ int atomic_read_and_add(int i, atomic_t * v)
+{
+	__asm__ __volatile__(LOCK "xadd %1,%0":"+m"(v->counter), "=r"(i)
+			     :"0"(v->counter), "1"(i):"memory");
+	return (i);
+}
+
+/**
+ * local_atomic_read_and_inc - read and increment a variable on local processor
+ * @v: pointer of type int. 
+ * 
+ * Atomically increments @cnt by 1.
+ */
+static __inline__ int local_atomic_read_and_add(int i, int *v)
+{
+	__asm__ __volatile__("xadd %1,%0":"+m"(*v), "=r"(i)
+			     :"0"(*v), "1"(i):"memory");
+	return (i);
+}
+
+/*
+ * function lkst_evhandlerprim_mc()
+ * A primitive part of an Event-handler. This function returns current
+ * value of machine-cycle-counter.
+ * 
+ *  Arguments
+ *    NONE
+ *
+ *  returns
+ *    tsc:	current value of machine-cycle-counter.
+ * 
+ */
+static __inline__ lkst_tsc_t lkst_evhandlerprim_mc(void)
+{
+	register lkst_tsc_t tsc;
+
+	/* Read the Time Stamp Counter */
+	rdtscll(tsc);
+	return tsc;
+}
+
+
+/*
+ * get variable "cpu_khz".
+ */
+#define	LKST_GET_CPU_KHZ() ((lkst_cpu_freq_t)cpu_khz)
+
+#define LKST_LIMIT_ADDRESS_CHECK(buffer, size, limit)			\
+	( (lkst_ptr_t)((char *) buffer + size) <= (lkst_ptr_t)limit)
+
+#endif /*__KERNEL__*/
+
+#endif /* _ARCH_I386_LKST_PRIVATE_H */
diff -Naru linux-2.4.19/include/asm-i386/spinlock.h linux-2.4.19-lkst/include/asm-i386/spinlock.h
--- linux-2.4.19/include/asm-i386/spinlock.h	2003-04-14 15:03:03.000000000 -0400
+++ linux-2.4.19-lkst/include/asm-i386/spinlock.h	2003-04-14 15:05:22.000000000 -0400
@@ -5,6 +5,7 @@
 #include <asm/rwlock.h>
 #include <asm/page.h>
 #include <linux/config.h>
+#include <linux/lkst.h>
 
 extern int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2)));
@@ -52,10 +53,59 @@
 #define spin_is_locked(x)	(*(volatile char *)(&(x)->lock) <= 0)
 #define spin_unlock_wait(x)	do { barrier(); } while(spin_is_locked(x))
 
+/*
+ * LKST_SPIN_LOCK_STRING
+ */
+
+
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || \
+	     defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) && \
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE) && \
+		defined(CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME) && \
+		!defined(_IN_LINUX_LKST_H)
+
+#define LKST_SPIN_LOCK_STRING_HOOK \
+	"movl LKST_ETYPE_LK_SPINLOCK_HEADER_head+16, %%eax\n\t" \
+	"testl %%eax, %%eax\n\t" \
+	"jns 4f\n\t" \
+	"movl $(LKST_ETYPE_LK_SPINLOCK_HEADER_head), %%eax\n\t" \
+	"pushl $0\n\t" \
+	"pushl $0\n\t" \
+	"pushl $0\n\t" \
+	"pushl $0\n\t" \
+	"pushl $0\n\t" \
+	"pushl %1\n\t" \
+	"pushl $0\n\t" \
+	"pushl %2\n\t" \
+	"pushl $128\n\t" \
+	"pushl 8(%%eax)\n\t" \
+	"call *(%%eax)\n\t" \
+	"addl $40, %%esp\n" \
+	"4:\n\t"
+
+#define LKST_SPIN_LOCK_STRING1 \
+        "lock ; decb %0\n\t" \
+        "jns 3f\n\t" \
+        LKST_SPIN_LOCK_STRING_HOOK \
+        "jmp 2f\n"
+
+#define LKST_SPIN_LOCK_STRING2 \
+        "3:\n"
+
+#else
+
+#define LKST_SPIN_LOCK_STRING1 ""
+#define LKST_SPIN_LOCK_STRING2 ""
+
+#endif
+
+
 #define spin_lock_string \
+        LKST_SPIN_LOCK_STRING1 \
 	"\n1:\t" \
 	"lock ; decb %0\n\t" \
 	"js 2f\n" \
+        LKST_SPIN_LOCK_STRING2 \
 	LOCK_SECTION_START("") \
 	"2:\t" \
 	"cmpb $0,%0\n\t" \
@@ -85,6 +135,11 @@
 	if (!spin_is_locked(lock))
 		BUG();
 #endif
+#ifndef _IN_LINUX_LKST_H
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINUNLOCK,
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(lock),
+		LKST_ARG(0), LKST_ARG(0));
+#endif /* !_IN_LINUX_LKST_H */
 	__asm__ __volatile__(
 		spin_unlock_string
 	);
@@ -106,6 +161,11 @@
 	if (!spin_is_locked(lock))
 		BUG();
 #endif
+#ifndef _IN_LINUX_LKST_H
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINUNLOCK,
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(lock),
+		LKST_ARG(0), LKST_ARG(0));
+#endif /* !_IN_LINUX_LKST_H */
 	__asm__ __volatile__(
 		spin_unlock_string
 	);
@@ -120,6 +180,11 @@
 		"xchgb %b0,%1"
 		:"=q" (oldval), "=m" (lock->lock)
 		:"0" (0) : "memory");
+#ifndef _IN_LINUX_LKST_H
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINTRYLOCK,
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(lock),
+		LKST_ARG((oldval > 0)), LKST_ARG(0));
+#endif /* !_IN_LINUX_LKST_H */
 	return oldval > 0;
 }
 
@@ -133,9 +198,24 @@
 		BUG();
 	}
 #endif
+#if !defined(CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME)
+#if !defined( _IN_LINUX_LKST_H)
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINLOCK,
+		       LKST_ARGP(lkst_current_pc()), LKST_ARGP(lock),
+		       LKST_ARG(0), LKST_ARG(0));
+#endif /*!_IN_LINUX_LKST_H*/
+	__asm__ __volatile__(
+		spin_lock_string
+		:"=m" (lock->lock) :: "memory" );
+#else /* CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME*/
+	__label__ lkst_here;
+ lkst_here:
 	__asm__ __volatile__(
 		spin_lock_string
-		:"=m" (lock->lock) : : "memory");
+		:"=m" (lock->lock)
+		:"g"(lock), "g"(&&lkst_here)
+		: "memory","%eax","%ecx","%edx");
+#endif /* !CONFIG_DEBUG_LKST_SPINLOCK_HOOK_ONE_TIME*/
 }
 
 
@@ -185,6 +265,11 @@
 	if (rw->magic != RWLOCK_MAGIC)
 		BUG();
 #endif
+#ifndef _IN_LINUX_LKST_H
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_RDLOCK,
+		       LKST_ARGP(lkst_current_pc()), LKST_ARGP(rw),
+		       LKST_ARG(0), LKST_ARG(0));
+#endif /* !_IN_LINUX_LKST_H */
 	__build_read_lock(rw, "__read_lock_failed");
 }
 
@@ -194,19 +279,57 @@
 	if (rw->magic != RWLOCK_MAGIC)
 		BUG();
 #endif
+#ifndef _IN_LINUX_LKST_H
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_WRLOCK,
+		       LKST_ARGP(lkst_current_pc()), LKST_ARGP(rw),
+		       LKST_ARG(0), LKST_ARG(0));
+#endif /* !_IN_LINUX_LKST_H */
 	__build_write_lock(rw, "__write_lock_failed");
 }
 
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) && !defined(_IN_LINUX_LKST_H)
+#define read_unlock(rw)		{	\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_RDUNLOCK, \
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(rw), \
+		LKST_ARG(0), LKST_ARG(0));\
+	asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory"); }
+#else /* !CONFIG_DEBUG_KERNEL_STATE_TRACE || _IN_LINUX_LKST_H */
 #define read_unlock(rw)		asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory")
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE && !_IN_LINUX_LKST_H */
+
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) && !defined(_IN_LINUX_LKST_H)
+#define write_unlock(rw)		{	\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_WRUNLOCK, \
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(rw), \
+		LKST_ARG(0), LKST_ARG(0)); \
+	asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0":"=m" ((rw)->lock) : : "memory"); }
+#else /* !CONFIG_DEBUG_KERNEL_STATE_TRACE || _IN_LINUX_LKST_H */
 #define write_unlock(rw)	asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0":"=m" ((rw)->lock) : : "memory")
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE && !_IN_LINUX_LKST_H */
 
 static inline int write_trylock(rwlock_t *lock)
 {
 	atomic_t *count = (atomic_t *)lock;
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) || defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) && !defined(_IN_LINUX_LKST_H)
+	int	locked = 0;
+
+	if (atomic_sub_and_test(RW_LOCK_BIAS, count)) {
+		locked	= 1;
+	}
+	else {
+		atomic_add(RW_LOCK_BIAS, count);
+		locked	= 0;
+	}
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_WRTRYLOCK,
+		LKST_ARGP(lkst_current_pc()), LKST_ARGP(lock),
+		LKST_ARG(locked), LKST_ARG(0));
+	return (locked);
+#else /* !CONFIG_DEBUG_KERNEL_STATE_TRACE || _IN_LINUX_LKST_H */
 	if (atomic_sub_and_test(RW_LOCK_BIAS, count))
 		return 1;
 	atomic_add(RW_LOCK_BIAS, count);
 	return 0;
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE && !_IN_LINUX_LKST_H */
 }
 
 #endif /* __ASM_SPINLOCK_H */
diff -Naru linux-2.4.19/include/asm-ia64/io.h linux-2.4.19-lkst/include/asm-ia64/io.h
--- linux-2.4.19/include/asm-ia64/io.h	2003-04-14 15:03:16.000000000 -0400
+++ linux-2.4.19-lkst/include/asm-ia64/io.h	2003-04-14 15:05:35.000000000 -0400
@@ -1,6 +1,10 @@
 #ifndef _ASM_IA64_IO_H
 #define _ASM_IA64_IO_H
 
+#include <linux/config.h>
+
+#include <linux/lkst.h>
+
 /*
  * This file contains the definitions for the emulated IO instructions
  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
@@ -101,6 +105,9 @@
 	volatile unsigned char *addr = __ia64_mk_io_addr(port);
 	unsigned char ret;
 
+	LKST_ENTRY_LOG_PIO_IN(port, sizeof(unsigned char), addr,
+			      __builtin_return_address(0));
+
 	ret = *addr;
 	__ia64_mf_a();
 	return ret;
@@ -112,6 +119,9 @@
 	volatile unsigned short *addr = __ia64_mk_io_addr(port);
 	unsigned short ret;
 
+	LKST_ENTRY_LOG_PIO_IN(port, sizeof(unsigned short), addr,
+			      __builtin_return_address(0));
+
 	ret = *addr;
 	__ia64_mf_a();
 	return ret;
@@ -123,6 +133,9 @@
 	volatile unsigned int *addr = __ia64_mk_io_addr(port);
 	unsigned int ret;
 
+	LKST_ENTRY_LOG_PIO_IN(port, sizeof(unsigned int), addr,
+			      __builtin_return_address(0));
+
 	ret = *addr;
 	__ia64_mf_a();
 	return ret;
@@ -133,6 +146,9 @@
 {
 	volatile unsigned char *addr = __ia64_mk_io_addr(port);
 
+	LKST_ENTRY_LOG_PIO_OUT(port, sizeof(val), addr,
+			       __builtin_return_address(0));
+
 	*addr = val;
 	__ia64_mf_a();
 }
@@ -142,6 +158,9 @@
 {
 	volatile unsigned short *addr = __ia64_mk_io_addr(port);
 
+	LKST_ENTRY_LOG_PIO_OUT(port, sizeof(val), addr,
+			       __builtin_return_address(0));
+
 	*addr = val;
 	__ia64_mf_a();
 }
@@ -151,6 +170,9 @@
 {
 	volatile unsigned int *addr = __ia64_mk_io_addr(port);
 
+	LKST_ENTRY_LOG_PIO_OUT(port, sizeof(val), addr,
+			       __builtin_return_address(0));
+
 	*addr = val;
 	__ia64_mf_a();
 }
@@ -163,13 +185,19 @@
 	if (platform_inb == __ia64_inb) {
 		volatile unsigned char *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_IN(port, count, addr,
+				      __builtin_return_address(0));
+
 		__ia64_mf_a();
 		while (count--)
 			*dp++ = *addr;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_IN(port, count, 0,
+				      __builtin_return_address(0));
 		while (count--)
 			*dp++ = platform_inb(port);
+	}
 	return;
 }
 
@@ -181,13 +209,19 @@
 	if (platform_inw == __ia64_inw) {
 		volatile unsigned short *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_IN(port, count, addr,
+				      __builtin_return_address(0));
+
 		__ia64_mf_a();
 		while (count--)
 			*dp++ = *addr;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_IN(port, count, 0,
+				      __builtin_return_address(0));
 		while (count--)
 			*dp++ = platform_inw(port);
+	}
 	return;
 }
 
@@ -199,13 +233,19 @@
 	if (platform_inl == __ia64_inl) {
 		volatile unsigned int *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_IN(port, count, addr,
+				      __builtin_return_address(0));
+
 		__ia64_mf_a();
 		while (count--)
 			*dp++ = *addr;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_IN(port, count, 0,
+				      __builtin_return_address(0));
 		while (count--)
 			*dp++ = platform_inl(port);
+	}
 	return;
 }
 
@@ -217,12 +257,18 @@
 	if (platform_outb == __ia64_outb) {
 		volatile unsigned char *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_OUT(port, count, addr,
+				       __builtin_return_address(0));
+
 		while (count--)
 			*addr = *sp++;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_OUT(port, count, 0,
+				       __builtin_return_address(0));
 		while (count--)
 			platform_outb(*sp++, port);
+	}
 	return;
 }
 
@@ -234,12 +280,18 @@
 	if (platform_outw == __ia64_outw) {
 		volatile unsigned short *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_OUT(port, count, addr,
+				       __builtin_return_address(0));
+
 		while (count--)
 			*addr = *sp++;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_OUT(port, count, 0,
+				       __builtin_return_address(0));
 		while (count--)
 			platform_outw(*sp++, port);
+	}
 	return;
 }
 
@@ -251,12 +303,18 @@
 	if (platform_outl == __ia64_outl) {
 		volatile unsigned int *addr = __ia64_mk_io_addr(port);
 
+		LKST_ENTRY_LOG_PIO_OUT(port, count, addr,
+				       __builtin_return_address(0));
+
 		while (count--)
 			*addr = *sp++;
 		__ia64_mf_a();
-	} else
+	} else {
+		LKST_ENTRY_LOG_PIO_OUT(port, count, 0,
+				       __builtin_return_address(0));
 		while (count--)
 			platform_outl(*sp++, port);
+	}
 	return;
 }
 
diff -Naru linux-2.4.19/include/asm-ia64/lkst.h linux-2.4.19-lkst/include/asm-ia64/lkst.h
--- linux-2.4.19/include/asm-ia64/lkst.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-ia64/lkst.h	2003-04-14 15:05:37.000000000 -0400
@@ -0,0 +1,68 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ ************************************************************/
+
+#ifndef _ARCH_IA64_LKST_H
+#define _ARCH_IA64_LKST_H
+
+#ifdef __KERNEL__
+# include <linux/types.h>
+#else /*!__KERNEL__*/
+# include <sys/types.h>
+#endif /*!__KERNEL__*/
+#include <asm/page.h>
+
+#define LKST_BIG_ENDIAN	0
+
+typedef unsigned long lkst_ptr_t;
+#define LKST_ARGP(ptr)							\
+	((lkst_arg_t) ((lkst_ptr_t)(ptr)))
+
+/* buffer size -- must be times of pagesize */
+#define LKST_BUFFER_SIZE_DEFAULT	((size_t)(1*1024*1024))		/* 1MBytes*/
+#define LKST_BUFFER_SIZE_MAX		((size_t)(1*1024*1024*1024))	/* 1GBytes*/
+#define LKST_BUFFER_SIZE_MIN		((size_t)(PAGE_SIZE))		/* 8k/16k/64kBytes */
+
+typedef	unsigned long	lkst_cpu_freq_t;
+typedef	u_int64_t 	lkst_tsc_t;
+
+
+#ifdef __KERNEL__
+
+extern void lkst_ia64_syscall_entry(u_long, u_long, u_long, u_long);
+extern void lkst_ia64_syscall_exit(u_long, u_long, u_long, u_long);
+
+/* IA64 specific definition */
+#define lkst_current_pc() \
+	({ void *pc; asm volatile ("mov %0=ip" : "=r" (pc)); pc; })
+
+	/* This is ugly fix for arch/i386/boot/compressed/misc.c */
+#ifdef LKST_SUPPRESS_PIO_TRACE
+
+#define LKST_ENTRY_LOG_PIO_OUT(portaddr,bw,val,calladdr)
+#define LKST_ENTRY_LOG_PIO_IN(portaddr,bw,val,calladdr)
+
+#else  /* i.e., !ifdef LKST_SUPPRESS_PIO_TRACE */
+
+#define LKST_ENTRY_LOG_PIO_OUT(portaddr,bw,val,calladdr)	\
+	LKST_HOOK_INLINE(LKST_ETYPE_O_PORTOUT,			\
+			LKST_ARG(portaddr),			\
+			LKST_ARG(bw),				\
+			LKST_ARG(val),				\
+			LKST_ARG(calladdr));
+#define LKST_ENTRY_LOG_PIO_IN(portaddr,bw,val,calladdr)		\
+	LKST_HOOK_INLINE(LKST_ETYPE_O_PORTIN,			\
+			LKST_ARG(portaddr),			\
+			LKST_ARG(bw),				\
+			LKST_ARG(val),				\
+			LKST_ARG(calladdr));
+
+#endif /* ifdef LKST_SUPPRESS_PIO_TRACE */
+
+#endif /*__KERNEL__*/
+
+#endif /* _ARCH_IA64_LKST_H */
diff -Naru linux-2.4.19/include/asm-ia64/lkst_events.h linux-2.4.19-lkst/include/asm-ia64/lkst_events.h
--- linux-2.4.19/include/asm-ia64/lkst_events.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-ia64/lkst_events.h	2003-04-14 15:05:37.000000000 -0400
@@ -0,0 +1,119 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by M.Hiramatsu <hiramatu@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+/* IA64 architecture dependant events */
+/* Do not check double (or more) including.
+ This file will be included many times.*/
+
+LKST_ETYPE_DEF(0x030, 0x03, NORMAL, SYSCALL_ENTRY, SYSCALL_ENTRY,                   \
+        //0x030 event
+        "system_call_entry",                                                        \
+         0,                                                                         \
+        "handler address",                                                          \
+        "call number",                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x031, 0x03, NORMAL, SYSCALL_EXIT, SYSCALL_EXIT,                     \
+        //0x031 event
+        "system_call_exit",                                                         \
+         0,                                                                         \
+        "handler address",                                                          \
+        "return value(errno)",                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0x020, 0x02, NORMAL, EXCEPT_PGFLT_ENTRY, EXCEPT_PGFLT_ENTRY,         \
+        //0x020 event
+        "except_pgflt_entry",                                                       \
+         0,                                                                         \
+        "fault address(ifa)",                                                       \
+        "isr",                                                                      \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x021, 0x02, NORMAL, EXCEPT_PGFLT_EXIT, EXCEPT_PGFLT_EXIT,           \
+        //0x021 event
+        "except_pgflt_exit",                                                        \
+         0,                                                                         \
+        "fault address(ifa)",                                                       \
+        "isr",                                                                      \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x022, 0x02, NORMAL, EXCEPT_ILLOP_ENTRY, EXCEPT_ILLOP_ENTRY,         \
+        //0x022 event
+        "except_illop_entry",                                                       \
+         0,                                                                         \
+        "ec",                                                                       \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x023, 0x02, NORMAL, EXCEPT_ILLOP_EXIT, EXCEPT_ILLOP_EXIT,           \
+        //0x023 event
+        "except_illop_exit",                                                        \
+         0,                                                                         \
+        "ec",                                                                       \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x024, 0x02, NORMAL, EXCEPT_BADBRK_ENTRY, EXCEPT_BADBRK_ENTRY,       \
+        //0x024 event
+        "except_badbrk_entry",                                                      \
+         0,                                                                         \
+        "break number(iim)",                                                        \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x025, 0x02, NORMAL, EXCEPT_BADBRK_EXIT, EXCEPT_BADBRK_EXIT,         \
+        //0x025 event
+        "except_badbrk_exit",                                                       \
+         0,                                                                         \
+        "break number(iim)",                                                        \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x026, 0x02, NORMAL, EXCEPT_FAULT_ENTRY, EXCEPT_FAULT_ENTRY,         \
+        //0x026 event
+        "except_fault_entry",                                                       \
+         0,                                                                         \
+        "fault vector number",                                                      \
+        "isr",                                                                      \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x027, 0x02, NORMAL, EXCEPT_FAULT_EXIT, EXCEPT_FAULT_EXIT,           \
+        //0x027 event
+        "except_fault_exit",                                                        \
+         0,                                                                         \
+        "fault vector number",                                                      \
+        "isr",                                                                      \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x028, 0x02, NORMAL, EXCEPT_UNALIGN_ENTRY, EXCEPT_UNALIGN_ENTRY,     \
+        //0x028 event
+        "except_unalign_entry",                                                     \
+         0,                                                                         \
+        "ifa",                                                                      \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x029, 0x02, NORMAL, EXCEPT_UNALIGN_EXIT, EXCEPT_UNALIGN_EXIT,       \
+        //0x029 event
+        "except_unalign_exit",                                                      \
+         0,                                                                         \
+        "ifa",                                                                      \
+        "NULL",                                                                     \
+        "ipsr",                                                                     \
+        "iip")
+LKST_ETYPE_DEF(0x0b0, 0x0a, NORMAL, OOPS_PGFAULT, OOPS_PGFAULT,                     \
+        //0x0b0 event
+        "page_fault_oops",                                                          \
+         0,                                                                         \
+        "accessed virtual address",                                                 \
+        "fault code address",                                                       \
+        "error code",                                                               \
+         NULL)
diff -Naru linux-2.4.19/include/asm-ia64/lkst_private.h linux-2.4.19-lkst/include/asm-ia64/lkst_private.h
--- linux-2.4.19/include/asm-ia64/lkst_private.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/asm-ia64/lkst_private.h	2003-04-14 15:05:37.000000000 -0400
@@ -0,0 +1,85 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ ************************************************************/
+
+#ifndef _ARCH_IA64_LKST_PRIVATE_H
+#define _ARCH_IA64_LKST_PRIVATE_H
+
+#include <asm/lkst.h>
+
+typedef lkst_ptr_t lkst_pointer_check_digit;
+#define LKST_POINTER_CHECK_MAGIC ((lkst_pointer_check_digit)0x3c695a0f3c695a0f)
+
+#define LKST_AVAILABLE_MEMORY_MAX	(64UL*1024*1024*1024)	/* 64GB */
+
+#ifdef __KERNEL__
+#include <asm/atomic.h>
+#include <asm/timex.h>		/* for get_cycles() */
+
+/* format strings for printk() */
+#define LKST_FMT_TSC	"%016lu"	/* lkst_tsc_t */
+#define LKST_FMT_SZT	"%lu"		/* size_t */
+
+/**
+ * atomic_read_and_add - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ * 
+ * Atomically adds @i to @v.  Note that the guaranteed
+ * useful range of an atomic_t is only 24 bits.
+ */
+
+static __inline__ int
+atomic_read_and_add (int i, atomic_t *v)
+{
+	__s32 old, new;
+	CMPXCHG_BUGCHECK_DECL
+
+	do {
+		CMPXCHG_BUGCHECK(v);
+		old = atomic_read(v);
+		new = old + i;
+	} while (ia64_cmpxchg("acq", v, old, old + i, sizeof(atomic_t)) != old);
+
+	return old;
+}
+
+
+/*
+ * function lkst_evhandlerprim_mc()
+ * A primitive part of an Event-handler. This function returns current
+ * value of machine-cycle-counter.
+ * 
+ *  Arguments
+ *    NONE
+ *
+ *  returns
+ *    tsc:	current value of machine-cycle-counter.
+ * 
+ */
+static __inline__ u_int64_t lkst_evhandlerprim_mc(void)
+{
+	__u64 itc;
+
+	/* Read the Interval Timer Counter */
+	__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(itc));
+
+	return itc;
+}
+
+
+/*
+ * get variable "cpu's khz".
+ */
+#define	LKST_GET_CPU_KHZ() ((lkst_cpu_freq_t)(local_cpu_data->itc_freq / 1000))
+
+#define LKST_LIMIT_ADDRESS_CHECK(buffer, size, limit)			\
+	(((void *) ((char *) buffer + size)) <= limit)
+
+#endif /*__KERNEL__*/
+
+#endif /* _ARCH_IA64_LKST_PRIVATE_H */
diff -Naru linux-2.4.19/include/asm-ia64/spinlock.h linux-2.4.19-lkst/include/asm-ia64/spinlock.h
--- linux-2.4.19/include/asm-ia64/spinlock.h	2003-04-14 15:03:16.000000000 -0400
+++ linux-2.4.19-lkst/include/asm-ia64/spinlock.h	2003-04-14 15:05:34.000000000 -0400
@@ -9,12 +9,15 @@
  * This file is used for SMP configurations only.
  */
 
+#include <linux/config.h>
 #include <linux/kernel.h>
 
 #include <asm/system.h>
 #include <asm/bitops.h>
 #include <asm/atomic.h>
 
+#include <linux/lkst.h>
+
 #undef NEW_LOCK
 
 #ifdef NEW_LOCK
@@ -31,6 +34,33 @@
  * rather than a simple xchg to avoid writing the cache-line when
  * there is contention.
  */
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_lock(x)							\
+({									\
+    register char *addr __asm__ ("r31") = (char *) &(x)->lock;		\
+									\
+    LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINLOCK,				\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(x),					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+									\
+    __asm__ __volatile__ (						\
+	"mov r30=1\n"							\
+	"mov ar.ccv=r0\n"						\
+	";;\n"								\
+	"cmpxchg4.acq r30=[%0],r30,ar.ccv\n"				\
+	";;\n"								\
+	"cmp.ne p15,p0=r30,r0\n"					\
+	"(p15) br.call.spnt.few b7=ia64_spinlock_contention\n"		\
+	";;\n"								\
+	"1:\n"				/* force a new bundle */	\
+	:: "r"(addr)							\
+	: "ar.ccv", "ar.pfs", "b7", "p15", "r28", "r29", "r30", "memory");\
+})
+#else
 #define spin_lock(x)									\
 {											\
 	register char *addr __asm__ ("r31") = (char *) &(x)->lock;			\
@@ -48,7 +78,30 @@
 		:: "r"(addr)								\
 		: "ar.ccv", "ar.pfs", "b7", "p15", "r28", "r29", "r30", "memory");	\
 }
+#endif
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_trylock(x)							\
+({									\
+    register long result;						\
+									\
+    __asm__ __volatile__ (						\
+	"mov ar.ccv=r0\n"						\
+	";;\n"								\
+	"cmpxchg4.acq %0=[%2],%1,ar.ccv\n"				\
+	: "=r"(result) : "r"(1), "r"(&(x)->lock) : "ar.ccv", "memory");	\
+									\
+    LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINTRYLOCK,				\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(x),					\
+			LKST_ARG((result == 0)),			\
+			LKST_ARG(0));					\
+									\
+    (result == 0);							\
+})
+#else
 #define spin_trylock(x)									\
 ({											\
 	register long result;								\
@@ -60,9 +113,30 @@
 		: "=r"(result) : "r"(1), "r"(&(x)->lock) : "ar.ccv", "memory");		\
 	(result == 0);									\
 })
+#endif
 
 #define spin_is_locked(x)	((x)->lock != 0)
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_unlock(x)							\
+({									\
+	do {								\
+		barrier();						\
+		((spinlock_t *) x)->lock = 0;				\
+	} while (0);							\
+									\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINUNLOCK,			\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(x),					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+})
+#else
 #define spin_unlock(x)		do { barrier(); ((spinlock_t *) x)->lock = 0;} while (0)
+#endif
+
 #define spin_unlock_wait(x)	do { barrier(); } while ((x)->lock)
 
 #else /* !NEW_LOCK */
@@ -79,6 +153,34 @@
  * rather than a simple xchg to avoid writing the cache-line when
  * there is contention.
  */
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_lock(x)						\
+({								\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINLOCK,		\
+			LKST_ARG(lkst_current_pc()),		\
+			LKST_ARG(x),				\
+			LKST_ARG(0),				\
+			LKST_ARG(0));				\
+								\
+	 __asm__ __volatile__ (					\
+	"mov ar.ccv = r0\n"					\
+	"mov r29 = 1\n"						\
+	";;\n"							\
+	"1:\n"							\
+	"ld4.bias r2 = [%0]\n"					\
+	";;\n"							\
+	"cmp4.eq p0,p7 = r0,r2\n"				\
+	"(p7) br.cond.spnt.few 1b \n"				\
+	"cmpxchg4.acq r2 = [%0], r29, ar.ccv\n"			\
+	";;\n"							\
+	"cmp4.eq p0,p7 = r0, r2\n"				\
+	"(p7) br.cond.spnt.few 1b\n"				\
+	";;\n"							\
+	:: "r"(&(x)->lock) : "ar.ccv","p7","r2","r29","memory");\
+})
+#else
 #define spin_lock(x) __asm__ __volatile__ (			\
 	"mov ar.ccv = r0\n"					\
 	"mov r29 = 1\n"						\
@@ -94,10 +196,51 @@
 	"(p7) br.cond.spnt.few 1b\n"				\
 	";;\n"							\
 	:: "r"(&(x)->lock) : "ar.ccv", "p7", "r2", "r29", "memory")
+#endif
 
 #define spin_is_locked(x)	((x)->lock != 0)
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_unlock(x)						\
+({								\
+	do {							\
+		barrier();					\
+		((spinlock_t *) x)->lock = 0;			\
+	} while (0);						\
+								\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINUNLOCK,		\
+			LKST_ARG(lkst_current_pc()),		\
+			LKST_ARG(x),				\
+			LKST_ARG(0),				\
+			LKST_ARG(0));				\
+})
+#else
 #define spin_unlock(x)		do { barrier(); ((spinlock_t *) x)->lock = 0; } while (0)
+#endif
+
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define spin_trylock(x)							\
+({									\
+		register long result;					\
+									\
+		result = cmpxchg_acq(&(x)->lock, 0, 1);			\
+									\
+		LKST_HOOK_INLINE(LKST_ETYPE_LK_SPINTRYLOCK,		\
+				LKST_ARG(lkst_current_pc()),		\
+				LKST_ARG(x),				\
+				LKST_ARG((result == 0)),		\
+				LKST_ARG(0));				\
+									\
+		(result == 0);						\
+})
+#else
 #define spin_trylock(x)		(cmpxchg_acq(&(x)->lock, 0, 1) == 0)
+#endif
+
 #define spin_unlock_wait(x)	do { barrier(); } while ((x)->lock)
 
 #endif /* !NEW_LOCK */
@@ -110,6 +253,37 @@
 
 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define read_lock(rw)							\
+do {									\
+	int tmp = 0;							\
+									\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_RDLOCK, 				\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(rw), 					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+									\
+	__asm__ __volatile__ ("1:\tfetchadd4.acq %0 = [%1], 1\n"	\
+			      ";;\n"					\
+			      "tbit.nz p6,p0 = %0, 31\n"		\
+			      "(p6) br.cond.sptk.few 2f\n"		\
+			      ".section .text.lock,\"ax\"\n"		\
+			      "2:\tfetchadd4.rel %0 = [%1], -1\n"	\
+			      ";;\n"					\
+			      "3:\tld4.acq %0 = [%1]\n"			\
+			      ";;\n"					\
+			      "tbit.nz p6,p0 = %0, 31\n"		\
+			      "(p6) br.cond.sptk.few 3b\n"		\
+			      "br.cond.sptk.few 1b\n"			\
+			      ";;\n"					\
+			      ".previous\n"				\
+			      : "=&r" (tmp)				\
+			      : "r" (rw) : "p6", "memory");		\
+} while(0)
+#else
 #define read_lock(rw)								\
 do {										\
 	int tmp = 0;								\
@@ -130,7 +304,27 @@
 			      : "=&r" (tmp)					\
 			      : "r" (rw) : "p6", "memory");			\
 } while(0)
+#endif
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define read_unlock(rw)							\
+do {									\
+	int tmp = 0;							\
+									\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_RDUNLOCK,			\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(rw),					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+									\
+	__asm__ __volatile__ ("fetchadd4.rel %0 = [%1], -1\n"		\
+			      : "=r" (tmp)				\
+			      : "r" (rw)				\
+			      : "memory");				\
+} while(0)
+#else
 #define read_unlock(rw)								\
 do {										\
 	int tmp = 0;								\
@@ -139,7 +333,37 @@
 			      : "r" (rw)					\
 			      : "memory");					\
 } while(0)
+#endif
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define write_lock(rw)							\
+do {									\
+									\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_WRLOCK,				\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(rw),					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+									\
+ 	__asm__ __volatile__ (						\
+		"mov ar.ccv = r0\n"					\
+		"dep r29 = -1, r0, 31, 1\n"				\
+		";;\n"							\
+		"1:\n"							\
+		"ld4 r2 = [%0]\n"					\
+		";;\n"							\
+		"cmp4.eq p0,p7 = r0,r2\n"				\
+		"(p7) br.cond.spnt.few 1b \n"				\
+		"cmpxchg4.acq r2 = [%0], r29, ar.ccv\n"			\
+		";;\n"							\
+		"cmp4.eq p0,p7 = r0, r2\n"				\
+		"(p7) br.cond.spnt.few 1b\n"				\
+		";;\n"							\
+		:: "r"(rw) : "ar.ccv", "p7", "r2", "r29", "memory");	\
+} while(0)
+#else
 #define write_lock(rw)								\
 do {										\
  	__asm__ __volatile__ (							\
@@ -158,11 +382,29 @@
 		";;\n"								\
 		:: "r"(rw) : "ar.ccv", "p7", "r2", "r29", "memory");		\
 } while(0)
+#endif
 
+#if ( defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||			\
+		defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) ) &&	\
+			!defined(_IN_LINUX_LKST_H)
+#define write_unlock(x)							\
+({									\
+	LKST_HOOK_INLINE(LKST_ETYPE_LK_WRUNLOCK,			\
+			LKST_ARG(lkst_current_pc()),			\
+			LKST_ARG(x),					\
+			LKST_ARG(0),					\
+			LKST_ARG(0));					\
+									\
+	/* need barrier before releasing lock... */			\
+	smp_mb__before_clear_bit();					\
+	clear_bit(31, (x));						\
+})
+#else
 #define write_unlock(x)									\
 ({											\
 	smp_mb__before_clear_bit();	/* need barrier before releasing lock... */	\
 	clear_bit(31, (x));								\
 })
+#endif
 
 #endif /*  _ASM_IA64_SPINLOCK_H */
diff -Naru linux-2.4.19/include/linux/hook.h linux-2.4.19-lkst/include/linux/hook.h
--- linux-2.4.19/include/linux/hook.h	2003-04-14 15:03:03.000000000 -0400
+++ linux-2.4.19-lkst/include/linux/hook.h	2003-04-14 15:05:21.000000000 -0400
@@ -8,7 +8,7 @@
  */
 #include <linux/compiler.h>
 #include <linux/module.h>
-#include <linux/proc_fs.h>
+//#include <linux/proc_fs.h> 
 
 /*
  * Use the DECLARE_HOOK_HEAD macro to define the hookhead structure in global 
diff -Naru linux-2.4.19/include/linux/lkst.h linux-2.4.19-lkst/include/linux/lkst.h
--- linux-2.4.19/include/linux/lkst.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst.h	2003-04-21 11:19:42.000000000 -0400
@@ -0,0 +1,331 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.SERIZAWA <serizawa@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _LINUX_LKST_H
+#define _LINUX_LKST_H
+
+/* event types */
+#include <linux/lkst_events.h>
+
+#ifdef __KERNEL__
+# ifdef CONFIG_HIGHMEM64G
+#  include <asm/system.h>
+# endif
+# include <linux/types.h>
+#define _IN_LINUX_LKST_H
+struct proc_dir_entry;
+#include <linux/hook.h>
+typedef hook_t hook_head_t;
+#undef _IN_LINUX_LKST_H
+#endif				/* __KERNEL__ */
+#include <linux/threads.h>
+#include <linux/ioctl.h>
+
+#include <asm/lkst.h>
+
+/* LKST version */
+#define LKST_VERSION_MAJOR	1
+#define LKST_VERSION_MINOR	5
+#define LKST_VERSION_REVISION	0
+#define LKST_VERSION_STR	"1.5"
+
+/* Max number of CPUs */
+#define LKST_CPU_MAX	32
+
+/* ioctl requests */
+#define LKST_IOC_MAGIC			'l'
+#define LKST_IOC_TRC_STATUS		_IO(LKST_IOC_MAGIC, 1)
+#define LKST_IOC_TRC_START		_IO(LKST_IOC_MAGIC, 2)
+#define LKST_IOC_TRC_STOP		_IO(LKST_IOC_MAGIC, 3)
+
+#define LKST_IOC_MASKSET_READ		_IO(LKST_IOC_MAGIC, 4)
+#define LKST_IOC_MASKSET_WRITE		_IO(LKST_IOC_MAGIC, 5)
+#define LKST_IOC_MASKSET_SET		_IO(LKST_IOC_MAGIC, 6)
+#define LKST_IOC_MASKSET_LIST		_IO(LKST_IOC_MAGIC, 7)
+#define LKST_IOC_MASKSET_DELETE		_IO(LKST_IOC_MAGIC, 8)
+
+#define LKST_IOC_EVHANDLER_LIST		_IO(LKST_IOC_MAGIC, 9)
+#define LKST_IOC_EVHANDLER_CTRL		_IO(LKST_IOC_MAGIC, 10)
+
+#define LKST_IOC_BUFFER_READ		_IO(LKST_IOC_MAGIC, 11)
+#define LKST_IOC_BUFFER_CREATE		_IO(LKST_IOC_MAGIC, 12)
+#define LKST_IOC_BUFFER_SHIFT		_IO(LKST_IOC_MAGIC, 13)
+#define LKST_IOC_BUFFER_JUMP		_IO(LKST_IOC_MAGIC, 14)
+#define LKST_IOC_BUFFER_DELETE		_IO(LKST_IOC_MAGIC, 15)
+#define LKST_IOC_BUFFER_LIST		_IO(LKST_IOC_MAGIC, 16)
+#define LKST_IOC_BUFFER_SETRMOD		_IO(LKST_IOC_MAGIC, 17)
+#define LKST_IOC_BUFFER_LINK		_IO(LKST_IOC_MAGIC, 18)
+
+#define LKST_IOC_ENTRY_LOG		_IO(LKST_IOC_MAGIC, 19)
+
+#define LKST_IOC_MASKSET_GETID		_IO(LKST_IOC_MAGIC, 20)
+#define LKST_IOC_EVHANDLER_GETID	_IO(LKST_IOC_MAGIC, 21)
+
+/* arguments */
+typedef u_int64_t lkst_arg_t;
+
+#define LKST_ARG64(val)	((lkst_arg_t)(val))
+
+#define LKST_ARG32(high,low)						\
+	((lkst_arg_t) (((lkst_arg_t) (u_int32_t) high << 32) |	\
+		           (u_int32_t) low))
+
+#ifdef CONFIG_DEBUG_LKST_DONOT_EXPAND_ARGBITS
+#define LKST_ARG(val)	(LKST_ARG32(0,val)) /* do not expand to 64bits */
+#else
+#define LKST_ARG(val)	(LKST_ARG64(val)) /* expand to 64 bits; 
+					   more compatible for IA64. 
+					   But larger overhead*/
+#endif
+
+
+#define LKST_ARG32_H(arg) ((u_int32_t)((lkst_arg_t)arg >> 32))
+#define LKST_ARG32_L(arg) ((u_int32_t)((lkst_arg_t)arg & \
+					       (lkst_arg_t)0x00000000ffffffff))
+
+/* maskset & buffer */
+typedef u_int8_t lkst_maskset_id;
+typedef u_int8_t lkst_buffer_id;
+typedef u_int8_t lkst_evhandler_id;
+
+
+/* Maskset to record no event */
+#define LKST_MASKSET_ID_RNOTHING	0
+/* Maskset to record all events */
+#define LKST_MASKSET_ID_RALL		1
+/* Maskset to record events specified when kernel compilation */
+#define LKST_MASKSET_ID_RDEFAULT	2
+
+/* LKST_MASKSET_TBL_MAX means size of maskset_table. (cf. LKST_MASKSET_TBL_LEN_MAX */
+#define LKST_MASKSET_TBL_MAX	((lkst_maskset_id) 0xFF)
+#define LKST_MASKSET_ID_MAX	((lkst_maskset_id) (LKST_MASKSET_TBL_MAX - 1))
+#define LKST_MASKSET_ID_VOID	((lkst_maskset_id) (LKST_MASKSET_ID_MAX + 1))
+
+#define LKST_EVHANDLER_TBL_MAX			((lkst_evhandler_id) 0xFF)
+#define LKST_EVHANDLER_ID_MAX						\
+	((lkst_evhandler_id) (LKST_EVHANDLER_TBL_MAX - 1))
+#define LKST_EVHANDLER_ID_VOID						\
+	((lkst_evhandler_id) (LKST_EVHANDLER_ID_MAX + 1))
+
+/* Definitions of event-handler ID.
+ *	(obsolate)EVHANDLER_ID_DMX:		for Dynamic Maskset eXchange
+ *	EVHANDLER_ID_DEFAULT:		default event-handler
+ *	EVHANDLER_ID_BUFFER_SHIFT:	shift buffers on buffer-overflow
+ *	EVHANDLER_ID_BUFFER_SHIFT_DW:	shift buffers and Wakeup LKST Daemon
+ *	EVHANDLER_ID_EXCEPTION:		for debug of exception loop
+ *	(obsolate)EVHANDLER_ID_MASKSET_XCHG:	do dynamic maskset exchange
+ *	EVHANDLER_ID_LOG_STATIC:	logging to static buffer
+ */
+//#define LKST_EVHANDLER_ID_DMX 			((lkst_evhandler_id) 0x00)
+#define LKST_EVHANDLER_ID_DEFAULT		((lkst_evhandler_id) 0x01)
+#define LKST_EVHANDLER_ID_BUFFER_SHIFT		((lkst_evhandler_id) 0x02)
+#define LKST_EVHANDLER_ID_BUFFER_SHIFT_DW	((lkst_evhandler_id) 0x03)
+#define LKST_EVHANDLER_ID_EXCEPTION		((lkst_evhandler_id) 0x04)
+//#define LKST_EVHANDLER_ID_MASKSET_XCHG		((lkst_evhandler_id) 0x05)
+#define LKST_EVHANDLER_ID_LOG_STATIC		((lkst_evhandler_id) 0x06)
+
+#define LKST_EVHANDLER_ID_RESERVED		((lkst_evhandler_id) 0x1f)
+
+#define LKST_BUFFER_TBL_MAX	((lkst_buffer_id) 0xFF)
+#define LKST_BUFFER_ID_MAX	((lkst_buffer_id) (LKST_BUFFER_TBL_MAX - 1))
+#define LKST_BUFFER_ID_VOID	((lkst_buffer_id) (LKST_BUFFER_ID_MAX + 1))
+
+
+struct lkst_version {
+	int major;
+	int minor;
+	int revision;
+};
+
+struct lkst_status_param {
+	unsigned long   online_cpu;
+	lkst_buffer_id	write_buffer_id[LKST_CPU_MAX];
+				/* current writing buffer ID */
+	lkst_buffer_id	read_buffer_id[LKST_CPU_MAX];
+				/* current reading buffer ID */
+	int	maskset_num;	/* total number of registered masksets */
+	int	evhandler_num;	/* total number of registered event handlers */
+	int	static_buffer_recid;	/* recid of the static buffer*/
+	size_t	static_buffer_size;	/* size of the static buffer*/
+	struct lkst_version version;	/* lkst version */
+	lkst_maskset_id	current_maskset_id;
+				/* current selected maskset ID */
+};
+
+struct lkst_entry_args {
+	int event_type;		/* corresponding event type */	
+	lkst_arg_t arg1;	/* 1st argument acquired at a trace point */
+	lkst_arg_t arg2;	/* 2nd argument acquired at a trace point */
+	lkst_arg_t arg3;	/* 3rd argument acquired at a trace point */
+	lkst_arg_t arg4;	/* 4th argument acquired at a trace point */
+};
+
+
+#ifdef __KERNEL__
+				/* Array of mnemonics of event types */
+extern char *lkst_event_type_mnemonics[];
+				/* Array of descriptions of event types */
+extern char *lkst_event_type_descriptions[];
+
+extern void lkst_entry_log(void *phookrec, int event_type,
+			   lkst_arg_t arg1,
+			   lkst_arg_t arg2,
+			   lkst_arg_t arg3,
+			   lkst_arg_t arg4);
+
+extern void lkst_trc_init_stage0(void);
+
+extern void lkst_trc_init_stage1(void);
+
+extern void lkst_trc_init_main(void);
+
+extern void lkst_time_set(int from_settimeofday);
+
+extern int lkst_trc_status(struct lkst_status_param *param);
+
+extern int lkst_trc_start(void);
+
+extern int lkst_trc_stop(void);
+
+extern int lkst_maskset_xchg(lkst_maskset_id * id);
+
+extern void lkst_mem_area_init(void);
+
+static inline void * lkst_generic_current_pc(void)
+{
+	__label__ here;
+here:
+	return (&&here);
+}
+
+#ifndef lkst_current_pc
+#define lkst_current_pc() lkst_generic_current_pc()
+#endif
+
+				/* For IO trace */
+#if (!defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) && !defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) || defined(CONFIG_HOOK) || defined(CONFIG_HOOK_MODULE) 
+#define LKST_SUPPRESS_PIO_TRACE
+#endif /* if (!defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) && !defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)) || defined(CONFIG_HOOK) || defined(CONFIG_HOOK_MODULE)  */
+
+				/* For GKHI */
+
+/* HOOK Information table */
+struct lkst_hook_info {
+	char* hook_id;
+	hook_rec_t* phookrec;
+};
+extern struct lkst_hook_info lkst_hook_info_table[];
+extern int lkst_hook_init_module(lkst_event_type etype);
+extern int lkst_hook_reset_all(void);
+
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+/* Declaration of hook header. compatible for GKHI. */
+#define DECLARE_GENERIC_EXCLUSIVE_HOOK_HEAD(hk) \
+char hk ## _id[sizeof(#hk)] = #hk; \
+extern void hk; \
+hook_head_t hk ## _head = { \
+    .hook_head= &(hk##_head), \
+    .hook_addr= NULL, \
+    .hook_id= hk##_id, \
+    .hook_flags= HOOK_HEAD_EXCLUSIVE \
+}; \
+EXPORT_SYMBOL_NOVERS(hk ## _head); \
+extern hook_head_t hk ## _head
+
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define GENERIC_EXCLUSIVE_HOOK(h,args...) _GENERIC_EXCLUSIVE_HOOK(h,##args)
+#define _GENERIC_EXCLUSIVE_HOOK(h,args...) __GENERIC_EXCLUSIVE_HOOK(#h,h,##args)
+#define __GENERIC_EXCLUSIVE_HOOK(h, h1, args...) { \
+	extern hook_head_t h1##_head; \
+	if (unlikely(h1##_head.hook_flags & HOOK_HEAD_ACTIVE)) { \
+		typedef int (*f)(hook_rec_t *, ...); \
+		(*(hook_fn_t)(h1##_head.hook_exit))(h1##_head.hook_next, ##args); \
+	} \
+}
+#else
+#define GENERIC_EXCLUSIVE_HOOK(h,args...) 
+#endif
+
+/* HOOK Interface */
+#define LKST_HOOK(etype, arg1, arg2, arg3, arg4) EXCLUSIVE_HOOK(etype##_HEADER, etype, arg1, arg2, arg3, arg4)
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define LKST_HOOK_INLINE(etype, arg1, arg2, arg3, arg4) GENERIC_EXCLUSIVE_HOOK(etype##_HEADER, etype, arg1, arg2, arg3, arg4)
+#else
+#define LKST_HOOK_INLINE(etype, arg1, arg2, arg3, arg4) 
+#endif
+
+/* Declaration of hook header */
+#define LKST_HOOK_DECLARE(etype) \
+	DECLARE_EXCLUSIVE_HOOK_HEAD(etype##_HEADER);	\
+	hook_rec_t etype##_hook_rec;
+
+
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define LKST_HOOK_DECLARE_INLINE(etype) \
+	DECLARE_GENERIC_EXCLUSIVE_HOOK_HEAD(etype##_HEADER);	\
+	hook_rec_t etype##_hook_rec;
+#else
+#define LKST_HOOK_DECLARE_INLINE(etype) 
+#endif
+/* Initialization of hook header */
+#define LKST_HOOK_INIT(etype, ret) \
+	_LKST_HOOK_INIT(etype, etype##_HEADER, etype##_hook_rec, ret)
+
+#define _LKST_HOOK_INIT(etype, hookid, hookrec, ret) ({ \
+	ret = hook_initialise(hookid);                      \
+	lkst_hook_info_table[etype].hook_id = #hookid;      \
+	lkst_hook_info_table[etype].phookrec = &hookrec;    \
+	memset(&hookrec, 0, sizeof(hook_rec_t));            \
+})
+
+/* Cleanup of hook header */
+#define LKST_HOOK_TERMINATE(etype, ret) \
+	_LKST_HOOK_TERMINATE(etype, etype##_HEADER, etype##_hook_rec, ret)
+
+#define _LKST_HOOK_TERMINATE(etype, hookid, hookrec, ret) ({  \
+	hook_exit_deregister(&hookrec);                           \
+	ret = hook_terminate(hookid, 0);                          \
+	lkst_hook_info_table[etype].hook_id = NULL;               \
+	lkst_hook_info_table[etype].phookrec = NULL;              \
+	memset(&hookrec, 0, sizeof(hook_rec_t));                  \
+})
+
+/* Initialization of hook header for module */
+#define LKST_HOOK_INIT_MODULE(etype, ret) \
+	_LKST_HOOK_INIT_MODULE(etype, etype##_HEADER, etype##_hook_rec, ret)
+//!FIXME! : correct return value. lkst_hook_init_module might fail.
+#define _LKST_HOOK_INIT_MODULE(etype, hookid, hookrec, ret) ({ \
+	ret = hook_initialise(hookid);                             \
+	lkst_hook_info_table[etype].hook_id = #hookid;             \
+	lkst_hook_info_table[etype].phookrec = &hookrec;           \
+	lkst_hook_init_module(etype);                              \
+})
+
+/* Cleanup of hook header for module */
+#define LKST_HOOK_TERMINATE_MODULE(etype, ret) \
+	_LKST_HOOK_TERMINATE(etype, etype##_HEADER, etype##_hook_rec, ret)
+
+#define LKST_HOOK_EXIST(etype) \
+	(lkst_hook_info_table[etype].phookrec)
+
+#else  /* !CONFIG_DEBUG_KERNEL_STATE_TRACE && !CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
+/* dummy macros when LKST is not compiled in */
+#define LKST_HOOK(etype, arg1, arg2, arg3, arg4)
+#define LKST_HOOK_INLINE(etype, arg1, arg2, arg3, arg4)
+#define LKST_HOOK_DECLARE(etype)
+#define LKST_HOOK_DECLARE_INLINE(etype)
+#define LKST_HOOK_INIT(etype, ret)
+#define LKST_HOOK_TERMINATE(etype, ret)
+#define LKST_HOOK_EXIST(etype)
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE */
+
+#endif /* __KERNEL__ */
+
+#endif				/* _LINUX_LKST_H */
diff -Naru linux-2.4.19/include/linux/lkst_buffer.h linux-2.4.19-lkst/include/linux/lkst_buffer.h
--- linux-2.4.19/include/linux/lkst_buffer.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst_buffer.h	2003-04-14 15:05:21.000000000 -0400
@@ -0,0 +1,211 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.HATASAKI <keisukeh@crl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _LINUX_LKST_BUFFER_H
+#define _LINUX_LKST_BUFFER_H
+
+
+#include <linux/lkst.h>
+#ifdef __KERNEL__
+#include <linux/types.h>
+#include <linux/time.h>
+#else /* #ifndef __KERNEL__ */
+#include <pthread.h>
+#include <sys/time.h>
+#endif	/* __KERNEL__ */
+
+		/* mode for ioctl(LKST_IOC_BUFFER_SETRMOD) command */
+#define RAW	0x01
+#define STD	0x02
+#define SORTED	0x04
+
+		/* size of lkst_event_record. It must be power of 2 */
+		/* This value will be verified in initialization of 
+		   LKST in DEBUG mode. */
+#define LKST_SIZEOF_LKST_EVENT_RECORD	(64)
+
+		/* 
+		 *  following 4 lines should be deleted
+		 *  if they has been already defined. 
+		 */
+typedef int posix_log_recid_t;
+typedef int posix_log_facility_t;
+typedef int posix_log_severity_t;
+typedef int posix_log_procid_t;
+
+#ifdef __KERNEL__
+typedef unsigned long int pthread_t;
+#endif /*__KERNEL__ */
+
+
+#ifndef PXLOG_BINARY
+#define PXLOG_BINARY	1
+#endif /* PXLOG_BINARY */
+
+#ifndef LOG_KERN
+#define LOG_KERN	0
+#endif /* LOG_KERN */
+
+#ifndef LOG_DEBUG
+#define LOG_DEBUG	7
+#endif /* LOG_DEBUG */
+
+
+#define LOGFILE_MAGIC   0xbeefface
+#define LOGREC_MAGIC    0xfeefface
+#define LKST_LOG_MAGIC_NUM 0x76758384
+
+#define LKST_ARCH_NAME_LEN 72
+
+/* Logfile Header for evlog compatibility. */
+typedef struct log_header {
+	uint		log_magic;	/* Magic number indicating log file */
+	long		log_version;	/* Event logging version */
+	posix_log_recid_t last_recid;	/* Last recid in log: used by evlogd */
+	off_t		reserved1;
+	uint		log_generation;	/* Changes during log maintenance */
+} log_header_t;
+
+struct posix_log_entry {
+	unsigned int log_magic;
+	posix_log_recid_t log_recid;	/* ID of the event record */
+	size_t log_size;	/* size of the event record variable data */
+	int log_format;		/* format of variable data */
+	int log_event_type;	/* event identification code */
+	posix_log_facility_t log_facility;	/* event facility code */
+	posix_log_severity_t log_severity;	/* event severity code */
+	uid_t log_uid;	/* effective user ID associated with the event */
+	gid_t log_gid;	/* effective group ID associated with the event */
+	pid_t log_pid;	/* process ID associated with event */
+	pid_t log_pgrp;	/* process group associated with event */
+	struct timespec log_time;	/* event time stamp */
+	unsigned int log_flags;		/* bitmap of event flag */
+	pthread_t log_thread;		/* thread ID associated with event */
+	posix_log_procid_t log_processor; /* processor ID associated with event */
+};
+
+struct lkst_log_record {
+	struct posix_log_entry posix;	/* log form specified by POSIX */
+	lkst_arg_t log_arg1;
+			/* 1st argument acquired at a trace point */
+	lkst_arg_t log_arg2;
+			/* 2nd argument acquired at a trace point */
+	lkst_arg_t log_arg3;
+			/* 3rd argument acquired at a trace point */
+	lkst_arg_t log_arg4;
+			/* 4th argument acquired at a trace point */
+};
+
+struct lkst_log_buffer {
+	int cpu;			/* cpu number */
+	size_t read_size;		/* size of event records to read */
+	size_t result_read_size;	/* size of read event records */
+	struct timeval xtime;		/* xtime */
+	lkst_tsc_t tsc;			/* machine cycle */ 
+					/* These two will be used to calculate 
+					 * time of events in real time. */
+	lkst_cpu_freq_t	cpu_freq;	/* cpu clockspeed in kHz */ 
+	struct lkst_log_record *buffer;
+			/* address of a buffer to store event records */
+
+	int endian_big;			/* byte order, 0 if little endian */
+	int buf_ver;			/* LKST buffer version */
+	char arch[LKST_ARCH_NAME_LEN];	/* Architecture name */
+	lkst_buffer_id id;		/* event buffer ID */
+};
+
+struct lkst_log_buffer_header {
+	struct log_header header;
+	struct posix_log_entry entry;
+	int endian_big;			/* byte order, 0 if little endian */
+	int buf_ver;			/* LKST buffer version */
+	char arch[LKST_ARCH_NAME_LEN];	/* Architecture name */	
+};
+
+struct lkst_buffer_param {
+	int cpu;		/* cpu number */
+	size_t size;		/* size of event buffer */
+	size_t result_size;	/* result size of event buffer */
+	lkst_buffer_id id;	/* event buffer ID */
+	lkst_buffer_id next;	/* event buffer ID of next buffer */
+};
+
+struct lkst_buffer_listent {
+	size_t size;			/* buffer size */
+	int write_offset;		/* offset to write */
+	int baseid;			/* base counter */
+	lkst_buffer_id id, next;	/* buffer ID of own/next buffer */
+	lkst_buffer_id rq_prev, rq_next;	/* buffer ID of read-queue previous/next buffer */
+};
+
+struct lkst_buffer_listparam {
+	int cpu;			/* cpu number of the buffer */
+	int listent_num;		/* num of the listent */
+	int buffer_num;			/* num of the buffers owned by this CPU*/
+	lkst_buffer_id write_buf;	/* current writing buffer */
+	lkst_buffer_id read_buf;	/* current reading buffer */
+	lkst_buffer_id rq_head;
+	lkst_buffer_id rq_tail;
+	pid_t owner;
+	int read_pos;
+	struct lkst_buffer_listent *listent;
+				/* area to store the list of event buffers 
+				 * this size must be lkstent_num*sizeof(struct lkst_buffer_listent)*/
+};
+
+struct lkst_buffer_linkparam {
+	int cpu;			/* cpu number */
+	lkst_buffer_id id, next;	/* link parameter */
+};
+
+struct lkst_buffer_delparam {
+	int cpu;			/* cpu number */
+	lkst_buffer_id id;		/* buffer id to be deleted */
+};
+
+struct lkst_buffer_jumpparam {
+	int cpu;			/* cpu number */
+	lkst_buffer_id dest;		/* destination buffer id */
+};
+
+struct lkst_buffer_srmodparam {
+	int cpu;			/* cpu number */
+	int mode;			/* read mode */
+	struct timeval xtime;		/* xtime */
+	lkst_tsc_t tsc;			/* machine cycle */ 
+					/* These two will be used to calculate 
+					 * time of events in real time. */
+	lkst_cpu_freq_t	cpu_freq;	/* cpu clockspeed in kHz */ 
+	int endian_big;			/* byte order, 0 if little endian */
+	int buf_ver;			/* LKST buffer version */
+	char arch[LKST_ARCH_NAME_LEN];	/* Architecture name */
+};
+
+#ifdef __KERNEL__
+
+int lkst_buffer_shift(void);
+int lkst_buffer_jump(lkst_buffer_id next);
+
+/* !NEVER use these functions in event handlers nor in interrupts !*/
+int lkst_buffer_create(lkst_buffer_id id, size_t size, lkst_buffer_id next);
+int lkst_buffer_delete(lkst_buffer_id id);
+int lkst_buffer_read(struct lkst_log_buffer *lbuffer);
+
+#endif /*__KERNEL__*/
+
+#define LKST_BUFFER_LISTENT_SIZE(n)					\
+	     (sizeof(struct lkst_buffer_listent) * (n))
+
+#define LKST_BUFFER_SIZE_LOCAL2EXT(size) 				\
+		((size)*sizeof(struct lkst_log_record)/LKST_SIZEOF_LKST_EVENT_RECORD)
+
+#endif				/* _LINUX_LKST_BUFFER_H */
+
+/* END */
diff -Naru linux-2.4.19/include/linux/lkst_events.h linux-2.4.19-lkst/include/linux/lkst_events.h
--- linux-2.4.19/include/linux/lkst_events.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst_events.h	2003-04-14 15:05:21.000000000 -0400
@@ -0,0 +1,909 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.SERIZAWA <serizawa@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+/*******************************************************
+ *
+ *  This file may be included twice or more!
+ *
+ *******************************************************/
+
+	/* The list of mnemonics:
+		If LKST_ETYPE_MNEMONICS is defined,
+ 		the list of LKST_ETYPE_DEF() will become a definition of 
+ 		lkst_event_type_mnemonics, 
+		that is an array of mnemonics of event types.	*/
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_MNEMONICS)&&(!defined LKST_ETYPE_DEF_MNEMONICS_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   mnemonic and value of event type.	*/
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4)         \
+        [(event_type)] = #mnemonic,
+
+				/* The header of the array. */
+#define LKST_ETYPE_DEF_ENUM_BEGIN       char *lkst_event_type_mnemonics[] = {
+
+				/* The tail of the enum. It must end with 
+				   LKST_ETYPE_MAX.                    	*/
+#define LKST_ETYPE_DEF_ENUM_END         [LKST_ETYPE_MAX] = "LKST_ETYPE_MAX" };
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_DEF_MNEMONICS_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_MNEMONICS)&&(!defined LKST_ETYPE_DEF_MNEMONICS_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The list of descriptions:
+		If LKST_ETYPE_DEF_DESCRIPTIONS is defined,
+ 		the list of LKST_ETYPE_DEF() will become a definition of 
+ 		lkst_event_type_descriptions, 
+		that is an array of descriptions of event types.	*/
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_DESCRIPTIONS)&&(!defined LKST_ETYPE_DEF_DESCRIPTIONS_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   description and value of event type.	*/
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4)         \
+        [(event_type)] = #description,
+
+				/* The header of the array. */
+#define LKST_ETYPE_DEF_ENUM_BEGIN       char *lkst_event_type_descriptions[] = {
+
+				/* The tail of the enum. It must end with 
+				   LKST_ETYPE_MAX.                    	*/
+#define LKST_ETYPE_DEF_ENUM_END         [LKST_ETYPE_MAX] = "LKST_ETYPE_MAX" };
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_DEF_DESCRIPTIONS_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_DESCRIPTIONS)&&(!defined LKST_ETYPE_DEF_DESCRIPTIONS_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The list of event data */
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_DATATABLE)&&(!defined LKST_ETYPE_DEF_DATATABLE_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   description and value of event type.	*/
+
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4)         \
+        [(event_type)] = { event_name, filter, { arg_1, arg_2, arg_3, arg_4 }, },
+
+				/* The header of the array. */
+#define LKST_ETYPE_DEF_ENUM_BEGIN       	struct LKST_list {                      \
+                                                        char*	LKST_event_name;    \
+                                                        int	LKST_filter;            \
+                                                        char*	LKST_inf_args[4];   \
+                                                        }LKST_event_data[]={
+
+				/* The tail of the enum. It must end with 
+				   LKST_ETYPE_MAX.                    	*/
+#define LKST_ETYPE_DEF_ENUM_END         [LKST_ETYPE_MAX] = {"LKST_ETYPE_MAX", 0,{"","","",""}} };
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_DEF_DATATABLE_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DEF_DESCRIPTIONS)&&(!defined LKST_ETYPE_DEF_DESCRIPTIONS_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The list of GKHI Declaration of hook header :
+		If LKST_ETYPE_DECLARE_HOOKHEADER is defined,
+ 		the list of LKST_ETYPE_DEF() will become a declaration of 
+ 		hook header and hook_rec_t data.	*/
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DECLARE_HOOKHEADER)&&(!defined LKST_ETYPE_DECLARE_HOOKHEADER_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   description and value of event type.	*/
+
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4) \
+        HOOK_DECL_##hooktype(LKST_ETYPE_##mnemonic);
+
+#define HOOK_DECL_NORMAL(etype) LKST_HOOK_DECLARE(etype)
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define HOOK_DECL_INLINE(etype) LKST_HOOK_DECLARE_INLINE(etype)
+#else
+#define HOOK_DECL_INLINE(etype) 
+#endif
+#define HOOK_DECL_MODULE(etype)
+#define HOOK_DECL_UNDEF(etype)
+
+#define LKST_ETYPE_DEF_ENUM_BEGIN
+#define LKST_ETYPE_DEF_ENUM_END
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_DECLARE_HOOKHEADER_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_DECLARE_HOOKHEADER)&&(!defined LKST_ETYPE_DECLARE_HOOKHEADER_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The list of GKHI Initialization of hook header :
+		If LKST_ETYPE_INIT_HOOK is defined,
+ 		the list of LKST_ETYPE_DEF() will become a initialization of 
+ 		hook.	*/
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_INIT_HOOK)&&(!defined LKST_ETYPE_INIT_HOOK_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   description and value of event type.	*/
+
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4) \
+        HOOK_INIT_##hooktype(LKST_ETYPE_##mnemonic)
+
+#define HOOK_INIT_NORMAL(etype) LKST_HOOK_INIT(etype, ret); \
+                                retall += ret;
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define HOOK_INIT_INLINE(etype) LKST_HOOK_INIT(etype, ret); \
+                                retall += ret;
+#else
+#define HOOK_INIT_INLINE(etype) 
+#endif
+#define HOOK_INIT_MODULE(etype)
+#define HOOK_INIT_UNDEF(etype)
+
+
+#define LKST_ETYPE_DEF_ENUM_BEGIN
+#define LKST_ETYPE_DEF_ENUM_END
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_INIT_HOOK_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_INIT_HOOK)&&(!defined LKST_ETYPE_INIT_HOOK_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The list of GKHI Cleanup of hook header :
+		If LKST_ETYPE_TERMINATE_HOOK is defined,
+ 		the list of LKST_ETYPE_DEF() will become a cleanup of 
+ 		hook.	*/
+#if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_TERMINATE_HOOK)&&(!defined LKST_ETYPE_TERMINATE_HOOK_DEFINED))
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the array is a pair of 
+				   description and value of event type.	*/
+
+#define LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4) \
+        HOOK_TERMINATE_##hooktype(LKST_ETYPE_##mnemonic)
+
+#define HOOK_TERMINATE_NORMAL(etype) LKST_HOOK_TERMINATE(etype, ret); \
+                                     retall += ret;
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_ENABLE_INLINE)
+#define HOOK_TERMINATE_INLINE(etype) LKST_HOOK_TERMINATE(etype, ret); \
+                                     retall += ret;
+#else
+#define HOOK_TERMINATE_INLINE(etype) 
+#endif
+#define HOOK_TERMINATE_MODULE(etype)
+#define HOOK_TERMINATE_UNDEF(etype)
+
+#define LKST_ETYPE_DEF_ENUM_BEGIN
+#define LKST_ETYPE_DEF_ENUM_END
+
+				/* Stopper of multi definition. */
+#define LKST_ETYPE_TERMINATE_HOOK_DEFINED
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)&&(defined LKST_ETYPE_TERMINATE_HOOK)&&(!defined LKST_ETYPE_TERMINATE_HOOK_DEFINED)) */
+
+/*******************************************************/
+
+
+	/* The enumerate of event types:
+		By default,
+ 		the list of LKST_ETYPE_DEF() will become a definition of 
+ 		lkst_event_type_descriptions, 
+		that is an array of descriptions of event types.	*/
+#if	(!(defined LKST_ETYPE_DEF))
+				/* The list of LKST_ETYPE_DEF()
+				   will be a definition of an enum. of
+				   event types.				*/
+
+				/* remember to undef 
+				   LKST_ETYPE_DEF{,_ENUM*}.		*/
+#define	LKST_ETYPE_DEF_TOCLEAN
+
+				/* each element of the enum. is a pair of 
+				   a name and value of event type.   	*/
+
+#define	LKST_ETYPE_DEF(event_type, prio, hooktype, mnemonic, description, event_name, filter, arg_1, arg_2, arg_3, arg_4)		\
+	LKST_ETYPE_##mnemonic =	(event_type),
+
+				/* The header of the enum. */
+#define LKST_ETYPE_DEF_ENUM_BEGIN					\
+	typedef enum {
+
+				/* The tail of the enum. It must end with 
+				   LKST_ETYPE_MAX.                    	*/
+#define LKST_ETYPE_DEF_ENUM_END						\
+		LKST_ETYPE_MAX = 0xFFF+0				\
+	} lkst_event_type;
+
+				/* remenber not redefine LKST_ETYPE_MAX. */
+#define	LKST_ETYPE_MAX_IS_ENUM
+
+#endif /* if	(!(defined LKST_ETYPE_DEF)) */
+
+
+/*******************************************************/
+
+    /* header */
+LKST_ETYPE_DEF_ENUM_BEGIN
+
+    /* Body of definitions of event types */
+    /* Syntax:
+        LKST_ETYPE_DEF(
+            VALUE_OF_THE_EVENT_TYPE:(0x001..0xffe),
+            PRIORITY_OF_THE_EVENT_TYPE:(0x00..0xff),
+            TYPE OF GKHI HOOK HEADER,
+            MNEMONIC_OF_THE_EVENT_TYPE,
+            DESCRIPTION_OF_THE_EVENT_TYPE,
+            EVENT_NAME_STRING,
+            DISPLAY_FILTER,
+            EVENT_ARG1,
+            EVENT_ARG2,
+            EVENT_ARG3,
+            EVENT_ARG4 )                  */
+
+LKST_ETYPE_DEF(0x001, 0x00, NORMAL, PROCESS_CONTEXTSWITCH, PROCESS_CONTEXTSWITCH,   \
+        // 0x001 event
+        "context_switch",                                                           \
+         0,                                                                         \
+        "pointer to task_struct(prev)",                                             \
+        "pointer to task_struct(next)",                                             \
+        "process state",    \
+        "process count")
+LKST_ETYPE_DEF(0x002, 0x00, INLINE, PROCESS_WAKEUP, PROCESS_WAKEUP,                 \
+        // 0x002 event
+        "process_wakeup",                                                           \
+         0,                                                                         \
+        "pointer to wakeup-process(p)",                                             \
+        "synchronous",                                                              \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x003, 0x00, NORMAL, PROCESS_SIGSEND, PROCESS_SIGSEND,               \
+        // 0x003 event
+        "process_sigsend",                                                          \
+         0,                                                                         \
+        "signal number(sig)",                                                       \
+        "pointer to process to which signal is sent",                               \
+        "pointer to info structure(info)",                                          \
+         NULL)
+LKST_ETYPE_DEF(0x004, 0x00, NORMAL, PROCESS_LTHREADGEN, PROCESS_LTHREADGEN,         \
+        // 0x004 event
+        "kernel_thread",                                                            \
+         0,                                                                         \
+        "pointer to kernel thread(fn)",                                             \
+        "argument of kernel thread(arg)",                                           \
+        "flag",                                                                     \
+         NULL)
+
+LKST_ETYPE_DEF(0x010, 0x01, NORMAL, INT_HARDWARE_ENTRY, INT_HARDWARE_ENTRY,         \
+        //0x010 event
+        "interrupt_hardware_entry",                                                 \
+         0,                                                                         \
+        "IRQ number(irq)",                                                          \
+        "interrupt status(status)",                                                 \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x012, 0x01, NORMAL, INT_TASKLETHI_ENTRY, INT_TASKLETHI_ENTRY,       \
+        //0x012 event
+        "interrupt_tasklethi_entry",                                                \
+         0,                                                                         \
+        "action address(t->func)",                                                  \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x014, 0x01, NORMAL, INT_TASKLET_ENTRY, INT_TASKLET_ENTRY,           \
+        //0x014 event
+        "interrupt_tasklet_entry",                                                  \
+         0,                                                                         \
+        "action address(t->func)",                                                  \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x016, 0x01, NORMAL, INT_BH_ENTRY, INT_BH_ENTRY,                     \
+        //0x016 event
+        "interrupt_bh_entry",                                                       \
+         0,                                                                         \
+        "interrupt type(nr)",                                                       \
+        "action address(bh_base)",                                                  \
+         NULL,                                                                      \
+         NULL)
+
+/* exception events(0x02*) are moved to asm/lkst_events.h */
+
+/* syscall events(0x03*) are moved to asm/lkst_events.h */
+
+LKST_ETYPE_DEF(0x040, 0x04, NORMAL, FS_DEVRW, FS_DEVRW,                             \
+        //0x040 event
+        "fs_devrw",                                                                 \
+         0,                                                                         \
+        "buffer(bh)",                                                               \
+        "READ/WRITE(rw)",                                                           \
+        "the number of block transfered(nr)",                                       \
+         NULL)
+LKST_ETYPE_DEF(0x041, 0x04, NORMAL, FS_DEVEND, FS_DEVEND,                           \
+        //0x041 event
+        "fs_devend",                                                                \
+         0,                                                                         \
+        "buffer(bf)",                                                               \
+        "uptodate",                                                                 \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x042, 0x04, NORMAL, FS_BUFBUSY, FS_BUFBUSY,                         \
+        //0x042 event
+        "fs_devwait",                                                               \
+         0,                                                                         \
+        "buffer(bh)",                                                               \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0x050, 0x05, INLINE, MEM_SWAPOUT, MEM_SWAPOUT,                       \
+        //0x050 event
+        "mem_swapout",                                                              \
+         0,                                                                         \
+        "pointer to page swapped-out",                                              \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x051, 0x05, NORMAL, MEM_SWAPIN, MEM_SWAPIN,                         \
+        //0x051 event
+        "mem_swapin",                                                               \
+         0,                                                                         \
+        "pointer to page swapped-in",                                               \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x052, 0x05, NORMAL, MEM_DO_NOPAGE, MEM_DO_NOPAGE,                   \
+        //0x052 event
+        "mem_do_nopage",                                                            \
+         0,                                                                         \
+        "pointer to page allocated",                                                \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x053, 0x05, NORMAL, MEM_DO_WPPAGE, MEM_DO_WPPAGE,                   \
+        //0x053 event
+        "mem_do_wppage",                                                            \
+         0,                                                                         \
+        "pointer to page",                                                          \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x054, 0x05, NORMAL, MEM_WAIT_PAGE, MEM_WAIT_PAGE,                   \
+        //0x054 event
+        "mem_wait_page",                                                            \
+         0,                                                                         \
+        "pointer to page",                                                          \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x055, 0x05, NORMAL, MEM_GET_FREEPAGE, MEM_GET_FREEPAGE,             \
+        //0x055 event
+        "mem_get_freepage",                                                         \
+         0,                                                                         \
+        "pointer to page",                                                          \
+        "type of page(gfp_mask)",                                                   \
+        "the number of page(order)",                                                \
+        "call address")
+LKST_ETYPE_DEF(0x056, 0x05, NORMAL, MEM_GET_ZEROPAGE, MEM_GET_ZEROPAGE,             \
+        //0x056 event
+        "mem_get_zeropage",                                                         \
+         0,                                                                         \
+        "pointer to page",                                                          \
+        "type of page(gfp_mask)",                                                   \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x057, 0x05, NORMAL, MEM_FREEPAGE, MEM_FREEPAGE,                     \
+        //0x057 event
+        "mem_freepage",                                                             \
+         0,                                                                         \
+        "pointer to page",                                                          \
+        "the number of page(order)",                                                \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x058, 0x05, INLINE, MEM_VMALLOC, MEM_VMALLOC,                       \
+        //0x058 event
+        "mem_vmalloc",                                                              \
+         0,                                                                         \
+        "address(addr)",                                                            \
+        "size",                                                                     \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x059, 0x05, NORMAL, MEM_VFREE, MEM_VFREE,                           \
+        //0x059 event
+        "mem_vfree",                                                                \
+         0,                                                                         \
+        "address(addr)",                                                            \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x05a, 0x05, NORMAL, MEM_CACHE_CREATE, MEM_CACHE_CREATE,             \
+        //0x05a event
+        "mem_cache_create",                                                         \
+         0,                                                                         \
+        "name",                                                                     \
+        "size",                                                                     \
+        "cachep",                                                                   \
+         NULL)
+LKST_ETYPE_DEF(0x05b, 0x05, NORMAL, MEM_CACHE_ALLOC, MEM_CACHE_ALLOC,               \
+        //0x05b event
+        "mem_cache_alloc",                                                          \
+         0,                                                                         \
+        "cachep",                                                                   \
+        "flags",                                                                    \
+        "objp",                                                                     \
+        "call address")
+LKST_ETYPE_DEF(0x05c, 0x05, NORMAL, MEM_MALLOC, MEM_MALLOC,                         \
+        //0x05c event
+        "mem_malloc",                                                               \
+         0,                                                                         \
+        "size",                                                                     \
+        "flags",                                                                    \
+        "objp",                                                                     \
+        "call address")
+LKST_ETYPE_DEF(0x05d, 0x05, NORMAL, MEM_CACHE_FREE, MEM_CACHE_FREE,                 \
+        //0x05d event
+        "mem_cache_free",                                                           \
+         0,                                                                         \
+        "cachep",                                                                   \
+        "objp",                                                                     \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x05e, 0x05, NORMAL, MEM_FREE, MEM_FREE,                             \
+        //0x05e event
+        "mem_free",                                                                 \
+         0,                                                                         \
+        "objp",                                                                     \
+        "call address",                                                             \
+         NULL,                                                                      \
+         NULL)
+	
+LKST_ETYPE_DEF(0x060, 0x06, NORMAL, NET_PKTSEND, NET_PKTSEND,                       \
+        //0x060 event
+        "net_pktsend",                                                              \
+         0,                                                                         \
+        "skb",                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x061, 0x06, NORMAL, NET_PKTSENDI, NET_PKTSENDI,                     \
+        //0x061 event
+        "net_pktsendi",                                                             \
+         0,                                                                         \
+        "h",                                                                        \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x062, 0x06, NORMAL, NET_PKTRECV, NET_PKTRECV,                       \
+        //0x062 event
+        "net_pktrecv",                                                              \
+         0,                                                                         \
+        "skb",                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x063, 0x06, NORMAL, NET_PKTRECVI, NET_PKTRECVI,                     \
+        //0x063 event
+        "net_pktrecvi",                                                             \
+         0,                                                                         \
+        "h",                                                                        \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x064, 0x06, NORMAL, NET_SOCKETIF, NET_SOCKETIF,                     \
+        //0x064 event
+        "net_socketif",                                                             \
+         0,                                                                         \
+        "call",                                                                     \
+        "args",                                                                     \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0x070, 0x07, NORMAL, SYSV_IPC_SEMOP, SYSV_IPC_SEMOP,                 \
+        //0x070 event
+        "sysv_ipc_semop",                                                           \
+         0,                                                                         \
+        "semid",                                                                    \
+        "tsops",                                                                    \
+        "nsops",                                                                    \
+         NULL)
+LKST_ETYPE_DEF(0x071, 0x07, NORMAL, SYSV_IPC_SEMGET, SYSV_IPC_SEMGET,               \
+        //0x071 event
+        "sysv_ipc_semget",                                                          \
+         0,                                                                         \
+        "key",                                                                      \
+        "nsems",                                                                    \
+        "semflg",                                                                   \
+         NULL)
+LKST_ETYPE_DEF(0x072, 0x07, NORMAL, SYSV_IPC_SEMCTL, SYSV_IPC_SEMCTL,               \
+        //0x072 event
+        "sysv_ipc_semctl",                                                          \
+         0,                                                                         \
+        "semid",                                                                    \
+        "semnum",                                                                   \
+        "cmd",                                                                      \
+        "arg.__pad")
+LKST_ETYPE_DEF(0x073, 0x07, NORMAL, SYSV_IPC_MSGSEND, SYSV_IPC_MSGSEND,             \
+        //0x073 event
+        "sysv_ipc_msgsend",                                                         \
+         0,                                                                         \
+        "msqid",                                                                    \
+        "msgp",                                                                     \
+        "msgsz",                                                                    \
+        "msgflg")
+LKST_ETYPE_DEF(0x074, 0x07, NORMAL, SYSV_IPC_MSGRCV, SYSV_IPC_MSGRCV,               \
+        //0x074 event
+        "sysv_ipc_msgrcv",                                                          \
+         0,                                                                         \
+        "msqid/msgflg",                                                             \
+        "msgp",                                                                     \
+        "msgsz",                                                                    \
+        "msgtyp")
+LKST_ETYPE_DEF(0x075, 0x07, NORMAL, SYSV_IPC_MSGGET, SYSV_IPC_MSGGET,               \
+        //0x075 event
+        "sysv_ipc_msgget",                                                          \
+         0,                                                                         \
+        "key",                                                                      \
+        "msgflg",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x076, 0x07, NORMAL, SYSV_IPC_MSGCTL, SYSV_IPC_MSGCTL,               \
+        //0x076 event
+        "sysv_ipc_msgctl",                                                          \
+         0,                                                                         \
+        "msqid",                                                                    \
+        "cmd",                                                                      \
+        "buf",                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x077, 0x07, NORMAL, SYSV_IPC_SHMAT, SYSV_IPC_SHMAT,                 \
+        //0x077 event
+        "sysv_ipc_shmat",                                                           \
+         0,                                                                         \
+        "shmid",                                                                    \
+        "shmaddr",                                                                  \
+        "shmflg",                                                                   \
+        "raddr")
+LKST_ETYPE_DEF(0x078, 0x07, NORMAL, SYSV_IPC_SHMDT, SYSV_IPC_SHMDT,                 \
+        //0x078 event
+        "sysv_ipc_shmdt",                                                           \
+         0,                                                                         \
+        "shmaddr",                                                                  \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x079, 0x07, NORMAL, SYSV_IPC_SHMGET, SYSV_IPC_SHMGET,               \
+        //0x079 event
+        "sysv_ipc_shmget",                                                          \
+         0,                                                                         \
+        "key",                                                                      \
+        "size",                                                                     \
+        "shmflg",                                                                   \
+         NULL)
+LKST_ETYPE_DEF(0x07a, 0x07, NORMAL, SYSV_IPC_SHMCTL, SYSV_IPC_SHMCTL,               \
+        //0x07a event
+        "sysv_ipc_shmctl",                                                          \
+         0,                                                                         \
+        "shmid",                                                                    \
+        "cmd",                                                                      \
+        "buf",                                                                      \
+         NULL)
+
+/* Events concerned with spinlocks should have event_type as 0x08x. */
+LKST_ETYPE_DEF(0x080, 0x08, INLINE, LK_SPINLOCK, LK_SPINLOCK,                       \
+        //0x080 event
+        "spin_lock",                                                                \
+         0,                                                                         \
+        "call address",                                                             \
+        "lock",                                                                     \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x081, 0x08, INLINE, LK_SPINTRYLOCK, LK_SPINTRYLOCK,                 \
+        //0x081 event
+        "spin_trylock",                                                             \
+         0,                                                                         \
+        "call address",                                                             \
+        "lock",                                                                     \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x082, 0x08, INLINE, LK_SPINUNLOCK, LK_SPINUNLOCK,                   \
+        //0x082 event
+        "spin_unlock",                                                              \
+         0,                                                                         \
+        "call address",                                                             \
+        "lock",                                                                     \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x083, 0x08, INLINE, LK_WRLOCK, LK_WRLOCK,                           \
+        //0x083 event
+        "write_lock",                                                               \
+         0,                                                                         \
+        "call address",                                                             \
+        "rwlock",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x084, 0x08, INLINE, LK_WRTRYLOCK, LK_WRTRYLOCK,                     \
+        //0x084 event
+        "write_trylock",                                                            \
+         0,                                                                         \
+        "call address",                                                             \
+        "rwlock",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x085, 0x08, INLINE, LK_WRUNLOCK, LK_WRUNLOCK,                       \
+        //0x085 event
+        "write_unlock",                                                             \
+         0,                                                                         \
+        "call address",                                                             \
+        "rwlock",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x086, 0x08, INLINE, LK_RDLOCK, LK_RDLOCK,                           \
+        //0x086 event
+        "read_lock",                                                                \
+         0,                                                                         \
+        "call address",                                                             \
+        "rwlock",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x087, 0x08, INLINE, LK_RDUNLOCK, LK_RDUNLOCK,                       \
+        //0x087 event
+        "read_unlock",                                                              \
+         0,                                                                         \
+        "call address",                                                             \
+        "rwlock",                                                                   \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x088, 0x08, UNDEF,  LK_RESV88, LK_RESV88, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x089, 0x08, UNDEF,  LK_RESV89, LK_RESV89, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08a, 0x08, UNDEF,  LK_RESV8a, LK_RESV8a, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08b, 0x08, UNDEF,  LK_RESV8b, LK_RESV8b, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08c, 0x08, UNDEF,  LK_RESV8c, LK_RESV8c, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08d, 0x08, UNDEF,  LK_RESV8d, LK_RESV8d, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08e, 0x08, UNDEF,  LK_RESV8e, LK_RESV8e, NULL, 0, NULL, NULL, NULL, NULL)
+LKST_ETYPE_DEF(0x08f, 0x08, UNDEF,  LK_RESV8f, LK_RESV8f, NULL, 0, NULL, NULL, NULL, NULL)
+
+LKST_ETYPE_DEF(0x090, 0x09, INLINE, O_PORTIN, O_PORTIN,                             \
+        //0x090 event
+        "portin",                                                                   \
+         0,                                                                         \
+        "port address/bite-width",                                                  \
+        "value",                                                                    \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x091, 0x09, INLINE, O_PORTOUT, O_PORTOUT,                           \
+        //0x091 event
+        "portout",                                                                  \
+         0,                                                                         \
+        "port address/bite-width",                                                  \
+        "value",                                                                    \
+        "call address",                                                             \
+         NULL)
+LKST_ETYPE_DEF(0x092, 0x09, NORMAL, O_PANIC, O_PANIC,                               \
+        //0x092 event
+        "panic",                                                                    \
+         0,                                                                         \
+        "address of argument",                                                      \
+        "call address",                                                             \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x093, 0x09, NORMAL, O_PRINTK, O_PRINTK,                             \
+        //0x093 event
+        "printk",                                                                   \
+         0,                                                                         \
+        "address of argument",                                                      \
+        "call address",                                                             \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0x0a0, 0x0a, INLINE, TIMER_RUN, TIMER_RUN,                           \
+        //0x0a0 event
+        "timer_run",                                                                \
+         0,                                                                         \
+        "function address(fn)",                                                     \
+        "parameter(data)",                                                          \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0x0a1, 0x0a, NORMAL, TIMER_ADD, TIMER_ADD,                           \
+        //0x0a1 event
+        "timer_add",                                                                \
+         0,                                                                         \
+        "timer",                                                                    \
+        "timer->expires",                                                           \
+        "timer->function",                                                          \
+        "timer->data")
+LKST_ETYPE_DEF(0x0a2, 0x0a, NORMAL, TIMER_MOD, TIMER_MOD,                           \
+        //0x0a2 event
+        "timer_mod",                                                                \
+         0,                                                                         \
+        "timer",                                                                    \
+        "timer->expires",                                                           \
+        "timer->function",                                                          \
+        "timer->data")
+LKST_ETYPE_DEF(0x0a3, 0x0a, NORMAL, TIMER_DEL, TIMER_DEL,                           \
+        //0x0a3 event
+        "timer_del",                                                                \
+         0,                                                                         \
+        "timer",                                                                    \
+        "timer->expires",                                                           \
+        "timer->function",                                                          \
+        "timer->data")
+#ifdef CONFIG_SMP
+LKST_ETYPE_DEF(0x0a4, 0x0a, NORMAL, TIMER_DEL_SYNC, TIMER_DEL_SYNC,                 \
+        //0x0a4 event
+        "timer_del_sync",                                                           \
+         0,                                                                         \
+        "timer",                                                                    \
+        "timer->expires",                                                           \
+        "timer->function",                                                          \
+        "timer->data")
+#endif /* CONFIG_SMP */
+/*Oops series are in architecture dependant */
+LKST_ETYPE_DEF(0xF00, 0xF0, INLINE, LKST_INIT, LKST_INIT,                           \
+        //0xf00 event
+        "lkst_init",                                                                \
+         0,                                                                         \
+        "data",                                                                     \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0xF01, 0xF0, UNDEF, LKST_KERNEL_DUMP, LKST_KERNEL_DUMP,              \
+        //0xf01 event
+        "lkst_kernel_dump",                                                         \
+         0,                                                                         \
+        "dump state",                                                               \
+        "dump device",                                                              \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0xF08, 0xF0, INLINE, LKST_MSET_XCHG, LKST_MSET_XCHG,                 \
+        //0xf08 event
+        "lkst_mset_xchg",                                                           \
+         0,                                                                         \
+        "old_id/new_id",                                                            \
+        "old_maskset",                                                              \
+        "new_maskset",                                                              \
+         NULL)
+
+LKST_ETYPE_DEF(0xF10, 0xF1, INLINE, LKST_BUFF_SHIFT, LKST_BUFF_SHIFT,               \
+        //0xf10 event
+        "lkst_buff_shift",                                                          \
+         0,                                                                         \
+        "buffer",                                                                   \
+        "next_buffer",                                                              \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0xF11, 0xF1, INLINE, LKST_BUFF_OVFLOW, LKST_BUFF_OVFLOW,             \
+        //0xf11 event
+        "lkst_buff_ovflow",                                                         \
+         0,                                                                         \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0xF12, 0xF1, UNDEF,  LKST_BUFF_HIGH, LKST_BUFF_HIGH,                 \
+        //0xf12 event
+        "lkst_buff_high",                                                           \
+         0,                                                                         \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0xF18, 0xF1, UNDEF,  LKST_SYNC_TIME, LKST_SYNC_TIME,                 \
+        //0xf18 event
+        "lkst_sync_time",                                                           \
+         0,                                                                         \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+LKST_ETYPE_DEF(0xF19, 0xF1, INLINE, LKST_SYNC_UID, LKST_SYNC_UID,                   \
+        //0xf19 event
+        "lkst_sync_uid",                                                            \
+         0,                                                                         \
+        "ruid",                                                                     \
+         NULL,                                                                      \
+        "currnet",                                                                  \
+         NULL)
+LKST_ETYPE_DEF(0xF1A, 0xF1, INLINE, LKST_SYNC_GID, LKST_SYNC_GID,                   \
+        //0xf1a event
+        "lkst_sync_gid",                                                            \
+         0,                                                                         \
+        "rgid",                                                                     \
+         NULL,                                                                      \
+        "currnet",                                                                  \
+         NULL)
+LKST_ETYPE_DEF(0xF1B, 0xF1, INLINE, LKST_SYNC_PGID, LKST_SYNC_PGID,                 \
+        //0xf1b event
+        "lkst_sync_pgid",                                                           \
+         0,                                                                         \
+        "pid",                                                                      \
+        "pgrp",                                                                     \
+        "pointer to task_struct",                                                   \
+        "leader")
+LKST_ETYPE_DEF(0xF1C, 0xF1, NORMAL, LKST_SYNC_TID, LKST_SYNC_TID,                   \
+        //0xf1c event
+        "lkst_sync_tid",                                                            \
+         0,                                                                         \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL,                                                                      \
+         NULL)
+
+LKST_ETYPE_DEF(0xFFC, 0xFF, UNDEF,  LKST_EXTEND, LKST_EXTEND, NULL, 0, NULL, NULL, NULL, NULL)	// TODO: Tantative code
+LKST_ETYPE_DEF(0xFFD, 0xFF, UNDEF,  LKST_EXTENDE, LKST_EXTENDE, NULL, 0, NULL, NULL, NULL, NULL)	// TODO: Tantative code
+LKST_ETYPE_DEF(0xFFE, 0xFF, UNDEF,  LKST_OVWRTN_REC, LKST_OVWRTN_REC,               \
+        //0xffe event
+        "overwritten_record",                                                       \
+         0,                                                                         \
+        "old arg1",                                                                 \
+        "old arg2",                                                                 \
+        "old arg3",                                                                 \
+        "old event_type")
+
+#include <asm/lkst_events.h>
+
+#if	((!defined(LKST_ETYPE_MAX_IS_ENUM))&&(!defined(LKST_ETYPE_MAX)))
+        /* By default, LKST_ETYPE_MAX is
+           defined as an element of the enum.
+           Otherwise here LKST_ETYPE_MAX is 
+           defined as a MACRO.               */
+#define LKST_ETYPE_MAX  (0xFFF+0)
+
+#endif /* if ((!defined(LKST_ETYPE_MAX_IS_ENUM))&&(!defined(LKST_ETYPE_MAX))) */
+
+#ifndef	LKST_ETYPE_VOID
+#define LKST_ETYPE_VOID  (LKST_ETYPE_MAX+1)
+#endif /* ifndef LKST_ETYPE_VOID */
+
+    /* tail */
+LKST_ETYPE_DEF_ENUM_END
+
+        /* By default, undef LKST_ETYPE_DEF* 
+           for the next inclusion of this file. */
+#ifdef  LKST_ETYPE_DEF_TOCLEAN
+
+#undef  LKST_ETYPE_DEF
+#undef  LKST_ETYPE_DEF_ENUM_BEGIN
+#undef  LKST_ETYPE_DEF_ENUM_END
+#undef  LKST_ETYPE_DEF_TOCLEAN
+
+#endif /* ifdef LKST_ETYPE_DEF_TOCLEAN */
+
+/* END */
diff -Naru linux-2.4.19/include/linux/lkst_evhandler.h linux-2.4.19-lkst/include/linux/lkst_evhandler.h
--- linux-2.4.19/include/linux/lkst_evhandler.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst_evhandler.h	2003-04-14 15:05:22.000000000 -0400
@@ -0,0 +1,63 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.HATASAKI <keisukeh@crl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _LINUX_LKST_EVHANDLER_H
+#define _LINUX_LKST_EVHANDLER_H
+
+#include<linux/lkst.h>
+
+#define LKST_EVHANDLER_NAME_LEN		256
+
+//#define LKST_EVHANDLER_NAME_DMX			"DynamicMasksetXchg"
+#define LKST_EVHANDLER_NAME_DEFAULT		"DEFAULT"
+#define LKST_EVHANDLER_NAME_BUFFER_SHIFT	"BUFFER_SHIFT"
+#define LKST_EVHANDLER_NAME_BUFFER_SHIFT_DW	"BUFFER_SHIFT_AND_DAEMON_WAKEUP"
+#define LKST_EVHANDLER_NAME_EXCEPTION		"EXCEPTION"
+//#define LKST_EVHANDLER_NAME_MASKSET_XCHG	"MASKSET_XCHG"
+#define LKST_EVHANDLER_NAME_LOG_STATIC		"LOG_STATIC"
+
+struct lkst_evhandler_ctrl_param {
+	lkst_evhandler_id id;	/* event handler ID */
+	void *buf;		/* a communication area for control-function */
+	size_t bufsize;		/* size of the communication area */
+	int ret;		/* return value from control-function */
+};
+
+struct lkst_evhandler_listent {
+	lkst_evhandler_id id;	/* event handler ID */
+	char name[LKST_EVHANDLER_NAME_LEN];
+					/* event handler name */
+};
+
+struct lkst_evhandler_listparam {
+	size_t listent_size;	/* size of the listent */
+	struct lkst_evhandler_listent *listent;
+				/* area to store the list of event handlers */
+};
+
+# define LKST_EVHANDLER_LISTENT_SIZE(n)					\
+	     (sizeof(struct lkst_evhandler_listent) * (n))
+
+/* same as lkst_evhandler_listent ... but different sense.*/
+struct lkst_evhandler_getparam {
+	lkst_evhandler_id id;			/* event handler ID */
+	char name[LKST_EVHANDLER_NAME_LEN];	/* event handler name */
+};
+
+#ifdef __KERNEL__
+
+extern int lkst_evhandler_ctrl(struct lkst_evhandler_ctrl_param
+			       *evhandler_ctrl_param);
+
+extern int lkst_evhandler_list(struct lkst_evhandler_listparam *lp);
+
+#endif /*__KERNEL__*/
+
+#endif				/* _LINUX_LKST_EVHANDLER_H */
diff -Naru linux-2.4.19/include/linux/lkst_maskset.h linux-2.4.19-lkst/include/linux/lkst_maskset.h
--- linux-2.4.19/include/linux/lkst_maskset.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst_maskset.h	2003-04-14 15:05:22.000000000 -0400
@@ -0,0 +1,100 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2002 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by T.Nakamura <tetsu@crl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _LINUX_LKST_MASKSET_H
+#define _LINUX_LKST_MASKSET_H
+
+#include<linux/lkst.h>
+#include<linux/lkst_evhandler.h>
+
+#define LKST_MASKSET_NAME_LEN	256
+
+/* LKST_MASKSET_TBL_LEN_MAX means n of entries in a maskset. (cf. LKST_MASKSET_TBL_MAX */
+#define LKST_MASKSET_TABLE_LEN_MAX	((LKST_ETYPE_MAX)+1)
+
+#define LKST_MASKSET_NAME_RALL		"RALL"
+#define LKST_MASKSET_NAME_RNOTHING	"RNOTHING"
+#define LKST_MASKSET_NAME_RDEFAULT	"RDEFAULT"
+
+typedef int lkst_maskset_table_len;
+
+struct lkst_maskset_entry {
+	int event_type;			/* corresponding type of evnet */
+	lkst_evhandler_id id;	/* event handler ID */
+};
+
+struct lkst_maskset_body {
+	char name[LKST_MASKSET_NAME_LEN];	/* maskset name */
+	lkst_maskset_table_len len;	/* total number of maskset entries */
+	struct lkst_maskset_entry entry[LKST_MASKSET_TABLE_LEN_MAX];
+					/* maskset entry */
+};
+
+struct lkst_maskset_param {
+	lkst_maskset_id id;	/* maskset ID */
+	size_t maskset_size;	/* maskset size */
+	struct lkst_maskset_body *maskset;
+				/* address of a maskset stored area */
+};
+
+struct lkst_maskset_listent {
+	lkst_maskset_id id;			/* maskset ID */
+	char name[LKST_MASKSET_NAME_LEN];	/* maskset name */
+	lkst_maskset_table_len len;	/* total number of maskset entries */
+};
+
+struct lkst_maskset_listparam {
+	lkst_maskset_id current_id;	/* current maskset ID */
+	size_t listent_size;	/* size of the listent */
+	struct lkst_maskset_listent *listent;
+				/* area to store the list of masksets */
+};
+
+struct lkst_maskset_getparam {
+	lkst_maskset_id id;			/* maskset ID */
+	char name[LKST_MASKSET_NAME_LEN];	/* maskset name */
+};
+
+/* normal kernel APIs(Never use in event handlers)*/
+extern int lkst_maskset_read(struct lkst_maskset_param *maskset_param);
+
+extern int lkst_maskset_write(struct lkst_maskset_param *maskset_param);
+
+extern int lkst_maskset_xchg(lkst_maskset_id * id);
+
+static __inline__ int lkst_maskset_set(lkst_maskset_id id) {
+	return lkst_maskset_xchg(&id);
+}
+
+extern int lkst_maskset_delete(lkst_maskset_id id);
+
+extern int lkst_maskset_list(struct lkst_maskset_listparam *lp);
+
+extern int lkst_maskset_get_id(const char * name);
+
+/* event handler primitives */
+#define lkst_evhandlerprim_maskset_get_id(name) lkst_maskset_get_id(name)
+
+extern int lkst_evhandlerprim_maskset_xchg(lkst_maskset_id *id);
+
+static __inline__ int lkst_evhandlerprim_maskset_set(lkst_maskset_id id) {
+	return lkst_evhandlerprim_maskset_xchg(&id);
+}
+
+#define LKST_MASKSET_SIZE(n)						\
+	(sizeof(char)*LKST_MASKSET_NAME_LEN +				\
+	     sizeof(lkst_maskset_table_len) +				\
+	     sizeof(struct lkst_maskset_entry) * (n))
+
+#define LKST_MASKSET_LISTENT_SIZE(n)					\
+	     (sizeof(struct lkst_maskset_listent) * (n))
+
+
+#endif				/* _LINUX_LKST_MASKSET_H */
diff -Naru linux-2.4.19/include/linux/lkst_private.h linux-2.4.19-lkst/include/linux/lkst_private.h
--- linux-2.4.19/include/linux/lkst_private.h	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/include/linux/lkst_private.h	2003-04-18 10:43:48.000000000 -0400
@@ -0,0 +1,526 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2003 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by T.Nakamura <tetsu@crl.hitachi.co.jp>
+ * Updated by M.Hiramatsu <hiramatu@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#ifndef _LINUX_LKST_PRIVATE_H
+#define _LINUX_LKST_PRIVATE_H
+
+#include <linux/lkst.h>
+#include <linux/lkst_maskset.h>
+#include <linux/lkst_buffer.h>
+#include <linux/lkst_evhandler.h>
+#include <asm/lkst_private.h>
+#include <asm/page.h>
+
+#ifdef __KERNEL__
+
+#include <linux/sched.h>
+#include <linux/kernel_stat.h>
+#include <linux/string.h>
+#include <linux/wait.h>
+#include <linux/cache.h>
+
+
+extern void * lkst_encounter_a_BUG(const char *file, int line);
+#define LKST_ENCOUNTER_A_BUG lkst_encounter_a_BUG(__FILE__,__LINE__);
+
+#ifdef CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION
+
+	/* Needed to be volatile, because the order of modification
+	 *   and reference of these values are significant.
+	 */
+	/*  p + p##_check == LKST_POINTER_CHECK_MAGIC */
+#define LKST_POINTER_CHECK_VAL(p) 					\
+	(LKST_POINTER_CHECK_MAGIC - ((lkst_pointer_check_digit)(p)))
+	/* initialize p##_check */
+#define LKST_POINTER_CHECK_INIT(p) 					\
+	(p##_check = LKST_POINTER_CHECK_VAL(p))
+	/* initialize p and p##_check */
+#define LKST_POINTER_INIT(p, value)					\
+	(p##_check = LKST_POINTER_CHECK_VAL(value), p = value)
+	/* verify p and p##_check */
+#define LKST_POINTER_VERIFY(src)					\
+	((lkst_ptr_t)(src##_check) == (lkst_ptr_t)LKST_POINTER_CHECK_VAL((src)))
+	/* load and verify p and p##_check */
+#define LKST_POINTER_VERIFY_WITH_LOAD(src, dst)				\
+	( (dst) = (src),						\
+	 (lkst_ptr_t)(src##_check) == (lkst_ptr_t)LKST_POINTER_CHECK_VAL((dst)))
+	/* verify and validate pointer */
+#define LKST_POINTER_VERIFY_AND_LOAD(src, dst)				\
+	( ((dst) = (src)) && LKST_POINTER_VERIFY(src))
+	/* call BUG() if failed to verify */
+#define LKST_POINTER_LOAD_BUG_IF_FAIL(src, dst)				\
+	 (LKST_POINTER_VERIFY(src) ? ((dst) = (src)) :  		\
+		((dst) = lkst_encounter_a_BUG(__FILE__, __LINE__)) )
+
+#else /*!CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION*/
+
+#define LKST_POINTER_CHECK_VAL(p)  (lkst_pointer_check_digit)(0)
+#define LKST_POINTER_CHECK_INIT(p) 					\
+	(p##_check = LKST_POINTER_CHECK_VAL(p))
+#define LKST_POINTER_INIT(p, value)					\
+	(p##_check = LKST_POINTER_CHECK_VAL(value), p = value)
+#define LKST_POINTER_VERIFY(src)	  	(1)
+#define LKST_POINTER_VERIFY_WITH_LOAD(src, dst)	((dst)=(src), 1)
+#define LKST_POINTER_VERIFY_AND_LOAD(src, dst)	((dst)=(src))
+#define LKST_POINTER_LOAD_BUG_IF_FAIL(src, dst)				\
+	((dst) = (src))
+
+#endif /*CONFIG_DEBUG_LKST_STRICT_POINTER_VERIFICATION*/
+
+/*Instead of (valiable = pointer), use LKST_POINTER_LOAD(pointer,valiable)*/
+#define LKST_POINTER_LOAD(ptr, dst) LKST_POINTER_VERIFY_AND_LOAD(ptr, dst)
+/*Instead of (pointer = value), use LKST_POINTER_STORE(pointer, value)*/
+#define LKST_POINTER_STORE(ptr, src) LKST_POINTER_INIT(ptr, src)
+
+/* If pointer *MUST NOT* point NULL address, please use these macros*/
+/*#define LKST_POINTER_LOAD_VALID(ptr, dst)				\
+	(LKST_POINTER_VERIFY_AND_LOAD(ptr, dst) ? (dst) : 		\
+		 lkst_encounter_a_BUG(__FILE__, __LINE__) )
+#define LKST_POINTER_STORE_VALID(ptr, src)				\
+	(LKST_POINTER_INIT(ptr, src) ? (src) : 				\
+		 lkst_encounter_a_BUG(__FILE__, __LINE__) )
+*/
+
+#endif /*__KERNEL__*/
+
+
+/* declare p & p##_check */
+# define LKST_POINTER_DECLARE(type, p) 					\
+	type * p; 							\
+	lkst_pointer_check_digit p##_check;
+#define LKST_POINTER_DECLARE_NP(type, p)				\
+	type p;								\
+	lkst_pointer_check_digit p##_check;
+
+#define LKST_EVHANDLER_BUFFER_TRIAL_MAX		10
+#define LKST_EVHANDLER_MASKSET_TRIAL_MAX	10
+
+#define LKST_DEV_MAJOR	231	/* LKST device major number */  /* TODO */
+#define LKST_DEV_MINOR	0	/* LKST device minor number */
+#define LKST_DEV_NAME	"lkst"	/* LKST device name */
+
+/* LKST buffer version */
+#define LKST_BUF_VER	0x000102	/* major(1B) miner(1B) sub(1B) */
+
+#define LKST_MASKSET_TABLE_BYTE	\
+	(sizeof(lkst_evhandler_id) * (LKST_ETYPE_MAX + 1))
+
+typedef lkst_evhandler_id * lkst_maskset;
+
+struct lkst_maskset_table {
+	char name[LKST_MASKSET_NAME_LEN];
+	LKST_POINTER_DECLARE(lkst_maskset, masksetp);
+};
+
+struct lkst_event_record {
+	int32_t    log_recid;
+	int32_t    log_event_type;
+	lkst_tsc_t log_time;
+	pid_t      log_pid;
+  	int32_t    processor;
+	lkst_arg_t log_arg1;
+	lkst_arg_t log_arg2;
+	lkst_arg_t log_arg3;
+	lkst_arg_t log_arg4;
+	lkst_arg_t _reserved1;
+};
+
+typedef void (*lkst_evhandler_func) (void *phookrec, int32_t event_type,
+				     lkst_arg_t arg1, lkst_arg_t arg2,
+				     lkst_arg_t arg3, lkst_arg_t arg4);
+
+typedef int (*lkst_evhandler_ctrl_func) (void *buf, size_t bufsize);
+
+struct lkst_evhandler_entry {
+	char name[LKST_EVHANDLER_NAME_LEN];
+	LKST_POINTER_DECLARE_NP(lkst_evhandler_func, evhandler);
+	LKST_POINTER_DECLARE_NP(lkst_evhandler_ctrl_func, evhandler_ctrl);
+};
+
+#define LKST_EVENT_RECORD_BYTE (sizeof(struct lkst_event_record)) /*MUST be 64 bytes*/
+#define LKST_LOG_RECORD_BYTE (sizeof(struct lkst_log_record))
+
+#define LKST_BASEID_MASK	0x00ffffff
+#define LKST_BUFFER_RECID(bufferid, baseid) \
+	((baseid & LKST_BASEID_MASK) | (bufferid << 24))
+
+/*Only header -- use macros when access to body*/
+/* write position is calcurated from recid and initial recid */
+struct lkst_event_buffer {
+	char eyecatcher[4];			/* EyeCatcher */
+	int  buf_ver;				/* LKST buffer version */
+	int  cmos_time_flag; 			/* cmos time flag */
+	struct timeval xtime;			/* xtime */
+	int  cpu;				/* owner processor */
+	int  size;				/* buffer size (count). including margin area.*/
+	int  baseid;				/* base recid */
+	int  write_offset;			/* write position offset */
+	lkst_buffer_id id, next;		/* buffer ID of own/next buffer */
+	lkst_buffer_id rq_next, rq_prev;	/* buffer ID of read queue */
+};
+
+#define LKST_BUFFER_HEADER_COUNT \
+	((int)( (sizeof(struct lkst_event_buffer)-1) \
+		   / LKST_EVENT_RECORD_BYTE) + 1)
+
+#define LKST_BUFFER_HEADER_BYTE \
+	(LKST_BUFFER_HEADER_COUNT*LKST_EVENT_RECORD_BYTE)
+
+#define LKST_BUFFER_PAGE_BYTE  (PAGE_SIZE)	/* arch dep. */
+#define LKST_BUFFER_PAGE_MASK  (~(LKST_BUFFER_PAGE_BYTE - 1))
+#define LKST_BUFFER_PAGE_COUNT (LKST_BUFFER_PAGE_BYTE/LKST_EVENT_RECORD_BYTE)
+
+/* Rooms for overrun in buffer wrapping around.	
+	 It assumes the worst case that all the CPUs 
+	 interrupt in detection of buffer wrapping,
+	 and exception occurs on each CPU.		*/
+#define LKST_BUFFER_MARGIN_BYTE	  (LKST_BUFFER_PAGE_BYTE-LKST_BUFFER_HEADER_BYTE)
+#define LKST_BUFFER_MARGIN_COUNT  (LKST_BUFFER_MARGIN_BYTE/LKST_EVENT_RECORD_BYTE)
+
+#define LKST_BUFFER_INIT_POS	((int)LKST_BUFFER_MARGIN_COUNT)
+
+/* static buffer size -- must be power of 2 */
+#if defined(CONFIG_DEBUG_LKST_SBUF_TINY)
+# define CONFIG_DEBUG_LKST_SBUF_SIZE 32768
+#elif defined(CONFIG_DEBUG_LKST_SBUF_LARGE)
+# define CONFIG_DEBUG_LKST_SBUF_SIZE 524288
+#else /*defined(CONFIG_DEBUG_LKST_SBUF_MEDIUM)*/
+# define CONFIG_DEBUG_LKST_SBUF_SIZE 131072
+#endif
+
+#define LKST_STATIC_BUFFER_BYTE		(CONFIG_DEBUG_LKST_SBUF_SIZE)	/* Configurable */
+#define LKST_STATIC_BUFFER_COUNT	(LKST_STATIC_BUFFER_BYTE/LKST_EVENT_RECORD_BYTE)
+#define LKST_STATIC_BUFFER_MASK		(LKST_STATIC_BUFFER_COUNT - 1)
+
+/* temporary buffer that used as cache to read from user space.*/
+#define LKST_TEMP_BUFFER_COUNT		128 /* 128 entries*/
+#define LKST_TEMP_BUFFER_BYTE		(LKST_TEMP_BUFFER_COUNT*LKST_LOG_RECORD_BYTE)
+
+#if defined(__KERNEL__) || defined( CMD_LKSTDUMP)
+
+#include <asm/atomic.h>
+
+struct lkst_elapsed_times_buff {
+	time_t current_time;
+	atomic_t count;
+	int count0;
+	/* average, maximum, minimum and varianceof elapsed times */
+	time_t avg_time;
+	time_t max_time;
+	time_t min_time;
+	time_t var_time;
+	/* room for optional times */
+	time_t o0_time;
+	time_t o1_time;
+	time_t o2_time;
+	time_t o3_time;
+
+	/* room for optional event_types */
+	int event_type0;
+	int event_type1;
+	int event_type2;
+	int event_type3;
+};
+
+struct lkst_static_buffer {
+	atomic_t recid;			/* write_pos = recid % LKST_STATIC_BUFFER_COUNT */
+	struct lkst_event_record body[LKST_STATIC_BUFFER_COUNT];
+					/* buffer body */
+};
+
+struct lkst_buffer_owner {
+	pid_t pid;			/* owner pid */
+	lkst_buffer_id read_buf;	/* current read buffer */
+	char _pad[3];
+	int read_pos;			/* current read position (count)*/
+ 	int read_baseid;		/* baseid of the event record in read_pos */
+	int ready;			/* ready to read flag */
+	wait_queue_head_t wait;		/* buffer wait queue */
+};
+
+struct lkst_header_percpu {
+	int cpu;			/* bound cpu (for lcrash)*/
+	lkst_buffer_id write_buf;	/* IDs of current buffers. */
+	lkst_buffer_id rq_tail;		/* Tail of read queue(in) */
+	lkst_buffer_id rq_head;		/* Head of read queue(out) */
+	char _pad;
+	int reading;			/* per processor reading flag*/
+	struct lkst_buffer_owner owner;
+	char eyecatcher[4];		/* EyeCatcher */
+	struct {
+		LKST_POINTER_DECLARE(struct lkst_event_buffer, ptr);
+	} buffer_table[LKST_BUFFER_TBL_MAX];
+} ____cacheline_aligned;
+
+//TODO : header size is changed by the architecture.
+struct lkst_header {
+	char eyecatcher[4];	/* EyeCatcher */
+	lkst_maskset_id current_maskset_id;	/* Current maskset id */
+	lkst_maskset_id maskset_id_saved;	/* Saved maskset id */
+	char _pad[2];
+	
+	/* Current Maskset Pointer */
+	LKST_POINTER_DECLARE(lkst_maskset, current_masksetp);
+
+	/* Maskset Table */
+	struct lkst_maskset_table maskset_table[LKST_MASKSET_TBL_MAX];
+
+	/* Event Handler Table */
+	struct lkst_evhandler_entry evhandler_table[LKST_EVHANDLER_TBL_MAX];
+
+	/* LKST available memory size */
+	size_t available_memory_size;
+	/* LKST available memory limit address */
+	void * limit_addr;
+
+	int endian_big;			/* byte order, 0 if little endian */
+	lkst_cpu_freq_t	cpu_freq;	/* cpu clockspeed in kHz */
+	lkst_tsc_t tsc;			/* machine cycle */
+	struct timeval xtime;		/* xtime */
+	unsigned int cmos_time_flag; 	/* cmos time flag */
+	int buf_ver;			/* LKST buffer version */
+	char arch[LKST_ARCH_NAME_LEN];	/* Architecture name */
+
+	struct lkst_static_buffer static_buffer;
+};
+
+
+/* macros to access to the body of buffers */
+				/* top address of buffer body */
+#define LKST_BUFFER_BODY(buffer) \
+	((struct lkst_event_record *)((char *)buffer+LKST_BUFFER_HEADER_BYTE))
+				/* entry address indexed in buffer body */
+#define LKST_BUFFER_BODY_INDEX(buffer,index) (LKST_BUFFER_BODY(buffer)[index])
+
+				/* Offset of buffer body from buffer head */
+#define LKST_BUFFER_BODY_OFFSET() LKST_BUFFER_HEADER_BYTE
+
+				/* size of the buffer whole */
+#define LKST_BUFFER_AREA_SIZE(n)					\
+	(LKST_BUFFER_BODY_OFFSET() + (n))
+
+#define LKST_STATIC_BUFFER_BODY() \
+	((struct lkst_event_record *)lkst.static_buffer.body)
+#define LKST_STATIC_BUFFER_BODY_INDEX(index) (LKST_STATIC_BUFFER_BODY()[index])
+
+
+#endif /*defined(__KERNEL__) || defined( CMD_LKSTDUMP)*/
+
+#ifdef __KERNEL__
+
+extern struct lkst_header lkst;
+
+/* Implemented in lkst_kernel.c */
+extern lkst_cpu_freq_t lkst_get_cpu_khz(void);
+extern struct lkst_header_percpu lkst_cpu[LKST_CPU_MAX];
+
+				/* header structure of current processor */
+#define lkst_current lkst_cpu[smp_processor_id()]
+
+				/* buffer access macros */
+#define LKST_BUFFER_LOAD(id, pt) \
+	LKST_POINTER_LOAD(lkst_current.buffer_table[id].ptr, pt)
+
+#define LKST_CURRENT_BUFFER_LOAD(pt) \
+	((lkst_current.write_buf != LKST_BUFFER_ID_VOID ) && \
+	 LKST_BUFFER_LOAD(lkst_current.write_buf, pt) )
+
+#define LKST_BUFFER_STORE(id, pt) \
+	LKST_POINTER_STORE(lkst_current.buffer_table[id].ptr, pt)
+
+#define LKST_BUFFER_CHECK_NULL(id) \
+	( LKST_POINTER_VERIFY(lkst_current.buffer_table[id].ptr) && \
+	 lkst_current.buffer_table[id].ptr == NULL )
+
+
+/*
+ * event handler register (GPL only!)
+ */
+
+extern int lkst_evhandler_register(lkst_evhandler_id id, 
+				   const char * name,
+				   lkst_evhandler_func evhandler,
+				   lkst_evhandler_ctrl_func
+				   evhandler_ctrl);
+extern int lkst_evhandler_unregister(lkst_evhandler_id id);
+extern int lkst_evhandler_get_id(const char * name);
+
+/*
+ * event handler primitive functions
+ */
+
+extern void lkst_buffer_dump_current_txt(void);
+
+extern struct lkst_event_buffer * \
+lkst_evhandlerprim_select_buffer_id(lkst_buffer_id id);
+
+extern struct lkst_event_buffer * \
+lkst_evhandlerprim_select_buffer(void);
+
+extern void lkst_evhandlerprim_owner_wakeup(void);
+
+extern void lkst_evhandlerprim_entry_log(int event_type,
+					 lkst_arg_t arg1, lkst_arg_t arg2,
+					 lkst_arg_t arg3, lkst_arg_t arg4);
+#define lkst_evhandlerprim_entry_log_l2(event_type, arg1, arg2, arg3, arg4) \
+	lkst_evhandlerprim_entry_log(event_type,                       \
+				     arg1, arg2, arg3, arg4)
+
+extern void lkst_evhandlerprim_entry_log_static(int event_type,
+						lkst_arg_t arg1, lkst_arg_t arg2,
+						lkst_arg_t arg3, lkst_arg_t arg4);
+
+#define lkst_evhandlerprim_buffer_jump(next) lkst_buffer_jump(next)
+#define lkst_evhandlerprim_buffer_shift() lkst_buffer_shift()
+
+/* System default event handlers */
+
+extern void lkst_evhandler_default(void * phookrec, int event_type,
+				   lkst_arg_t arg1,
+				   lkst_arg_t arg2,
+				   lkst_arg_t arg3, lkst_arg_t arg4);
+
+extern void lkst_evhandler_log_static(void * phookrec, int event_type,
+				      lkst_arg_t arg1,
+				      lkst_arg_t arg2,
+				      lkst_arg_t arg3, lkst_arg_t arg4);
+
+extern int lkst_evhandler_default_ctrl(void * buf, size_t buf_size);
+
+extern void lkst_evhandler_buffer_shift(void * phookrec, int event_type,
+					lkst_arg_t arg1,
+					lkst_arg_t arg2,
+					lkst_arg_t arg3,
+					lkst_arg_t arg4);
+
+extern void lkst_evhandler_buffer_shift_wakeup(void * phookrec, int event_type,
+					       lkst_arg_t arg1,
+					       lkst_arg_t arg2,
+					       lkst_arg_t arg3,
+					       lkst_arg_t arg4);
+
+extern void lkst_evhandler_maskset_xchg(void * phookrec, int event_type,
+					lkst_arg_t arg1,
+					lkst_arg_t arg2,
+					lkst_arg_t arg3,
+					lkst_arg_t arg4);
+
+#if DEBUG
+extern void lkst_evhandler_exception(void * phookrec, int event_type,
+				     lkst_arg_t arg1,
+				     lkst_arg_t arg2,
+				     lkst_arg_t arg3,
+				     lkst_arg_t arg4);
+#endif /* DEBUG */
+
+/*
+ * This migrates current process to specified CPU
+ * and save its cpus_allowed flags.
+ */
+static __inline__ int lkst_cpu_migrate_save(unsigned long *allowed, int cpu)
+{
+#ifdef CONFIG_SMP 
+	unsigned long mask;
+	*allowed = current->cpus_allowed;
+	mask = (( 1UL << cpu ) & cpu_online_map);
+	if ( mask != 0UL ) {
+		/* if you use Ingo's O(1)scheduler, you must use 
+		 * set_cpus_allowed(current, mask);
+		 * instead of following.*/
+		current->cpus_allowed = mask;
+		while (!(current->cpus_runnable & current->cpus_allowed))
+			schedule();
+	} else {
+		return -EINVAL;
+	}
+	return 0;
+#else /*!CONFIG_SMP*/
+	return (cpu==0)?0:-EINVAL;
+#endif /*CONFIG_SMP*/
+}
+
+/*
+ * This restore current process's cpus_allowed flags. 
+ */
+static __inline__ void lkst_cpu_migrate_restore(unsigned long allowed)
+{
+#ifdef CONFIG_SMP 
+	/* if you use Ingo's O(1)scheduler, you must use 
+	 * set_cpus_allowed(current, allowed);
+	 * instead of following.*/
+	current->cpus_allowed = allowed;
+	while (!(current->cpus_runnable & current->cpus_allowed))
+		schedule();
+#endif /*CONFIG_SMP*/
+}
+
+/*
+ * This check whether the cpu is online.
+ */
+static __inline__ int lkst_cpu_is_online(int cpu)
+{
+#ifdef CONFIG_SMP 
+	return  (cpu >= 0) && (cpu < NR_CPUS) &&
+		((1UL << cpu) & cpu_online_map );
+#else /*!CONFIG_SMP*/
+	return (cpu==0)?1:0;
+#endif /*CONFIG_SMP*/
+}
+
+/* implemented in lkst_kernel.c */
+extern struct module * lkst_find_module_by_address(unsigned long addr);
+
+/*
+ * function lkst_evhandlerprim_kernel_text_address
+ * A primitive part of an Event-handler. This returns whether
+ * addr is in kernel (or kernel modules) text address.
+ *
+ *  Arguments
+ *    addr {IN}: address to investigate.
+ *
+ *  returns
+ *    0: addr is out of the kernel code nor kernel module.
+ *    1: addr is in the kernel code or kernel module.
+ *
+ */
+static __inline__ int \
+lkst_evhandlerprim_kernel_text_address(unsigned long addr) {
+	return (NULL != lkst_find_module_by_address(addr));
+}
+
+#endif /* __KERNEL__ */
+
+
+#define LKST_ETYPE_VERIFY(event_type) 					\
+	(!(0xfffff000&(event_type)))
+
+#define LKST_MASKSET_TABLE_LOAD(i, ptr) \
+	LKST_POINTER_LOAD(lkst.maskset_table[i].masksetp, ptr)
+
+#define	LKST_MASKSET_QUERY_EVHANDLER_ID(maskset_ptr, event_type)	\
+	(((lkst_evhandler_id *)(maskset_ptr))[(event_type)])
+#define	LKST_MASKSET_SET_EVHANDLER_ID(maskset_ptr, event_type, id)	\
+	(((lkst_evhandler_id *)(maskset_ptr))[(event_type)] = (id))
+
+#define	LKST_MASKSET_TABLE_ENTRY_SET(table, id, maskname, addr) ({     	\
+	LKST_POINTER_STORE((table)[(id)].masksetp, 			\
+			   (lkst_maskset *)(addr));			\
+	strncpy((table)[(id)].name, (maskname),				\
+		(size_t) LKST_MASKSET_NAME_LEN);			\
+	(table)[id].name[LKST_MASKSET_NAME_LEN-1] = '\0';})
+
+#define	LKST_MASKSET_SET_CURRENT(id) ({					\
+	lkst.current_maskset_id = (id);					\
+	LKST_POINTER_STORE(lkst.current_masksetp,			\
+			   lkst.maskset_table[(id)].masksetp);})
+
+
+#endif /* _LINUX_LKST_PRIVATE_H */
diff -Naru linux-2.4.19/include/linux/vmalloc.h linux-2.4.19-lkst/include/linux/vmalloc.h
--- linux-2.4.19/include/linux/vmalloc.h	2003-04-14 15:03:00.000000000 -0400
+++ linux-2.4.19-lkst/include/linux/vmalloc.h	2003-04-14 15:05:19.000000000 -0400
@@ -7,6 +7,8 @@
 
 #include <asm/pgtable.h>
 
+#include <linux/lkst.h>
+
 /* bits in vm_struct->flags */
 #define VM_IOREMAP	0x00000001	/* ioremap() and friends */
 #define VM_ALLOC	0x00000002	/* vmalloc() */
@@ -32,7 +34,17 @@
  
 static inline void * vmalloc (unsigned long size)
 {
-	return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
+	void * addr;
+
+	addr = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
+
+	LKST_HOOK_INLINE(LKST_ETYPE_MEM_VMALLOC,
+			 LKST_ARGP(addr),
+			 LKST_ARG(size),
+			 LKST_ARGP(__builtin_return_address(0)),
+			 LKST_ARG(0));
+
+	return addr;
 }
 
 /*
diff -Naru linux-2.4.19/init/main.c linux-2.4.19-lkst/init/main.c
--- linux-2.4.19/init/main.c	2003-04-14 15:02:54.000000000 -0400
+++ linux-2.4.19-lkst/init/main.c	2003-04-14 15:05:14.000000000 -0400
@@ -70,6 +70,10 @@
 #include <asm/smp.h>
 #endif
 
+#ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE
+#include <linux/lkst.h>
+#endif /* ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE */
+
 /*
  * Versions of gcc older than that listed below may actually compile
  * and link okay, but the end product can have subtle run time bugs.
@@ -365,6 +369,9 @@
  * enable them
  */
 	lock_kernel();
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE)&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START))
+        lkst_trc_init_stage0();
+#endif /* if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE)&&defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_IN_START)) */
 	printk(linux_banner);
 	setup_arch(&command_line);
 	printk("Kernel command line: %s\n", saved_command_line);
@@ -418,6 +425,9 @@
 	 */
 	if (num_mappedpages == 0)
 		num_mappedpages = num_physpages;
+#if (defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE))
+ 	lkst_mem_area_init();
+#endif /* (CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE) */
   
 	fork_init(num_mappedpages);
 	proc_caches_init();
@@ -446,6 +456,9 @@
 	 *	make syscalls (and thus be locked).
 	 */
 	smp_init();
+#ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE
+	lkst_trc_init_main();
+#endif /* ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE */
 	rest_init();
 }
 
diff -Naru linux-2.4.19/ipc/msg.c linux-2.4.19-lkst/ipc/msg.c
--- linux-2.4.19/ipc/msg.c	2003-04-14 15:03:29.000000000 -0400
+++ linux-2.4.19-lkst/ipc/msg.c	2003-04-14 15:05:48.000000000 -0400
@@ -22,6 +22,7 @@
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/list.h>
+#include <linux/lkst.h>
 #include <asm/uaccess.h>
 #include "util.h"
 
@@ -305,6 +306,12 @@
 	int id, ret = -EPERM;
 	struct msg_queue *msq;
 	
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_MSGGET,
+			LKST_ARG(key),
+			LKST_ARG(msgflg),
+			LKST_ARG(0),
+			LKST_ARG(0));
+
 	down(&msg_ids.sem);
 	if (key == IPC_PRIVATE) 
 		ret = newque(key, msgflg);
@@ -427,6 +434,12 @@
 	struct msq_setbuf setbuf;
 	struct kern_ipc_perm *ipcp;
 	
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_MSGCTL,
+			LKST_ARG(msqid),
+			LKST_ARG(cmd),
+			LKST_ARGP(buf),
+			LKST_ARG(0));
+
 	if (msqid < 0 || cmd < 0)
 		return -EINVAL;
 
@@ -630,6 +643,12 @@
 	long mtype;
 	int err;
 	
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_MSGSEND,
+			LKST_ARG(msqid),
+			LKST_ARGP(msgp),
+			LKST_ARG(msgsz),
+			LKST_ARG(msgflg));
+
 	if (msgsz > msg_ctlmax || (long) msgsz < 0 || msqid < 0)
 		return -EINVAL;
 	if (get_user(mtype, &msgp->mtype))
@@ -735,6 +754,12 @@
 	int err;
 	int mode;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_MSGRCV,
+			LKST_ARG32(msqid, msgflg),
+			LKST_ARGP(msgp),
+			LKST_ARG(msgsz),
+			LKST_ARG(msgtyp));
+
 	if (msqid < 0 || (long) msgsz < 0)
 		return -EINVAL;
 	mode = convert_mode(&msgtyp,msgflg);
diff -Naru linux-2.4.19/ipc/sem.c linux-2.4.19-lkst/ipc/sem.c
--- linux-2.4.19/ipc/sem.c	2003-04-14 15:03:29.000000000 -0400
+++ linux-2.4.19-lkst/ipc/sem.c	2003-04-14 15:05:48.000000000 -0400
@@ -62,6 +62,7 @@
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/lkst.h>
 #include <asm/uaccess.h>
 #include "util.h"
 
@@ -154,6 +155,12 @@
 	int id, err = -EINVAL;
 	struct sem_array *sma;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SEMGET,
+			LKST_ARG(key),
+			LKST_ARG(nsems),
+			LKST_ARG(semflg),
+			LKST_ARG(0));
+
 	if (nsems < 0 || nsems > sc_semmsl)
 		return -EINVAL;
 	down(&sem_ids.sem);
@@ -757,6 +764,12 @@
 	int err = -EINVAL;
 	int version;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SEMCTL,
+			LKST_ARG(semid),
+			LKST_ARG(semnum),
+			LKST_ARG(cmd),
+			LKST_ARGP(arg.__pad));
+
 	if (semid < 0)
 		return -EINVAL;
 
@@ -847,6 +860,12 @@
 	int undos = 0, decrease = 0, alter = 0;
 	struct sem_queue queue;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SEMOP,
+			LKST_ARG(semid),
+			LKST_ARGP(tsops),
+			LKST_ARG(nsops),
+			LKST_ARG(0));
+
 	if (nsops < 1 || semid < 0)
 		return -EINVAL;
 	if (nsops > sc_semopm)
diff -Naru linux-2.4.19/ipc/shm.c linux-2.4.19-lkst/ipc/shm.c
--- linux-2.4.19/ipc/shm.c	2003-04-14 15:03:29.000000000 -0400
+++ linux-2.4.19-lkst/ipc/shm.c	2003-04-14 15:05:48.000000000 -0400
@@ -22,6 +22,7 @@
 #include <linux/file.h>
 #include <linux/mman.h>
 #include <linux/proc_fs.h>
+#include <linux/lkst.h>
 #include <asm/uaccess.h>
 
 #include "util.h"
@@ -231,6 +232,12 @@
 	struct shmid_kernel *shp;
 	int err, id = 0;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SHMGET,
+			LKST_ARG(key),
+			LKST_ARG(size),
+			LKST_ARG(shmflg),
+			LKST_ARG(0));
+
 	down(&shm_ids.sem);
 	if (key == IPC_PRIVATE) {
 		err = newseg(key, shmflg, size);
@@ -378,6 +385,12 @@
 	struct shmid_kernel *shp;
 	int err, version;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SHMCTL,
+			LKST_ARG(shmid),
+			LKST_ARG(cmd),
+			LKST_ARG(buf),
+			LKST_ARG(0));
+
 	if (cmd < 0 || shmid < 0)
 		return -EINVAL;
 
@@ -578,6 +591,12 @@
 	int acc_mode;
 	void *user_addr;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SHMAT,
+			LKST_ARG(shmid),
+			LKST_ARG(shmaddr),
+			LKST_ARG(shmflg),
+			LKST_ARG(raddr));
+
 	if (shmid < 0)
 		return -EINVAL;
 
@@ -675,6 +694,12 @@
 	struct vm_area_struct *shmd, *shmdnext;
 	int retval = -EINVAL;
 
+	LKST_HOOK(LKST_ETYPE_SYSV_IPC_SHMDT,
+		  LKST_ARGP(shmaddr),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0));
+
 	down_write(&mm->mmap_sem);
 	for (shmd = mm->mmap; shmd; shmd = shmdnext) {
 		shmdnext = shmd->vm_next;
diff -Naru linux-2.4.19/kernel/Makefile linux-2.4.19-lkst/kernel/Makefile
--- linux-2.4.19/kernel/Makefile	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/Makefile	2003-04-14 15:05:14.000000000 -0400
@@ -9,7 +9,7 @@
 
 O_TARGET := kernel.o
 
-export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o hook.o
+export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o hook.o lkst_kernel.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o info.o time.o softirq.o resource.o \
@@ -20,6 +20,9 @@
 obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += ksyms.o
 obj-$(CONFIG_PM) += pm.o
+obj-$(subst m,y,$(CONFIG_DEBUG_KERNEL_STATE_TRACE)) += lkst_kernel.o
+
+CFLAGS_lkst_kernel.o += -DUTS_MACHINE='"$(ARCH)"'
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff -Naru linux-2.4.19/kernel/hook.c linux-2.4.19-lkst/kernel/hook.c
--- linux-2.4.19/kernel/hook.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/hook.c	2003-04-14 15:05:14.000000000 -0400
@@ -347,11 +347,17 @@
 
 	/* rec points to the hook record after which we make the insertion */
 	hook_rec->hook_next = rec->hook_next;
-	rec->hook_next = rec;
+	if ( rec==hook )
+	{
+		rec->hook_next = hook_rec;
+	}
+	else
+	{
+		rec->hook_next = rec;
+	}
 	hook_rec->hook_prev = rec;
 	hook_rec->hook_next->hook_prev = hook_rec;
 	hook_rec->hook_head = hook;
-
 	calculate_indicies(hook_rec->hook_head);
 
 	create_hook_exit_proc_entry(hook_rec);
diff -Naru linux-2.4.19/kernel/lkst_kernel.c linux-2.4.19-lkst/kernel/lkst_kernel.c
--- linux-2.4.19/kernel/lkst_kernel.c	1969-12-31 19:00:00.000000000 -0500
+++ linux-2.4.19-lkst/kernel/lkst_kernel.c	2003-04-14 15:05:14.000000000 -0400
@@ -0,0 +1,388 @@
+/************************************************************
+ *
+ * COPYRIGHT (C) HITACHI,LTD. 2001-2003 ALL RIGHTS RESERVED.
+ * WRITTEN BY HITACHI SYSTEMS DEVELOPMENT LABORATORY,
+ *            HITACHI CENTRAL RESEARCH LABORATORY.
+ *
+ * Created by K.SERIZAWA <serizawa@sdl.hitachi.co.jp>
+ *
+ ************************************************************/
+
+#include <linux/module.h>
+#include <linux/lkst_private.h>
+#include <linux/vmalloc.h>
+#include <linux/highmem.h>
+
+/* this is just for backporting */
+#ifndef EXPORT_SYMBOL_GPL
+#define EXPORT_SYMBOL_GPL(sym) EXPORT_SYMBOL(sym)
+#endif
+
+#ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE
+#undef	DEBUG
+#endif
+
+
+#define BUFFER_TBL_INIT {NULL, LKST_POINTER_CHECK_VAL(NULL)}
+#define MASKSET_TBL_INIT {"", NULL, LKST_POINTER_CHECK_VAL(NULL)}
+#define EVHANDLER_TBL_INIT {"", NULL, LKST_POINTER_CHECK_VAL(NULL), NULL, LKST_POINTER_CHECK_VAL(NULL)}
+
+/* LKST availabe memory size -- max vmalloc size */
+//#define LKST_AVAILABLE_MEMORY_SIZE	(unsigned long)((unsigned long)VMALLOC_END - (unsigned long)VMALLOC_START - (unsigned long)PAGE_SIZE)
+//#define LKST_AVAILABLE_MEMORY_SIZE	(64<<20)
+
+struct lkst_header_percpu lkst_cpu[LKST_CPU_MAX] = {
+	[0 ... (LKST_CPU_MAX - 1)] = {
+		.cpu=			0,
+		.write_buf=		LKST_BUFFER_ID_VOID,
+		.rq_tail=		LKST_BUFFER_ID_VOID,
+		.rq_head=		LKST_BUFFER_ID_VOID,
+		.reading=		0,
+		.owner= 		{
+			.pid=		PID_MAX+1,
+			.read_buf=	LKST_BUFFER_ID_VOID,
+			.read_pos=	0,
+			.ready=		0,
+			.wait=		{WAITQUEUE_RW_LOCK_UNLOCKED, {0}},
+		},
+		.eyecatcher=		{'L','K','C','P'},
+		.buffer_table=		{[0 ... (LKST_BUFFER_TBL_MAX-1)] = {NULL, LKST_POINTER_CHECK_VAL(NULL)}},
+	},
+} ;
+EXPORT_SYMBOL_GPL(lkst_cpu);
+
+struct lkst_header lkst = {
+	.eyecatcher=		{'L','K','S','T'},
+	.current_masksetp=	NULL,
+ 	.current_masksetp_check=	LKST_POINTER_CHECK_VAL(NULL),
+  	.current_maskset_id=	0,
+ 	.maskset_table= 	{[0 ... (LKST_MASKSET_TBL_MAX-1)] = MASKSET_TBL_INIT},
+ 	.evhandler_table=	{[0 ... (LKST_EVHANDLER_TBL_MAX-1)] = EVHANDLER_TBL_INIT},
+ 	.maskset_id_saved=	LKST_MASKSET_ID_RDEFAULT,
+	.available_memory_size=	0,
+	.limit_addr=		NULL,
+	.endian_big=		LKST_BIG_ENDIAN, /* 1 means BIG_ENDIAN. */
+	.cpu_freq=		0,
+	.tsc=			0,
+	.xtime=			{0 ,0},
+	.cmos_time_flag=	1,
+	.buf_ver=		LKST_BUF_VER,
+	.arch=			{UTS_MACHINE},
+	.static_buffer=		{
+		.recid=		ATOMIC_INIT(0),
+	}
+};
+EXPORT_SYMBOL_GPL(lkst); // now, you can access directory.
+
+/* for pointer verification, etc... */
+void * lkst_encounter_a_BUG (const char *file, int line)
+{
+	hook_rec_t* phookrec;
+	int etype;
+	/* make all hook point disarmed*/
+	for ( etype = 0; etype <= LKST_ETYPE_MAX ; etype++) {
+		phookrec = lkst_hook_info_table[etype].phookrec;
+		if(phookrec != NULL) hook_exit_disarm(phookrec);
+	}
+	/* Now we encounter a bug. and cannot help ourselves. 
+	 Only what we can do is panic dump.*/
+	panic("LKST encounter a BUG at %s : %d\n", file, line);
+	return NULL;
+}
+EXPORT_SYMBOL(lkst_encounter_a_BUG);
+
+/*
+ * function lkst_time_set
+ * This function sets time stamp of LKST header.
+ * 
+ *  Arguments
+ *    from_settimeofday : flag shows to be called from do_sys_settimeofday().
+ *  returns
+ *    NONE
+ * 
+ */
+void lkst_time_set(int from_settimeofday)
+{
+	unsigned long flags;
+	local_irq_save(flags);
+	if (from_settimeofday)
+		lkst.cmos_time_flag = 0;
+	do_gettimeofday(&lkst.xtime);
+	lkst.tsc = lkst_evhandlerprim_mc();
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(lkst_time_set);
+
+
+/*
+ * This function is called by lkst modules to get
+ * variable "cpu_khz" from LKST_GET_CPU_KHZ().
+ * In some arch, LKST will not provide this function.
+ */
+#ifdef	LKST_GET_CPU_KHZ
+lkst_cpu_freq_t lkst_get_cpu_khz(void)
+{
+	return LKST_GET_CPU_KHZ();
+}
+EXPORT_SYMBOL(lkst_get_cpu_khz);
+#endif /* ifdef	LKST_GET_CPU_KHZ */
+
+
+extern char _stext, _etext;
+
+#ifdef CONFIG_MODULES
+/* These symbols are not exported. so we must 
+   embed this function into kernel itself. */
+extern struct module *module_list;
+extern struct module kernel_module;
+/*
+ * function lkst_find_module_by_address
+ * Find module in which specified address is contained, and return
+ * pointer to the module.
+ * 
+ *  Note: This function is used from stack trace module only.
+ * 
+ *  Arguments
+ *    addr {IN}:	address.
+ *
+ *  returns
+ *    address to the module.
+ * 
+ */
+static __inline__ struct module * \
+lkst_find_module_by_address_inline(unsigned long addr)
+{
+	struct module *mod;
+
+	if (addr >= (unsigned long) &_stext &&
+	    addr <= (unsigned long) &_etext)
+		return &kernel_module;
+
+	// TODO: avoid conflicts without spin_lock(&modlist_lock);
+
+	for (mod = module_list;
+	     mod != &kernel_module && 
+	     mod != NULL ; mod = mod->next) {
+		if (!(mod->flags&MOD_RUNNING))
+			return NULL;
+		if (mod->flags&MOD_DELETED)
+			return NULL;
+		/* mod_bound tests for addr being inside the vmalloc'ed
+		 * module area. Of course it'd be better to test only
+		 * for the .text subset... */
+		if (mod_bound(addr, 0, mod)) {
+			return mod;
+			break;
+		}
+	}
+	/* address was not found. */
+	return NULL;
+}
+#else /* !CONFIG_MODULES */
+static __inline__ struct module * \
+lkst_find_module_by_address_inline(unsigned long addr)
+{
+	if (addr >= (unsigned long) &_stext &&
+	    addr <= (unsigned long) &_etext)
+		return &kernel_module;
+	return NULL;
+}
+#endif /* CONFIG_MODULES */
+
+/*
+ * function lkst_find_module_by_address
+ * Find module in which specified address is contained, and return
+ * pointer to the module.
+ * 
+ *  Caution: This function does not verify value of event_entry_p.
+ * 
+ *  Arguments
+ *    addr {IN}:	address.
+ *
+ *  returns
+ *    address to the module.
+ * 
+ */
+
+struct module * lkst_find_module_by_address(unsigned long addr)
+{
+	return (lkst_find_module_by_address_inline(addr));
+}
+EXPORT_SYMBOL(lkst_find_module_by_address);
+
+
+/*
+ * Function lkst_maxvm_setup
+ * This function gets size of lkst available memory area from kernel parameter.
+ */
+
+static int __init lkst_maxvm_setup(char *line)
+{
+	int size;
+	if (get_option(&line, &size))
+		lkst.available_memory_size = (size_t) size;
+	return 1;
+}
+ 
+__setup("lkst_maxvm=", lkst_maxvm_setup);
+
+/* instead of module param. */
+#ifdef CONFIG_DEBUG_KERNEL_STATE_TRACE
+
+extern int lkst_init_maskset;
+
+static int __init lkst_startup_maskset(char *line)
+{
+	int mask;
+	if (get_option(&line, &mask)) {
+		if (mask >= 0 && mask <=2)
+			lkst_init_maskset = (lkst_maskset_id) mask;
+	}
+	return 1;
+}	
+ 
+__setup("lkst_maskset=", lkst_startup_maskset);
+
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE*/
+/*
+ * Function lkst_mem_area_init
+ * Set : lkst.available_memory_size, lkst.limit_addr
+ * Ths area size is set by kernel parameter `lkst_maxvm=`. If omitted,
+ * the size is set to architecture specific size. 
+ * But if 1/8 of physical memory size is less than it, 
+ * 1/8 of physical memory is allocated.
+ * The allocation limit address is stored as lkst.limit_addr.
+ */
+#ifndef __i386__
+void lkst_mem_area_init(void) 
+{
+	char *buf;
+	unsigned long size;
+	size = lkst.available_memory_size;
+	if ( !size  ) {
+		size = PAGE_SIZE * (num_physpages >> 3);
+	}	
+	if ( size > LKST_AVAILABLE_MEMORY_MAX ) {
+		size = LKST_AVAILABLE_MEMORY_MAX;
+	}
+	buf = (char *) (VMALLOC_START & 0xf000000000000000);
+	lkst.available_memory_size = size;
+	(char *) lkst.limit_addr = (char *) buf + size;
+	printk(KERN_INFO "LKST information: Avaliable memory area is up to an address 0x%p, size is %ld bytes\n", lkst.limit_addr, size);
+}
+
+#else /*__i386__*/
+/*
+ * ifarch i386
+ * This function allocates dummy memory area to gets page directory entry
+ * for LKST using memory area. Because of updating entries of page tables of kernel.
+ * Note. The vmalloc function allocates required size + a page size.
+ * TODO: port to arch/.../kernel/lkst_kernel.c
+ */
+void lkst_mem_area_init(void)
+{
+	char *buf;
+	unsigned long size;
+	unsigned long max_size;
+	int i;
+	int reserve_size;
+	size = lkst.available_memory_size;
+
+	if ( (buf = vmalloc(PAGE_SIZE))==NULL )
+	{
+		printk(KERN_ERR "LKST error: Cannot get available memory area , a page");
+		return;
+	};
+	vfree(buf);
+	if ( VMALLOC_RESERVE>(VMALLOC_END-VMALLOC_START) )
+		reserve_size=(unsigned long)VMALLOC_END-(unsigned long)VMALLOC_START;
+	else
+		reserve_size=VMALLOC_RESERVE-VMALLOC_OFFSET;
+       	max_size=reserve_size-(4*PAGE_SIZE)-((unsigned long)(buf)-VMALLOC_START);
+	max_size=(max_size+(PAGE_SIZE-1))&~PAGE_SIZE;
+
+	printk("LKST information: Available max memory area is %lu bytes. " \
+	       "START=%#lx-%#lx %#x MEMMAX=%#lx reserve size=%d\n",
+	       max_size, VMALLOC_START,VMALLOC_END,
+	       (unsigned int)buf,MAXMEM,reserve_size);
+
+	if ( !size  )
+	{
+		size = PAGE_SIZE * (num_physpages >> 3);
+		if ( size>max_size )
+		{
+			size=max_size;
+		}
+	}
+	else
+	{
+		if ( size>max_size )
+		{
+			printk(KERN_INFO "LKST warning: Cannot get available memory area(auto size=%ld), size is setted to %ld\n",size,max_size);
+			size=max_size;
+		}
+	}
+	buf = vmalloc(size);
+
+	if (buf==NULL) {
+		printk(KERN_ERR "LKST warning: Cannot get available memory area(size=%ld)"
+		       " for LKST! Please restart kernel, or cannot allocate memory for LKST.\n", size);
+		return;
+	} 
+
+	/* get pages dirty... */
+	for ( i = 0; i < size ; i+= PAGE_SIZE) {
+	  buf[i] = 1;
+	}
+	vfree(buf);
+	lkst.available_memory_size = size;
+	(char *) lkst.limit_addr = (char *) buf + size;
+	printk(KERN_INFO "LKST information: LKST Avaliable memory area is up to an address 0x%p, size is %ld bytes\n", lkst.limit_addr, size);
+
+}
+#endif /*__i386__*/
+
+struct lkst_hook_info lkst_hook_info_table[LKST_MASKSET_TABLE_LEN_MAX];
+EXPORT_SYMBOL(lkst_hook_info_table);
+
+/* Declaration of hook header */
+#define LKST_ETYPE_DECLARE_HOOKHEADER
+#include <linux/lkst_events.h>
+#undef  LKST_ETYPE_DECLARE_HOOKHEADER
+
+void lkst_trc_hook_init(void)
+{
+	int ret, retall = 0;
+	int i;
+
+	/* Initialize lkst_hook_info_table */
+	for(i=0; i<LKST_MASKSET_TABLE_LEN_MAX; i++){
+		lkst_hook_info_table[i].hook_id = NULL;
+		lkst_hook_info_table[i].phookrec = NULL;
+	}
+
+/* Initialization of hook header */
+#define LKST_ETYPE_INIT_HOOK
+#include <linux/lkst_events.h>
+#undef  LKST_ETYPE_INIT_HOOK
+
+	if (retall) {
+		printk(KERN_ERR "LKST error(hook_init): hook_init failed: %u\n", ret);
+	}
+}
+
+void lkst_trc_hook_cleanup(void)
+{
+	int ret, retall = 0;
+
+/* Cleanup of hook */
+#define LKST_ETYPE_TERMINATE_HOOK
+#include <linux/lkst_events.h>
+#undef  LKST_ETYPE_TERMINATE_HOOK
+
+	if (retall) {
+		printk(KERN_ERR "LKST error(hook_cleanup): hook_cleanup failed: %u\n", ret);
+	}
+}
+EXPORT_SYMBOL(lkst_trc_hook_init);
+EXPORT_SYMBOL(lkst_trc_hook_cleanup);
diff -Naru linux-2.4.19/kernel/panic.c linux-2.4.19-lkst/kernel/panic.c
--- linux-2.4.19/kernel/panic.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/panic.c	2003-04-14 15:05:14.000000000 -0400
@@ -15,6 +15,9 @@
 #include <linux/notifier.h>
 #include <linux/dump.h>
 #include <linux/init.h>
+
+#include <linux/lkst.h>
+
 #include <linux/sysrq.h>
 #include <linux/interrupt.h>
 
@@ -60,6 +63,12 @@
 	get_current_regs(&regs);
 #endif
 
+	LKST_HOOK(LKST_ETYPE_O_PANIC,
+		       LKST_ARGP(fmt),
+		       LKST_ARGP(__builtin_return_address(0)),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	bust_spinlocks(1);
 	va_start(args, fmt);
 	vsprintf(buf, fmt, args);
diff -Naru linux-2.4.19/kernel/printk.c linux-2.4.19-lkst/kernel/printk.c
--- linux-2.4.19/kernel/printk.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/printk.c	2003-04-14 15:05:14.000000000 -0400
@@ -28,6 +28,8 @@
 #include <linux/config.h>
 
 #include <asm/uaccess.h>
+#include <linux/lkst.h>
+
 
 #if defined(CONFIG_MULTIQUAD) || defined(CONFIG_IA64)
 #define LOG_BUF_LEN	(65536)
@@ -413,6 +415,12 @@
 	static char printk_buf[1024];
 	static int log_level_unknown = 1;
 
+	LKST_HOOK(LKST_ETYPE_O_PRINTK,
+		       LKST_ARGP(fmt),
+		       LKST_ARGP(__builtin_return_address(0)),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	if (oops_in_progress) {
 		/* If a crash is occurring, make sure we can't deadlock */
 		spin_lock_init(&logbuf_lock);
diff -Naru linux-2.4.19/kernel/sched.c linux-2.4.19-lkst/kernel/sched.c
--- linux-2.4.19/kernel/sched.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/sched.c	2003-04-14 15:05:14.000000000 -0400
@@ -34,6 +34,9 @@
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
 
+#include <linux/lkst.h>
+#include <linux/lkst_private.h>
+
 extern void timer_bh(void);
 extern void tqueue_bh(void);
 extern void immediate_bh(void);
@@ -354,6 +357,9 @@
 	unsigned long flags;
 	int success = 0;
 
+	LKST_HOOK_INLINE(LKST_ETYPE_PROCESS_WAKEUP,
+			LKST_ARGP(p), LKST_ARG(synchronous),
+			LKST_ARG(0), LKST_ARG(0));
 	/*
 	 * We want the common case fall through straight, thus the goto.
 	 */
@@ -553,7 +559,9 @@
 	struct task_struct *prev, *next, *p;
 	struct list_head *tmp;
 	int this_cpu, c;
-
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+        int lkst_current_counter = current->counter;
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
 
 #if defined(CONFIG_DUMP) || defined(CONFIG_DUMP_MODULE)
 	if (dump_in_progress) {
@@ -561,6 +569,15 @@
 	}
 #endif
 
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+	if ( waitqueue_active(&lkst_current.owner.wait) && 
+	     lkst_current.owner.ready ) {
+		/* If owner is ready to read, wake it up.*/
+		lkst_current.owner.ready = 0;
+		wake_up_interruptible(&lkst_current.owner.wait);
+	}
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
+	
 	spin_lock_prefetch(&runqueue_lock);
 
 	BUG_ON(!current->active_mm);
@@ -701,6 +718,11 @@
 	 * This just switches the register state and the
 	 * stack.
 	 */
+        LKST_HOOK(LKST_ETYPE_PROCESS_CONTEXTSWITCH,
+		       LKST_ARGP(prev), LKST_ARGP(next),
+		       LKST_ARG(prev->state),
+		       LKST_ARG(lkst_current_counter)); 
+// TODO : add SYNC events
 	switch_to(prev, next, prev);
 	__schedule_tail(prev);
 
diff -Naru linux-2.4.19/kernel/signal.c linux-2.4.19-lkst/kernel/signal.c
--- linux-2.4.19/kernel/signal.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/signal.c	2003-04-14 15:05:14.000000000 -0400
@@ -16,6 +16,8 @@
 
 #include <asm/uaccess.h>
 
+#include <linux/lkst.h>
+
 /*
  * SLAB caches for signal bits.
  */
@@ -540,6 +542,11 @@
 printk("SIG queue (%s:%d): %d ", t->comm, t->pid, sig);
 #endif
 
+	LKST_HOOK(LKST_ETYPE_PROCESS_SIGSEND,
+			LKST_ARG(sig), LKST_ARGP(t),
+			LKST_ARGP(info),
+			LKST_ARG(0));
+
 	ret = -EINVAL;
 	if (sig < 0 || sig > _NSIG)
 		goto out_nolock;
diff -Naru linux-2.4.19/kernel/softirq.c linux-2.4.19-lkst/kernel/softirq.c
--- linux-2.4.19/kernel/softirq.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/softirq.c	2003-04-14 15:05:14.000000000 -0400
@@ -17,6 +17,8 @@
 #include <linux/init.h>
 #include <linux/tqueue.h>
 
+#include <linux/lkst.h>
+
 /*
    - No shared variables, all the data are CPU local.
    - If a softirq needs serialization, let it serialize itself
@@ -192,6 +194,9 @@
 			if (!atomic_read(&t->count)) {
 				if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
 					BUG();
+	LKST_HOOK(LKST_ETYPE_INT_TASKLET_ENTRY,
+		  LKST_ARGP(t->func), LKST_ARG(0),
+		  LKST_ARG(0), LKST_ARG(0));
 				t->func(t->data);
 				tasklet_unlock(t);
 				continue;
@@ -226,6 +231,9 @@
 			if (!atomic_read(&t->count)) {
 				if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
 					BUG();
+	LKST_HOOK(LKST_ETYPE_INT_TASKLETHI_ENTRY,
+		  LKST_ARGP(t->func), LKST_ARG(0),
+		  LKST_ARG(0), LKST_ARG(0));
 				t->func(t->data);
 				tasklet_unlock(t);
 				continue;
@@ -297,7 +305,16 @@
 		goto resched_unlock;
 
 	if (bh_base[nr])
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+        {
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
+		LKST_HOOK(LKST_ETYPE_INT_BH_ENTRY,
+			  LKST_ARG(nr), LKST_ARGP(bh_base[nr]),
+			  LKST_ARG(0), LKST_ARG(0));
 		bh_base[nr]();
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+        }
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
 
 	hardirq_endlock(cpu);
 	spin_unlock(&global_bh_lock);
diff -Naru linux-2.4.19/kernel/sys.c linux-2.4.19-lkst/kernel/sys.c
--- linux-2.4.19/kernel/sys.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/sys.c	2003-04-14 15:05:14.000000000 -0400
@@ -21,6 +21,8 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
+#include <linux/lkst.h>
+
 /*
  * this is where the system-wide overflow UID and GID are defined, for
  * architectures that now have 32-bit UID/GID but didn't in the past
@@ -448,6 +450,9 @@
 	current->fsgid = new_egid;
 	current->egid = new_egid;
 	current->gid = new_rgid;
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_GID,
+		       LKST_ARG(new_rgid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return 0;
 }
 
@@ -480,6 +485,9 @@
 	}
 	else
 		return -EPERM;
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_GID,
+		       LKST_ARG(current->gid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return 0;
 }
   
@@ -553,6 +561,9 @@
 	current->uid = new_ruid;
 	current->user = new_user;
 	free_uid(old_user);
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_UID,
+		       LKST_ARG(new_ruid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return 0;
 }
 
@@ -713,7 +724,9 @@
 	if (!(retval = put_user(current->uid, ruid)) &&
 	    !(retval = put_user(current->euid, euid)))
 		retval = put_user(current->suid, suid);
-
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_UID,
+		       LKST_ARG(*ruid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return retval;
 }
 
@@ -746,6 +759,9 @@
 		current->gid = rgid;
 	if (sgid != (gid_t) -1)
 		current->sgid = sgid;
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_GID,
+		       LKST_ARG(current->gid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return 0;
 }
 
@@ -756,7 +772,9 @@
 	if (!(retval = put_user(current->gid, rgid)) &&
 	    !(retval = put_user(current->egid, egid)))
 		retval = put_user(current->sgid, sgid);
-
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_GID,
+		       LKST_ARG(current->gid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return retval;
 }
 
@@ -902,6 +920,9 @@
 ok_pgid:
 	p->pgrp = pgid;
 	err = 0;
+	LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_PGID,
+		       LKST_ARG(p->pid), LKST_ARG(p->pgrp),
+		       LKST_ARGP(p), LKST_ARG(p->leader)); 
 out:
 	/* All paths lead to here, thus we are safe. -DaveM */
 	read_unlock(&tasklist_lock);
@@ -911,6 +932,11 @@
 asmlinkage long sys_getpgid(pid_t pid)
 {
 	if (!pid) {
+		LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_PGID,
+			       LKST_ARG(current->pid),
+			       LKST_ARG(current->pgrp),
+			       LKST_ARGP(current),
+			       LKST_ARG(current->leader)); 
 		return current->pgrp;
 	} else {
 		int retval;
@@ -922,6 +948,14 @@
 		retval = -ESRCH;
 		if (p)
 			retval = p->pgrp;
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+		if (p) 
+			LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_PGID,
+				       LKST_ARG(p->pid),
+				       LKST_ARG(p->pgrp),
+				       LKST_ARGP(p),
+				       LKST_ARG(p->leader));
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
 		read_unlock(&tasklist_lock);
 		return retval;
 	}
@@ -930,6 +964,11 @@
 asmlinkage long sys_getpgrp(void)
 {
 	/* SMP - assuming writes are word atomic this is fine */
+	LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_PGID,
+		       LKST_ARG(current->pid),
+		       LKST_ARG(current->pgrp),
+		       LKST_ARGP(current),
+		       LKST_ARG(current->leader));
 	return current->pgrp;
 }
 
@@ -970,6 +1009,11 @@
 	err = current->pgrp;
 out:
 	read_unlock(&tasklist_lock);
+	LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_PGID,
+		       LKST_ARG(current->pid),
+		       LKST_ARG(current->pgrp),
+		       LKST_ARGP(current),
+		       LKST_ARG(current->leader));
 	return err;
 }
 
diff -Naru linux-2.4.19/kernel/time.c linux-2.4.19-lkst/kernel/time.c
--- linux-2.4.19/kernel/time.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/time.c	2003-04-14 15:05:14.000000000 -0400
@@ -30,6 +30,10 @@
 
 #include <asm/uaccess.h>
 
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+#include <linux/lkst.h>
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
+
 /* 
  * The timezone where the local system is located.  Used as a default by some
  * programs who obtain this value by using gettimeofday.
@@ -164,6 +168,10 @@
 		 */
 		do_settimeofday(tv);
 	}
+#if defined(CONFIG_DEBUG_KERNEL_STATE_TRACE) ||  defined(CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE)
+	if (!firsttime)
+		lkst_time_set(1);
+#endif /* CONFIG_DEBUG_KERNEL_STATE_TRACE || CONFIG_DEBUG_KERNEL_STATE_TRACE_MODULE*/
 	return 0;
 }
 
diff -Naru linux-2.4.19/kernel/timer.c linux-2.4.19-lkst/kernel/timer.c
--- linux-2.4.19/kernel/timer.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/kernel/timer.c	2003-04-14 15:05:14.000000000 -0400
@@ -25,6 +25,8 @@
 
 #include <asm/uaccess.h>
 
+#include <linux/lkst.h>
+
 /*
  * Timekeeping variables
  */
@@ -185,6 +187,11 @@
 	if (timer_pending(timer))
 		goto bug;
 	internal_add_timer(timer);
+        LKST_HOOK(LKST_ETYPE_TIMER_ADD,
+		       LKST_ARGP(timer),
+		       LKST_ARG(timer->expires),
+		       LKST_ARGP(timer->function),
+		       LKST_ARG(timer->data)); 
 	spin_unlock_irqrestore(&timerlist_lock, flags);
 	return;
 bug:
@@ -210,6 +217,11 @@
 	timer->expires = expires;
 	ret = detach_timer(timer);
 	internal_add_timer(timer);
+        LKST_HOOK(LKST_ETYPE_TIMER_MOD,
+		       LKST_ARGP(timer),
+		       LKST_ARG(timer->expires),
+		       LKST_ARGP(timer->function),
+		       LKST_ARG(timer->data)); 
 	spin_unlock_irqrestore(&timerlist_lock, flags);
 	return ret;
 }
@@ -220,6 +232,11 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&timerlist_lock, flags);
+        LKST_HOOK(LKST_ETYPE_TIMER_DEL,
+		       LKST_ARGP(timer),
+		       LKST_ARG(timer->expires),
+		       LKST_ARGP(timer->function),
+		       LKST_ARG(timer->data)); 
 	ret = detach_timer(timer);
 	timer->list.next = timer->list.prev = NULL;
 	spin_unlock_irqrestore(&timerlist_lock, flags);
@@ -244,6 +261,11 @@
 {
 	int ret = 0;
 
+        LKST_HOOK(LKST_ETYPE_TIMER_DEL_SYNC,
+		       LKST_ARGP(timer),
+		       LKST_ARG(timer->expires),
+		       LKST_ARGP(timer->function),
+		       LKST_ARG(timer->data)); 
 	for (;;) {
 		unsigned long flags;
 		int running;
@@ -319,6 +341,12 @@
 			timer_enter(timer);
 			spin_unlock_irq(&timerlist_lock);
 			fn(data);
+
+			LKST_HOOK_INLINE(LKST_ETYPE_TIMER_RUN,
+					 LKST_ARGP(fn),
+					 LKST_ARG(data),
+					 LKST_ARG(0),
+					 LKST_ARG(0));
 			spin_lock_irq(&timerlist_lock);
 			timer_exit();
 			goto repeat;
@@ -787,6 +815,9 @@
 asmlinkage long sys_getuid(void)
 {
 	/* Only we change this so SMP safe */
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_UID,
+		       LKST_ARG(current->uid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return current->uid;
 }
 
@@ -799,7 +830,11 @@
 asmlinkage long sys_getgid(void)
 {
 	/* Only we change this so SMP safe */
+        LKST_HOOK_INLINE(LKST_ETYPE_LKST_SYNC_GID,
+		       LKST_ARG(current->gid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return current->gid;
+
 }
 
 asmlinkage long sys_getegid(void)
@@ -813,6 +848,9 @@
 /* Thread ID - the internal kernel "pid" */
 asmlinkage long sys_gettid(void)
 {
+        LKST_HOOK(LKST_ETYPE_LKST_SYNC_TID,
+		       LKST_ARG(current->pid), LKST_ARG(0),
+		       LKST_ARGP(current), LKST_ARG(0)); 
 	return current->pid;
 }
 
diff -Naru linux-2.4.19/mm/filemap.c linux-2.4.19-lkst/mm/filemap.c
--- linux-2.4.19/mm/filemap.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/filemap.c	2003-04-14 15:05:15.000000000 -0400
@@ -30,6 +30,8 @@
 
 #include <linux/highmem.h>
 
+#include <linux/lkst.h>
+
 /*
  * Shared mappings implemented 30.11.1994. It's not fully working yet,
  * though.
@@ -819,6 +821,12 @@
 	struct task_struct *tsk = current;
 	DECLARE_WAITQUEUE(wait, tsk);
 
+ 	LKST_HOOK(LKST_ETYPE_MEM_WAIT_PAGE,
+		  LKST_ARGP(page),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0));
+ 
 	add_wait_queue(waitqueue, &wait);
 	do {
 		set_task_state(tsk, TASK_UNINTERRUPTIBLE);
diff -Naru linux-2.4.19/mm/memory.c linux-2.4.19-lkst/mm/memory.c
--- linux-2.4.19/mm/memory.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/memory.c	2003-04-14 15:05:15.000000000 -0400
@@ -50,6 +50,8 @@
 #include <asm/uaccess.h>
 #include <asm/tlb.h>
 
+#include <linux/lkst.h>
+
 unsigned long max_mapnr;
 unsigned long num_physpages;
 unsigned long num_mappedpages;
@@ -977,6 +979,12 @@
 		goto no_mem;
 	copy_cow_page(old_page,new_page,address);
 
+	LKST_HOOK(LKST_ETYPE_MEM_DO_WPPAGE,
+		       LKST_ARGP(new_page),
+		       LKST_ARG(0),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	/*
 	 * Re-check the pte - we dropped the lock
 	 */
@@ -1180,6 +1188,13 @@
 	/* No need to invalidate - it was non-present before */
 	update_mmu_cache(vma, address, pte);
 	spin_unlock(&mm->page_table_lock);
+
+	LKST_HOOK(LKST_ETYPE_MEM_SWAPIN,
+		       LKST_ARGP(page),
+		       LKST_ARG(0),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	return ret;
 }
 
@@ -1305,6 +1320,13 @@
 	/* no need to invalidate: a not-present page shouldn't be cached */
 	update_mmu_cache(vma, address, entry);
 	spin_unlock(&mm->page_table_lock);
+
+	LKST_HOOK(LKST_ETYPE_MEM_DO_NOPAGE,
+		       LKST_ARGP(new_page),
+		       LKST_ARG(0),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	return 2;	/* Major fault */
 }
 
diff -Naru linux-2.4.19/mm/page_alloc.c linux-2.4.19-lkst/mm/page_alloc.c
--- linux-2.4.19/mm/page_alloc.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/page_alloc.c	2003-04-14 15:05:15.000000000 -0400
@@ -22,6 +22,8 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 
+#include <linux/lkst.h>
+
 int nr_swap_pages;
 int nr_active_pages;
 int nr_inactive_pages;
@@ -419,11 +421,19 @@
 unsigned long __get_free_pages(unsigned int gfp_mask, unsigned int order)
 {
 	struct page * page;
+	unsigned long paddr;
 
 	page = alloc_pages(gfp_mask, order);
 	if (!page)
 		return 0;
-	return (unsigned long) page_address(page);
+	paddr = (unsigned long) page_address(page);
+	LKST_HOOK(LKST_ETYPE_MEM_GET_FREEPAGE,
+		       LKST_ARG(paddr),
+		       LKST_ARG(gfp_mask),
+		       LKST_ARG(order),
+		       LKST_ARGP(__builtin_return_address(0)));
+
+	return paddr;
 }
 
 unsigned long get_zeroed_page(unsigned int gfp_mask)
@@ -434,6 +444,11 @@
 	if (page) {
 		void *address = page_address(page);
 		clear_page(address);
+		LKST_HOOK(LKST_ETYPE_MEM_GET_ZEROPAGE,
+			       LKST_ARGP(address),
+			       LKST_ARG(gfp_mask),
+			       LKST_ARGP(__builtin_return_address(0)),
+			       LKST_ARG(0));
 		return (unsigned long) address;
 	}
 	return 0;
@@ -447,8 +462,14 @@
 
 void free_pages(unsigned long addr, unsigned int order)
 {
-	if (addr != 0)
+	if (addr != 0) {
+		LKST_HOOK(LKST_ETYPE_MEM_FREEPAGE,
+			       LKST_ARG(addr), 
+			       LKST_ARG(order),
+			       LKST_ARGP(__builtin_return_address(0)),
+			       LKST_ARG(0));
 		__free_pages(virt_to_page(addr), order);
+	}
 }
 
 /*
diff -Naru linux-2.4.19/mm/slab.c linux-2.4.19-lkst/mm/slab.c
--- linux-2.4.19/mm/slab.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/slab.c	2003-04-14 15:05:15.000000000 -0400
@@ -76,6 +76,8 @@
 #include	<linux/seq_file.h>
 #include	<asm/uaccess.h>
 
+#include <linux/lkst.h>
+
 /*
  * DEBUG	- 1 for kmem_cache_create() to honour; SLAB_DEBUG_INITIAL,
  *		  SLAB_RED_ZONE & SLAB_POISON.
@@ -822,6 +824,13 @@
 	list_add(&cachep->next, &cache_chain);
 	up(&cache_chain_sem);
 opps:
+
+	LKST_HOOK(LKST_ETYPE_MEM_CACHE_CREATE,
+		       LKST_ARGP(name),
+		       LKST_ARG(size),
+		       LKST_ARGP(cachep),
+		       LKST_ARG(0));
+
 	return cachep;
 }
 
@@ -1528,7 +1537,16 @@
  */
 void * kmem_cache_alloc (kmem_cache_t *cachep, int flags)
 {
-	return __kmem_cache_alloc(cachep, flags);
+	void* objp;
+	objp = __kmem_cache_alloc(cachep, flags);
+
+	LKST_HOOK(LKST_ETYPE_MEM_CACHE_ALLOC,
+		       LKST_ARGP(cachep),
+		       LKST_ARG(flags),
+		       LKST_ARGP(objp),
+		       LKST_ARGP(__builtin_return_address(0)));
+
+	return objp;
 }
 
 /**
@@ -1554,13 +1572,23 @@
  */
 void * kmalloc (size_t size, int flags)
 {
+	void* objp;
 	cache_sizes_t *csizep = cache_sizes;
 
 	for (; csizep->cs_size; csizep++) {
 		if (size > csizep->cs_size)
 			continue;
-		return __kmem_cache_alloc(flags & GFP_DMA ?
+
+		objp = __kmem_cache_alloc(flags & GFP_DMA ?
 			 csizep->cs_dmacachep : csizep->cs_cachep, flags);
+
+		LKST_HOOK(LKST_ETYPE_MEM_MALLOC,
+			       LKST_ARG(size),
+			       LKST_ARG(flags),
+			       LKST_ARGP(objp),
+			       LKST_ARGP(__builtin_return_address(0)));
+
+		return objp;
 	}
 	return NULL;
 }
@@ -1576,6 +1604,13 @@
 void kmem_cache_free (kmem_cache_t *cachep, void *objp)
 {
 	unsigned long flags;
+
+	LKST_HOOK(LKST_ETYPE_MEM_CACHE_FREE,
+		       LKST_ARGP(cachep),
+		       LKST_ARGP(objp),
+		       LKST_ARGP(__builtin_return_address(0)),
+		       LKST_ARG(0));
+
 #if DEBUG
 	CHECK_PAGE(virt_to_page(objp));
 	if (cachep != GET_PAGE_CACHE(virt_to_page(objp)))
@@ -1599,6 +1634,12 @@
 	kmem_cache_t *c;
 	unsigned long flags;
 
+	LKST_HOOK(LKST_ETYPE_MEM_FREE,
+		       LKST_ARGP(objp),
+		       LKST_ARGP(__builtin_return_address(0)),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	if (!objp)
 		return;
 	local_irq_save(flags);
diff -Naru linux-2.4.19/mm/vmalloc.c linux-2.4.19-lkst/mm/vmalloc.c
--- linux-2.4.19/mm/vmalloc.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/vmalloc.c	2003-04-14 15:05:15.000000000 -0400
@@ -16,6 +16,8 @@
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 
+#include <linux/lkst.h>
+
 rwlock_t vmlist_lock = RW_LOCK_UNLOCKED;
 struct vm_struct * vmlist;
 
@@ -188,6 +190,8 @@
 		if (addr > VMALLOC_END-size)
 			goto out;
 	}
+	if (addr > VMALLOC_END-size)
+		goto out;
 	area->flags = flags;
 	area->addr = (void *)addr;
 	area->size = size;
@@ -208,6 +212,13 @@
 
 	if (!addr)
 		return;
+
+	LKST_HOOK(LKST_ETYPE_MEM_VFREE,
+		       LKST_ARGP(addr),
+		       LKST_ARG(0),
+		       LKST_ARG(0),
+		       LKST_ARG(0));
+
 	if ((PAGE_SIZE-1) & (unsigned long) addr) {
 		printk(KERN_ERR "Trying to vfree() bad address (%p)\n", addr);
 		return;
diff -Naru linux-2.4.19/mm/vmscan.c linux-2.4.19-lkst/mm/vmscan.c
--- linux-2.4.19/mm/vmscan.c	2003-04-14 15:02:55.000000000 -0400
+++ linux-2.4.19-lkst/mm/vmscan.c	2003-04-14 15:05:14.000000000 -0400
@@ -23,6 +23,8 @@
 
 #include <asm/pgalloc.h>
 
+#include <linux/lkst.h>
+
 /*
  * The "priority" of VM scanning is how much of the queues we
  * will scan in one go. A value of 6 for DEF_PRIORITY implies
@@ -91,6 +93,13 @@
 		{
 			int freeable = page_count(page) - !!page->buffers <= 2;
 			page_cache_release(page);
+
+			LKST_HOOK_INLINE(LKST_ETYPE_MEM_SWAPOUT,
+				       LKST_ARGP(page),
+				       LKST_ARG(0),
+				       LKST_ARG(0),
+				       LKST_ARG(0));
+
 			return freeable;
 		}
 	}
diff -Naru linux-2.4.19/net/core/dev.c linux-2.4.19-lkst/net/core/dev.c
--- linux-2.4.19/net/core/dev.c	2003-04-14 15:03:24.000000000 -0400
+++ linux-2.4.19-lkst/net/core/dev.c	2003-04-14 15:05:43.000000000 -0400
@@ -107,6 +107,7 @@
 #ifdef CONFIG_PLIP
 extern int plip_init(void);
 #endif
+#include <linux/lkst.h>
 
 
 /* This define, if set, will randomly drop a packet when congestion
@@ -978,6 +979,12 @@
 	struct net_device *dev = skb->dev;
 	struct Qdisc  *q;
 
+        LKST_HOOK(LKST_ETYPE_NET_PKTSEND,
+		  LKST_ARGP(skb),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0)); 
+
 	if (skb_shinfo(skb)->frag_list &&
 	    !(dev->features&NETIF_F_FRAGLIST) &&
 	    skb_linearize(skb, GFP_ATOMIC) != 0) {
@@ -1218,6 +1225,11 @@
 	struct softnet_data *queue;
 	unsigned long flags;
 
+        LKST_HOOK(LKST_ETYPE_NET_PKTRECV,
+		  LKST_ARGP(skb),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0)); 
 	if (skb->stamp.tv_sec == 0)
 		do_gettimeofday(&skb->stamp);
 
@@ -1327,6 +1339,12 @@
 {
 	int cpu = smp_processor_id();
 
+        LKST_HOOK(LKST_ETYPE_NET_PKTSENDI,
+		  LKST_ARGP(h),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0)); 
+
 	if (softnet_data[cpu].completion_queue) {
 		struct sk_buff *clist;
 
@@ -1426,6 +1444,12 @@
 
 	br_read_lock(BR_NETPROTO_LOCK);
 
+        LKST_HOOK(LKST_ETYPE_NET_PKTRECVI,
+		  LKST_ARGP(h),
+		  LKST_ARG(0),
+		  LKST_ARG(0),
+		  LKST_ARG(0)); 
+
 	for (;;) {
 		struct sk_buff *skb;
 		struct net_device *rx_dev;
diff -Naru linux-2.4.19/net/socket.c linux-2.4.19-lkst/net/socket.c
--- linux-2.4.19/net/socket.c	2003-04-14 15:03:23.000000000 -0400
+++ linux-2.4.19-lkst/net/socket.c	2003-04-14 15:05:42.000000000 -0400
@@ -84,6 +84,7 @@
 #include <net/sock.h>
 #include <net/scm.h>
 #include <linux/netfilter.h>
+#include <linux/lkst.h>
 
 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
 static ssize_t sock_read(struct file *file, char *buf,
@@ -1538,6 +1539,11 @@
 	unsigned long a0,a1;
 	int err;
 
+        LKST_HOOK(LKST_ETYPE_NET_SOCKETIF,
+			LKST_ARG(call), LKST_ARGP(args),
+			LKST_ARG(0),
+			LKST_ARG(0)); 
+
 	if(call<1||call>SYS_RECVMSG)
 		return -EINVAL;
 
