--- cvc_linux-rh-gcc3-3.5/src/linux_wrapper.c	2007-09-10 15:37:01.000000000 +0000
+++ cvc_linux-rh-gcc3-3.5/src/linux_wrapper.c	2007-09-10 15:36:15.000000000 +0000
@@ -99,17 +99,45 @@
   struct rtable;
 #endif
 
+int backtrace_flag;
+int backtrace_debug[1024];
+void enter_func(int line) {
+	int i;
+	for(i=0; i<1024 && backtrace_debug[i]; ++i);
+	if (i == 1024) printk("overflow\n");
+	backtrace_debug[i] = line;
+	if (backtrace_flag) {printk("{ "); backtrace();}
+}
+void exit_func() {
+	int i;
+	for(i=1; i<1024 && backtrace_debug[i]; ++i);
+	--i;
+	if (backtrace_flag) {printk("} "); backtrace();}
+	backtrace_debug[i] = 0;
+}
+void backtrace() {
+	int i;
+	for(i=0; i<1024 && backtrace_debug[i]; ++i) {
+		printk("%d,", backtrace_debug[i]);
+	}
+	printk("\n");
+	backtrace_flag = 1;
+}
+
 static inline int ip_route_output(struct rtable **rp,
                                       u32 daddr, u32 saddr, u32 tos, int oif)
 {
   struct flowi flw;
 
+  enter_func(__LINE__);
   flw.fl4_dst=daddr;
   flw.fl4_src=saddr;
   flw.oif=oif;
   flw.fl4_tos=tos;
 
-  return ip_route_output_key(rp, &flw);
+  int r = ip_route_output_key(rp, &flw);
+  exit_func();
+  return r;
 }
 
 #endif
