Our ISP's mail services have been dead for a while, so I didn't get any mail
until today... :-(

Mon, 24 Apr 2000 De Messemaeker Johan wrote:
> On Tue, 25 Apr 2000, David Olofson wrote:
> 
> > Anyway, I can dig out some headers and makefiles for C++ in kernel space if you
> > like.
> 
> I'm very interested thank you.

Ok, first, the new/delete stuff:

---8<-------------------------------------------------
/*
 *
 * kernel++.h - new and delete for C++ in kernel/module space
 *
 */

#ifndef __KERNELCPP
#define __KERNELCPP

extern "C" {
#include <linux/kernel.h>

void *kmalloc(unsigned size, int prio);
void kfree(void *p);
           };

void *operator new (unsigned size) {
  return kmalloc(size,0);
}

void *operator new[] (unsigned size, unsigned nb) {
  return kmalloc(size*nb,0);
}

void operator delete (void *p) {
  kfree(p);
}

void operator delete[] (void *p) {
  kfree(p);
}

#endif
------------------------------------------------->8---


To export the module init/cleanup stuff correctly, you need to do this:

---8<-------------------------------------------------
extern "C" {
        int init_module(void);
        void cleanup_module(void);
};
------------------------------------------------->8---


If you have statically allocated objects, you have to make sure their
constructors and destructors get called, as this isn't handled automatically
for kernel modules. (A result of the user space runtime init/exit code not
being used.) In you *.cc file:

---8<-------------------------------------------------
extern "C" {
        __do_global_ctors_aux();
        __do_global_dtors_aux();
};

....

int init_module(void)
{
        __do_global_ctors_aux();

        ...
        //Init code
        ...
}


void cleanup_module(void)
{
        ...
        //Cleanup code
        ...

        __do_global_dtors_aux();
}
------------------------------------------------->8---


This should handle the basic C++ OO stuff. There are probably some more things
you may run into, but I can't remember any specific issues right now...


David Olofson
 Programmer
 Reologica Instruments AB
 [EMAIL PROTECTED]

..- M u C o S --------------------------------. .- David Olofson ------.
|           A Free/Open Multimedia           | |     Audio Hacker     |
|      Plugin and Integration Standard       | |    Linux Advocate    |
`------------> http://www.linuxdj.com/mucos -' | Open Source Advocate |
..- A u d i a l i t y ------------------------. |        Singer        |
|  Rock Solid Low Latency Signal Processing  | |      Songwriter      |
`---> http://www.angelfire.com/or/audiality -' `-> [EMAIL PROTECTED] -'
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to