Linux device driver (kernel module) written in C++

Linux device driver (kernel module) written in C++

Post by az0t » Tue, 30 Jan 2001 22:05:12



Hi,

Is this possible to write device driver or kennel module using C++? I
digged all the Sourceforge and many other resources but didn't find
any driver/kernel module written in C++. I'll very appreciate if
someone will provide me with answer or link to exsisting project.

Thanks,
az0te

 
 
 

Linux device driver (kernel module) written in C++

Post by Kaz Kylhe » Thu, 01 Feb 2001 03:22:27



>Hi,

>Is this possible to write device driver or kennel module using C++? I

Yes. However there are a few obstacles:

- Kernel header files using C++ keywords for types, struct members and
  so on. This problem can be overcome by making a header file that
  uses macros to rename the C++ keywords ``out of the way'', and
  another header file that #undef's these macros. Include the first
  header, then the kernel headers you need, and then the second header.

- There is missing C++ run time support in the kernel. Basically this
  means that you cannot use exception handling, and will have to write
  your own global operator new (whether or not you use it; g++ emits
  some references operator new in code generated for class constructors).

- There is no support for global construction. So you should avoid
  defining static class objects, or any declarations with non-trivial
  initializers.

- The code for initialzing a block scope static class object is not
  thread safe in g++. That is, if you write:

  {
    static myclass x;
  }

  the code that g++ emits is something like

  {
    static myclass x;
    static bool __hidden_flag;

    if (__hidden_flag == false) {
       /* call x's constructor */
       __hidden_flag = true;
    }
  }

  If you do anything like this from multiple processors, or from an
  interrupt, that could cause trouble.

 
 
 

Linux device driver (kernel module) written in C++

Post by Johan Kullsta » Thu, 01 Feb 2001 03:38:41



> Hi,

> Is this possible to write device driver or kennel module using C++?

in theory, yes, but in practice, no.  C++ requires a fairly extensive
run-time environment which the kernel is not prepared to provide.
many names in the kernel conflict with C++ reserved words.  linus does
not seem amenable to changing the kernel to allow/support C++.

people always suggest C++ but no one ever puts in enough
infrastructure into the kernel and restricts themselves from using
fancy features to make it work.  don't ask someone else to do it for
you.  if *you* really want C++ so badly, then *you* must do the work.
no one else wants it enough to bother.

Quote:> I digged all the Sourceforge and many other resources but didn't
> find any driver/kernel module written in C++. I'll very appreciate
> if someone will provide me with answer or link to exsisting project.

ok.  the answer is no.

--
J o h a n  K u l l s t a m

sysengr

 
 
 

Linux device driver (kernel module) written in C++

Post by cbbro.. » Sat, 03 Feb 2001 10:29:11


az0te> Hi, Is this possible to write device driver or kennel module
az0te> using C++? I digged all the Sourceforge and many other
az0te> resources but didn't find any driver/kernel module written in
az0te> C++. I'll very appreciate if someone will provide me with
az0te> answer or link to exsisting project.

It is theoretically possible, but involves a number of challenges, in
roughly increasing order of dauntingness:

* Your module will certainly never be included in the "official"
  kernel stream, as the developers of Linux use C, not C++.

* You will need to work around conflicts whereby the standard Linux
  kernel headers use C++ keywords for C data structures.

* C++ requires considerable runtime support, including an exception
  handler and support for the "new" operator.  (And vtables, and RTTI,
  and such...)  You will need to create your own support for whatever
  such aspects that you require.

* Once you have worked around the preceding three challenges, you're
  going to be working with some tiny subset of C++ which is likely to
  beg the question "Why bother?"

The challenges are significant enough, and you'll get _no_ help from
the people that do serious work on the kernel, so the usual result is
that the would-be "C++ kernel hacker" chooses from two options:
 -> Give up altogether, or
 -> Give up on using C++, and write the extension in C just like
    everyone else does.

You're likely to have best success by deciding to write the extension
in C.
--