@@ -197,6 +225,7 @@ int register_nl_netfilter (
 {
   int rval;
 
+  enter_func(__LINE__);
   /* Register the netfilter hooks. */
   input_filter.list.next = NULL;
   input_filter.list.prev = NULL;
@@ -214,6 +243,7 @@ int register_nl_netfilter (
   if (rval < 0)
     {
       printk(KERN_ERR "input netfilter hooks registration failed.\n");
+      exit_func();
       return rval;
     }
 
@@ -221,23 +251,31 @@ int register_nl_netfilter (
   if (rval < 0)
     {
       printk(KERN_ERR "output netfilter hooks registration failed.\n");
+      exit_func();
       return rval;
     }
-
-
+  
+  
+  exit_func();
 }
 
 void unregister_netfilter()
 {
+enter_func(__LINE__);
   nf_unregister_hook(&input_filter);
   nf_unregister_hook(&output_filter);
+exit_func();
 }
 #endif
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
 struct iphdr ip_hdr(struct sk_buff *skb)
 {
-  return skb->nh.iph;
+  struct iphdr r;
+enter_func(__LINE__);
+  r = skb->nh.iph;
+exit_func();
+  return r;
 }
 
 net_device_t* net_device_entry(net_device_p *dev)
@@ -248,32 +286,41 @@ net_device_t* net_device_entry(net_devic
 
 void mod_inc_use_count()
 {
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
   try_module_get(THIS_MODULE);
 #else
   MOD_INC_USE_COUNT;
 #endif
+exit_func();
 }
 void mod_dec_use_count()
 {
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
   module_put(THIS_MODULE);
 #else
   MOD_DEC_USE_COUNT;
 #endif
+exit_func();
 }
 void nldo_gettimeofday(struct timeval *tvdataptr)
 {
+enter_func(__LINE__);
 	do_gettimeofday(tvdataptr);
+exit_func();
 }
 
 void nlpanic(const char *msg)
 {
+enter_func(__LINE__);
 	panic(msg);
+exit_func();
 }
 
 int nlprintk(const char *fmt, ...)
 {
+enter_func(__LINE__);
 	va_list args;
 	char buf[1024];
 
@@ -281,6 +328,7 @@ int nlprintk(const char *fmt, ...)
 	vsprintf(buf,fmt,args);
 	va_end(args);
 	
+exit_func();
 	return printk(buf);
 }
 
@@ -311,116 +359,184 @@ struct sk_buff *nl_skb_next (struct sk_b
 unsigned long
 nl_copy_from_user(void *to, const void *from, unsigned long n)
 {
-	return copy_from_user(to, from, n);
+	unsigned long r;
+enter_func(__LINE__);
+	r = copy_from_user(to, from, n);
+exit_func();
+	return r;
 }
 
 unsigned long
 nl_copy_to_user(void *to, const void *from, unsigned long n)
 {
-	return copy_to_user(to, from, n);
+	unsigned long r;
+enter_func(__LINE__);
+	r = copy_to_user(to, from, n);
+exit_func();
+	return r;
 }
 
 void init_misc(void)
 {
+	backtrace_flag = 0;
+	int i;
+	for(i=0; i<1024; ++i) {
+		backtrace_debug[i] = 0;
+	}
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
         nl_dev_base = &dev_base_head;
 #else
         nl_dev_base = dev_base;
 #endif
+exit_func();
 }
 
 #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)))
 
 int nl_register_firewall(int pf, struct firewall_ops *fw)
 {
-	return register_firewall(pf, fw);
+	int r;
+enter_func(__LINE__);
+	r = register_firewall(pf, fw);
+exit_func();
+	return r;
 }
 
 int nl_unregister_firewall(int pf, struct firewall_ops *fw)
 {
-	return unregister_firewall(pf, fw);
+	int r;
+enter_func(__LINE__);
+	r = unregister_firewall(pf, fw);
+exit_func();
+	return r;
 }
 
 
 void nl_poll_wait (struct file *file, struct wait_queue **sync, poll_table *pt)
 {
+enter_func(__LINE__);
     poll_wait(file, sync, pt);
+exit_func();
 }
 
 void nl_wake_up_interruptible (struct wait_queue **sync)
 {
+enter_func(__LINE__);
     wake_up_interruptible (sync);
+exit_func();
 }
 #else
 
 int nl_nf_register_hook(struct nf_hook_ops *reg)
 {
-  return nf_register_hook(reg);
+  int r;
+enter_func(__LINE__);
+  r = nf_register_hook(reg);
+exit_func();
+  return r;
 }
 
 void nl_nf_unregister_hook(struct nf_hook_ops *reg)
 {
+enter_func(__LINE__);
   nf_unregister_hook(reg);
+exit_func();
 }
 
 void nl_poll_wait (struct file *file, wait_queue_head_t * wait_address, poll_table *pt)
 {
+enter_func(__LINE__);
     poll_wait(file, wait_address, pt);
+exit_func();
 }
 
 void nl_wake_up_interruptible (wait_queue_head_t * wait_address)
 {
+enter_func(__LINE__);
     wake_up_interruptible (wait_address);
+exit_func();
 }
 #endif
 
 int nl_register_chrdev(unsigned int major, const char * name, struct file_operations *fops)
 {
-	return register_chrdev(major, name, fops);
+	int r;
+enter_func(__LINE__);
+	r = register_chrdev(major, name, fops);
+exit_func();
+	return r;
 }
 
 int nl_unregister_chrdev(unsigned int major, const char * name)
 {
-	return unregister_chrdev(major, name);
+	int r;
+enter_func(__LINE__);
+	r = unregister_chrdev(major, name);
+exit_func();
+	return r;
 }
 
 struct sk_buff *nl_alloc_skb(int size, int type)
 {
-	return alloc_skb(size, type);
+	struct sk_buff* r;
+enter_func(__LINE__);
+	r = alloc_skb(size, type);
+exit_func();
+	return r;
 }
 
 void nl_kfree_skb(struct sk_buff *skb)
 {
+enter_func(__LINE__);
 	kfree_skb(skb);
+exit_func();
 }
 
 void nl_kfree(const void *ptr)
 {
+enter_func(__LINE__);
 	kfree(ptr);
+exit_func();
 }
 
 void *nl_kmalloc (size_t size, int priority)
 {
-  return kmalloc(size, priority);
+  void* r;
+enter_func(__LINE__);
+  r = kmalloc(size, priority);
+exit_func();
+  return r;
 }
 
 struct sk_buff *nl_skb_clone(struct sk_buff *skb, int priority)
 {
-	return skb_clone(skb, priority);
+	struct sk_buff* r;
+enter_func(__LINE__);
+	r = skb_clone(skb, priority);
+exit_func();
+	return r;
 }
 
 struct sk_buff *nl_skb_copy(struct sk_buff *skb, int priority)
 {
-	return skb_copy(skb, priority);
+	struct sk_buff* r;
+enter_func(__LINE__);
+	r = skb_copy(skb, priority);
+exit_func();
+	return r;
 }
 
 void nl_spin_lock_init(spinlock_t *lockptr)
 {
+enter_func(__LINE__);
 	assert(lockptr); 
 	spin_lock_init(lockptr);
+exit_func();
 }
 void nl_spin_lock_irqsave(spinlock_t *lockptr, DWORD *flagptr)
 {
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)) 
 	assert(lockptr); 
 	assert(flagptr); 
@@ -428,10 +544,12 @@ void nl_spin_lock_irqsave(spinlock_t *lo
 #else
 	spin_lock_irq((spinlock_t *)lockptr);
 #endif
+exit_func();
 }
 
 void nl_spin_unlock_irqrestore(spinlock_t *lockptr, DWORD *flagptr)
 {
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)) 
 	assert(lockptr);
 	assert(flagptr);
@@ -439,15 +557,20 @@ void nl_spin_unlock_irqrestore(spinlock_
 #else
 	spin_unlock_irq((spinlock_t *)lockptr);
 #endif
+exit_func();
 }
 
 void nl_skb_put(struct sk_buff *skb, int length)
 {
+enter_func(__LINE__);
 	skb_put(skb, length);
+exit_func();
 }
 
 int nl_ip_rcv(struct sk_buff *skb, struct packet_type *pt)
 {
+int r;
+enter_func(__LINE__);
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12))
     struct net_device *dev = skb->dev;
     struct iphdr *iph = ip_hdr(skb);
@@ -457,67 +580,118 @@ int nl_ip_rcv(struct sk_buff *skb, struc
         if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))
             goto drop;
         }
