[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Kernel Prog.



Oren Poleg <poleg@inter.net.il> wrote:
|C++ in kernel space, Is it possible ?

Probably, but you should be very carefull.  I remember sometime in the
early kernels they tried to use it but got off the idea, I don't know
which features of the language prooved problemtic, or maybe it was the
immaturity of g++ back then (it was 2.6.*, g++ 2.7.* got way better
since then).

Points to consider:

1. Don't use exception handling, or actually anything which uses
   the stack in a complex way beyond what plain C does.

2. Redefine the global/class new/delete operators to be based on the
   kernel facilities (kmalloc/kfree?).  Be carefull not to conflict with
   other C++ code in the kernel (in case there is allready something,
   or in case something will be added later)

3. Remember you are in the kernel, i.e. a context switch or a hardware
   interrupt are possible any time, sorround your critical sections
   with locks (use the Guard pattern - that's were C++ might be handy)
   and declare "volatile" data structures and variables as such (which,
   on the other hand, might decrease optimization)

4. Allow C functions to call your C++ code via 'extern "C"' functions,
   C code can't call C++ methods.

You might want to take a look at ACE
(http://siesta.cs.wustl.edu/~schmidt/ACE.html), it's a user-level
library but it deals with OS stuff (threads, IPC, locks, etc..), so it
(or its documents) might give you some ideas for patterns to use in
your code.

Would be interesting to see what you come up with.  What are you
planning?

Cheers,

--Amos

--Amos Shapira                    | "Of course Australia was marked for
133 Shlomo Ben-Yosef st.          |  glory, for its people had been chosen
Jerusalem 93 805                  |  by the finest judges in England."
ISRAEL             amos@dsi.co.il |                     -- Anonymous


References: