Code Generator

Jim Cromie jim.cromie at
Thu Sep 15 23:52:33 EDT 2011

On Mon, Sep 12, 2011 at 3:04 PM, mosta < at> wrote:
> Hey All,
> does somebody know of projects that use code generators to generate
> kernel modules? I'm thinking about using a strongly typed language like
> haskell with a code generator to  generate kernel C-Code. I want to
> achieve more secure kernel modules this way. Is this a silly idea? or
> had someone already done that.
> hope for answers?

So you want to write a haskell program to write source code : foo.c
for a kernel module, maybe write a makefile for an out-of-tree module,
then make, install that module.

if you post a hello-world.ko generator, Id read the email  ( haskell curiosity )
But I imagine youre looking towards more complex stuff.
what advantages are you anticipating ?
- correct-by-construction ?

similar but different is  coccinelle.
it uses caml -> SmPL (the similar part) code
to parse C code, looks for sequences matched by semantic patches,
and rewrites that code.

Its been used to find and repair numerous kernel programming errors,
many with security ramifications.  dozens of cocci scripts are in
the kernel tree: ./scripts/coccinelle/*/*.cocci
to detect newly committed errors.

If security per se is your main motivation,
then you should probably use coccinelle.

If the haskell part is important too, maybe write an spatch generator.
(Id read that too :)

More information about the Kernelnewbies mailing list