-    return dst_input (skb);
+    r = dst_input (skb);
+exit_func();
+    return r;
 drop:
     kfree_skb(skb);
+exit_func();
     return 0;
 #else
-    return ip_rcv(skb, skb->dev, pt);
+    r = ip_rcv(skb, skb->dev, pt);
+exit_func();
+    return r;
 #endif
 }
 
 void nl_ip_send_check(struct iphdr *iph)
 {
+enter_func(__LINE__);
 	ip_send_check(iph);
+exit_func();
 }
 
 int nl_ip_route_output(struct rtable **rp, u32 daddr, u32 saddr, u32 tos, int oif)
 {
-	return ip_route_output(rp, daddr, saddr, tos, oif);
+	int r;
+enter_func(__LINE__);
+	r = ip_route_output(rp, daddr, saddr, tos, oif);
+exit_func();
+	return r;
 }
 
 int nl_register_netdevice_notifier(struct notifier_block *nb)
 {
-    return register_netdevice_notifier (nb);
+    int r;
+enter_func(__LINE__);
+    r = register_netdevice_notifier (nb);
+exit_func();
+    return r;
 }
 
 int nl_unregister_netdevice_notifier(struct notifier_block *nb)
 {
-    return unregister_netdevice_notifier (nb);
+    int r;
+enter_func(__LINE__);
+    r = unregister_netdevice_notifier (nb);
+exit_func();
+    return r;
 }
 
 char *dev_name (net_device_p *dev)
 {
-  return (net_device_entry(dev)->name);
+  char* r;
+enter_func(__LINE__);
+  r = (net_device_entry(dev)->name);
+exit_func();
+  return r;
 }
 
 int dev_name_len (net_device_p *dev)
 {
-  return (strlen(net_device_entry(dev)->name));
+  int r;
+enter_func(__LINE__);
+  r = (strlen(net_device_entry(dev)->name));
+exit_func();
+  return r;
 }
 unsigned *dev_mtu_ptr (net_device_p *dev)
 {
-  return &(net_device_entry(dev)->mtu);
+  unsigned *r;
+enter_func(__LINE__);
+  r = &(net_device_entry(dev)->mtu);
+exit_func();
+  return r;
 }
 unsigned dev_mtu (net_device_p *dev)
 {
-  return (net_device_entry(dev)->mtu);
+  unsigned r;
+enter_func(__LINE__);
+  r = (net_device_entry(dev)->mtu);
+exit_func();
+  return r;
 }
 int dev_ifindex (net_device_p *dev)
 {
-  return (net_device_entry(dev)->ifindex);
+  int r;
+enter_func(__LINE__);
+  r = (net_device_entry(dev)->ifindex);
+exit_func();
+  return r;
 }
 void *dev_ip_ptr (net_device_p *dev)
 {
-  return (net_device_entry(dev)->ip_ptr);
+  void* r;
+enter_func(__LINE__);
+  r = (net_device_entry(dev)->ip_ptr);
+exit_func();
+  return r;
 }
 net_device_t *dev_next (net_device_p *dev)
 {
-  return (dev->next);
+  net_device_t* r;
+enter_func(__LINE__);
+  r = (dev->next);
+exit_func();
+  return r;
 }
 int ip_summed(struct sk_buff *skb)
 {
-  return (skb->ip_summed);
+  int r;
+enter_func(__LINE__);
+  r = (skb->ip_summed);
+exit_func();
+  return r;
 }
 /* This structure will hold the functions to be called
  * when a process does something to the device we
@@ -538,12 +712,18 @@ struct file_operations kmsp_fops = {
 
 int max_skb_headroom (int type, struct sk_buff *skb)
 {
-  return (type == PACKET_HOST)?skb_headroom(skb):MAX_HEADER;
+	int r;
+enter_func(__LINE__);
+  r = (type == PACKET_HOST)?skb_headroom(skb):MAX_HEADER;
+exit_func();
+  return r;
 }
 
 void nl_skb_reserve (struct sk_buff *skb, int len)
 {
+enter_func(__LINE__);
   skb_reserve(skb, len);
+exit_func();
 }
 
 unsigned char * nl_skb_dataptr (struct sk_buff *skb)
@@ -559,6 +739,7 @@ int nl_skb_len(struct sk_buff *skb)
 void nl_skb_dup (struct sk_buff *new_skb, struct sk_buff *skb, int type)
 {
   int head_offset;
+enter_func(__LINE__);
 
   if (type == PACKET_HOST)
     {
@@ -592,10 +773,12 @@ void nl_skb_dup (struct sk_buff *new_skb
 #endif
   new_skb->pkt_type = type;
   new_skb->destructor = NULL;
+exit_func();
 }
 
 void nl_skb_hdr_copy (struct sk_buff *skb_to, struct sk_buff *skb_from)
 {
+enter_func(__LINE__);
   skb_to->dev = skb_from->dev;
   skb_to->dst = skb_from->dst;
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
@@ -619,11 +802,16 @@ void nl_skb_hdr_copy (struct sk_buff *sk
 
   skb_to->data = skb_from->data;
   skb_to->head = skb_from->head;
+exit_func();
 }
 
 struct iphdr * nl_skb_iph (struct sk_buff *skb)
 {
-  return ip_hdr(skb);
+  struct iphdr* r;
+enter_func(__LINE__);
+  r = ip_hdr(skb);
+exit_func();
+  return r;
 }
 
 net_device_t * nl_skb_dev (struct sk_buff *skb)
@@ -641,6 +829,7 @@ void nl_send_skb (struct sk_buff *skb, n
   struct iphdr *iph;
   int rval;
   struct rtable *rt;
+enter_func(__LINE__);
 
   if (skb)
     {
@@ -676,6 +865,7 @@ void nl_send_skb (struct sk_buff *skb, n
 
       }
     }
+exit_func();
 }
 
 int size_of_skb ()
@@ -685,7 +875,11 @@ int size_of_skb ()
 
 int nl_skb_cloned (struct sk_buff *skb)
 {
-  return skb_cloned(skb);
+  int r;
+enter_func(__LINE__);
+  r = skb_cloned(skb);
+exit_func();
+  return r;
 }
 
 int nl_data_len (struct sk_buff *skb)
@@ -695,9 +889,11 @@ int nl_data_len (struct sk_buff *skb)
 
 void update_inner_route (struct sk_buff *skb, net_device_t *dev)
 {
+enter_func(__LINE__);
   skb->dev = dev;
   dst_release(skb->dst);
   skb->dst = NULL;
+exit_func();
 }
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
 
@@ -705,30 +901,40 @@ extern char kernel_version [];
 
 int init_module(void)
 {
+enter_func(__LINE__);
 #if DEBUG
   printk("init_module (%x).\n", init_module);
 #endif
 
   if (mishim_init() != 0)
     return -EIO;
+exit_func();
   return 0;
 }
 
 void cleanup_module(void)
 {
+enter_func(__LINE__);
   if (mishim_uninit() != 0)
     printk("mishim module: module can't be removed.");
+exit_func();
 }
 #else
 
 static int __init nlshim_init (void)
 {
-  return mishim_init();
+  int r;
+enter_func(__LINE__);
+  r = mishim_init();
+exit_func();
+  return r;
 }
 
 static void __exit nlshim_exit(void)
 {
+enter_func(__LINE__);
   mishim_uninit();
+exit_func();
 }
 
 module_init(nlshim_init);
@@ -776,8 +982,10 @@ void do_checksum_offload( struct sk_buff
   struct sk_buff *frag_ptr;
   struct iphdr *iph;
 
+  enter_func(__LINE__);
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
   ip_send_check (skb->nh.iph);
+  exit_func();
   return;
 #else
   if ( !skb->ip_summed )                        /* if offload not enabled, */
@@ -811,9 +1019,11 @@ void do_checksum_offload( struct sk_buff
   skb->ip_summed = 0;     /* don't csum in hardware */
 
 done_exit:
+  exit_func();
   return;
 #endif
-
+  
+  exit_func();
 }
 #if 0
 /************************************************************************