http://vip.hex.net/~cbbrowne/rdbms.html
For example, if errors are detected in one of the disk drives, the system
will allow read-only access to memory until the problem is resolved.  This,
PE claimed, prohibits a damaged disk drive from entering errors into the
system.
-- Computerworld 8 Nov 82 page 4.

 
 
 

Linux device driver (kernel module) written in C++

Post by Dmitry Fedor » Sat, 03 Feb 2001 14:43:00



>Is this possible to write device driver or kennel module using C++? I
>digged all the Sourceforge and many other resources but didn't find
>any driver/kernel module written in C++. I'll very appreciate if
>someone will provide me with answer or link to exsisting project.

ftp://ftp.inp.nsk.su/export/fedorov/src/linux-cxx-1.10.tar.gz
ftp://ftp.inp.nsk.su/export/fedorov/src/linux-cxx-test-1.7.tar.gz
ftp://ftp.inp.nsk.su/export/fedorov/src/linux-compat-1.20.tar.gz
ftp://ftp.inp.nsk.su/export/fedorov/src/dfmakefiles-1.35.tar.gz
 
 
 

Linux device driver (kernel module) written in C++

Post by Kasper Dupon » Sun, 04 Feb 2001 01:28:18



> * Once you have worked around the preceding three challenges, you're
>   going to be working with some tiny subset of C++ which is likely to
>   beg the question "Why bother?"

C++ has two features which I really like.

1. Global constructors.
2. More freedom in where to declare variables.

The global constructors does also exist in the GNU-C
compiler, but does require a very small amount of
runtime support. I think the newest Linux kernels
does have support for something very similar.

I think the construction for(int i=0;i<42;++i) is
clearer than puting the variables in the start of
the block.

In the cases where I only use a variable for the
last three lines of a function, I don't think it is
good to move the declaration far away from where the
variable is used. You could start a new block, but
in some cases that will make the code harder to read.

But it shouldn't be too hard to add that feature to
the standard C compiler.

--
Kasper Dupont

 
 
 

Linux device driver (kernel module) written in C++

Post by Erik de Castro Lop » Sun, 04 Feb 2001 06:28:37




> > * Once you have worked around the preceding three challenges, you're
> >   going to be working with some tiny subset of C++ which is likely to
> >   beg the question "Why bother?"

> C++ has two features which I really like.

> 1. Global constructors.

Which should not be used in the kernel because there is not mechanism
to make sure they are called.

Quote:> 2. More freedom in where to declare variables.

Some people think this is an advantage, others see it
as ecouraging sloppy code.

<snip>

Quote:> I think the construction for(int i=0;i<42;++i) is
> clearer than puting the variables in the start of
> the block.

Some people think this is an advantage, others see it
as encouraging sloppy code.

Quote:> In the cases where I only use a variable for the
> last three lines of a function, I don't think it is
> good to move the declaration far away from where the
> variable is used. You could start a new block, but
> in some cases that will make the code harder to read.

> But it shouldn't be too hard to add that feature to
> the standard C compiler.

Its not part of the C standard. It means code written for
this "enhanced" C compiler will not compile with other
compilers.

Erik
--
+----------------------------------------------------------+

+----------------------------------------------------------+
"UNIX was not designed to stop you from doing stupid things,  because
that would also stop you from doing clever things."  -- Doug Gwyn

 
 
 

Linux device driver (kernel module) written in C++

Post by Kaz Kylhe » Sun, 04 Feb 2001 06:47:56


On Fri, 02 Feb 2001 21:28:37 GMT, Erik de Castro Lopo




>> > * Once you have worked around the preceding three challenges, you're
>> >   going to be working with some tiny subset of C++ which is likely to
>> >   beg the question "Why bother?"

>> C++ has two features which I really like.

>> 1. Global constructors.

>Which should not be used in the kernel because there is not mechanism
>to make sure they are called.

I could add to this: C++ global constructors are garbage that should be
avoided in sane C++ programming. The order in which these constructors
are executed is only partially constrained by the language.  This leads
to problems, when the constructor of one object assumes that another
has already been constructed. Destruction of global objects can
likewise create problems, typically worse ones.

