DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Writing drivers in C++

Known problems

Be aware of the following issues when implementing C++ drivers:

  1. The MOD_prefix_WRAPPER wrapper macros that are documented on the _load(D2) manual page for DDI versions prior to version 8 do not compile under C++. This is because the macro generates declarations in a form that C++ does not accept:
       extern void x;
    
    Only the MOD_MISC_WRAPPER macro works correctly.

    These wrapper macros are not needed in statically linked drivers, so one solution is to statically link any C++ driver.

    A more elegant solution is to separate the invocation of the macros into a .c file and compile that with the C compiler, then link the resulting .o file with the rest of the driver.

    DDI version 8 and ODDI drivers do not use these macros and so are not affected.

  2. The example C language drivers provided in the HDK do not compile well under C++ because of missing forward declarations, implicit int, and similar issues. C++ programmers can study these examples for an understanding of driver structure and the use of kernel functions and structures but will need to modify them appropriately for C++.

  3. When virtual methods are used in the driver code, you may get an unresolved symbol std::type_info::__vtbl or, in its mangled form, _vtbl__Q2__3std9type_info. To resolve this, add the following definition somewhere in the global namespace of your driver code:
       __vtbl__Q2__3std9type__info;
    
    The problem is that, even when compiled with the -Wf,--no_rtti option, the generated code for virtual functions references a class in the standard library typeinfo header. The class is defined in LibC.a:typeinfo.o, but extracting that library and linking it into the driver code would pull in a great deal of unnecessary code. For SVR5, just define the symbol; it will not actually be used as long as modules are compiled with the -Wf,--no_rtti option. When a dynamically-loadable module is provided to supply the necessary C++ runtime support routines, this definition will be included in that module to resolve this problem.

© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005