C++ Exceptions & the Linux Kernel

by Halldór Ísak Gylfason and Gísli Hjálmtýsson



Listing One



struct task_struct {

   volatile long state;

   struct thread_info *thread_info;

   ...

#ifdef CONFIG_CXX_RUNTIME

   struct {

     void *caughtExceptions;

     unsigned int uncaughtExceptions;

   } cxa_eh_globals;

#endif

}; 





Listing Two



#include <begin_include.h>

#include <linux/module.h>

#include <linux/kernel.h>

#include <end_include.h>



Listing Three



class OSException 

{ 

public: 

     char* getMessage();      

     OSException(char* msg,int sev);

     int getSeverity(); 

     virtual void report(); 

     enum tSeverity {MINOR=1,MAJOR,FATAL}; 

private: 

     char* message; 

     int severity; 

}; 

class NetworkException : public OSException 

{ 

   ...

}; 

class ProntoException : public NetworkException 

{

   ...

}; 





Listing Four



asmlinkage int 

sys_pproc_type_call(int pptype, int call, void* args) 

{ 

  int retval = -ENOSYS; 

  try { 

    if (thePProcKType) {

      retval = 

         thePProcKType->syscall(pptype, call, args); 

    } else { 

      printk(KERN_ERR "pproc not loaded");   

    } 

  } catch(ProntoException & exception) { 

         exception.report(); 

  } catch(...) { 

        printk(KERN_ERR "Unknown Exception occurred"); 

  } 

  return retval; 

} 





Listing Five



int pronto_ip_rcv(struct sk_buff *skb, .) 

{ 

  ...  

  flow = classifier->lookup(skb); 

  if( flow ){

    try { 

       flow->arrive( skb ); 

    } catch(ProntoException & exception) { 

       exception.report(); 

       kfree_skb(skb); 

    } catch(...) { 

     printk("Unknown exception occured"); 

     kfree_skb(skb); 

    } 

  }

  ...

} 













1