If some C++ newbie comes to you with a question like ``my program
crashes before main() is even run!'' or ``after main returns'',
chances are global construction is to blame.

C++ global construction should not be mistaken for global module
initialization in the style of Modula 2, which is done in the correct
module dependency order. E.g. if module A imports the interface of
module B, then B's initialization is done before A's.

Quote:>> 2. More freedom in where to declare variables.

>Some people think this is an advantage, others see it
>as ecouraging sloppy code.

Also, in any case, C99 has adopted the mixing of declarations among
statements. So this is now a C feature, though not yet adopted by most
compilers.

Quote:>> I think the construction for(int i=0;i<42;++i) is
>> clearer than puting the variables in the start of
>> the block.

>Some people think this is an advantage, others see it
>as encouraging sloppy code.

I see it as a disadvantage simply because historically, C++ compilers
have disagreed about the scope of variable i. This still causes
portability problems in practice. Even though the ANSI/ISO C++ standard
is supposed to settle the issue, broken C++ compilers are still around.
For example, Microsoft's C++ compiler as of VC++ 6!

If you write the following code which works great with g++:

    for (int i = 0; i < MAX; i++) {
        /* ... */
    }

    for (int i = 0; i < MAX; i++) {
        /* ... */
    }

a compiler which implements the incorrect scope rule will * about i
being redeclared.  You don't run into these kinds of stupid conformance
problems with C compilers that are not more than a decade old!

 
 
 

1. Ft. Worth - Linux Kernel Module Programmer - Unix kernel modules & Unix device drivers

Linux Kernel Module Programmer - A very loose environment, casual attire,
needs an intermediate to advanced Linux Kernel Module Programmer
immediately for a critical role. This person must have specific experience
in programming Unix kernel modules or drivers and TCP/sockets, preferably
with Linux kernel modules or drivers, or an understanding or experience of
parallel and distributed processing. Program a Linux kernal module to
fulfill the need for a routing program performing communications and shared
server resource management on web servers. These programming tasks are below
the socket level, but some manipulation of sockets is part of the tasks.
This person will perform cutting edge server applications development in a
parallel and distributed environment. This experience is a huge resume
boost.

Required Skills: MUST HAVE experience in programming a Unix or Linux KERNAL
MODULE or DRIVER! ... and C / Unix, networks and protocols, an innovative
mind that enjoys thinking out of the box, good work ethic, work well alone,
self motivated, requires little supervision.

Desired Skills: parallel and distributed processing.

Start Date: ASAP

Type: - Permanent -

Pay Range: $60,000 - $65,000 Annual
+stock options

Benefits: Health Insurance, Life Insurance, Dental Insurance, Disability
Insurance, Paid Vacation, Paid Sick Leave, Stock Options, Flex Time

Location: Ft. Worth , TX - Hurst, TX
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TO APPLY, PLEASE CALL OR FORWARD RESUME TO:

Larry Bergstrom
Computer Staff, LLC
1701 W. Northwest Highway
Grapevine, Texas 76051-8105

OFFICE metro  (817) 329-5009
FAX   (817) 329-5091
WEBSITE:  http://www.compstaffonline.com/listings.html
HOME  (817) 251-2029
MOBILE  (817) 723-4298
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information Technology Contract & Permanent Placement Services
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALL RESUME RESPONDENTS ARE HELD CONFIDENTIAL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. f77 bug

3. Linux Device Driver, Linux Kernel Module Developer - 5 packets per second

4. modems and linux

5. Start Writing Device Drivers in C/C++

6. Mixing Fortran & C

7. writing kernel module with c++

8. SLIP over null-modem lead - advice?

9. Anyone have written devices/drivers/module on solaris 2.6?

10. I want to write a simple device driver module: where do I start?

11. write a simple block device driver as module

12. char device kernel module won't write

13. Writing Device Drivers for Newer Kernels