[Click] C++ vs the kernel
Eddie Kohler
kohler at cs.ucla.edu
Tue Jul 24 16:02:23 EDT 2007
Hey Adam,
I will send a brief reply. We will see if it answers your questions.
Part of the issue is that some of the things you say are "C++" issues
are not in fact. Specifically threading & dynamic loading. The C++
language has no story for these features; they depend on the environment.
The Click framework makes C++ usable within the kernel with the
following exceptions:
- No exceptions.
- No RTTI.
- The standard library by default relies on malloc-based allocators
which interact badly with the kernel. Click provides its own String,
Vector, and HashMap classes that should be used in preference to
std::string, std::vector. It may be possible to use std::vector with a
kernel-specific allocator (as long as std::vector throws no exceptions),
or to use algorithms such as std::sort, but we haven't exactly tried.
Other projects have made more of C++ usable in the kernel.
http://netlab.ru.is/exception/LinuxCXX.shtml
Adam M wrote:
> Hi folks,
>
> I'm a little confused regarding the documentation for the
> 'click-devirtualize' tool:
>
> "The click-devirtualize tool speeds up a Click configuration by removing
> virtual function calls from its elements. ... The virtual function calls
> in this specialized C++ code are replaced with direct function calls to
> other elements in the configuration. ... You can install such an archive
> into the linuxmodule Linux kernel module with click-install"
>
> This is all well and good, but there seems to be a lot of unaddressed
> issues here. I'm certainly no Linux kernel expert, but it seems there
> would be a lot of "gotchas". Here's a few that I can think of off the
> top of my head:
> 1) Name mangling
Not a problem.
> 2) Exceptions
NOT ALLOWED. Thou shalt not use exceptions in Click.
> 3) Memory allocation
Not a problem. Click overloads "operator new" to call kmalloc.
> 4) Threading
Thou shalt use Linux primitives for implementing "threads". Pthreads
are NOT ALLOWED.
> 5) Dynamic loading
The Linux kernel has its own dynamic loading story, which Click uses.
Eddie
>
> I would expect that these gotchas would be well documented somewhere,
> with advice on how to write C++ code that will link with the kernel, but
> I've not really found anything.
>
> It seems that Click has been quite successful at writing C++ code that
> will link with the kernel, but I don't know how people have accomplished
> this.
>
> Could someone please shed some light? If there's already extensive
> documentation for this, a simple reference is fine. Otherwise, some
> tutelage may be necessary.
>
> Thanks again,
> Adam
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
More information about the click
mailing list