Hello all, I want to create a kernel
library supported c++ pure virtual function, and i had
created kernel mode library , link to driver , and load driver
, bring system crash.
the follow is my source code.
// class head file myclass.h
class
MyClassBase { public:
void * operator new(size_t size);
void operator delete(void * mem, size_t
size); MyClassBase()
{}; virtual ~ MyClassBase()
{}; virtual void
release() = 0;
public: virtual void
Enable(bool bEnable) = 0; virtual
void Process(float *pInBuf, float *pOutBuf, unsigned int
len)=0;
};
class MyClass public:
MyClassBase { private:
unsigned int m_Val1,
m_Val2;
float
m_fVal[12];
bool
m_bEnable; public:
void * operator new(size_t size);
void operator delete(void * mem, size_t
size);
MyClass(); virtual ~
MyClass(); virtual
void release();
public: virtual void
Enable(bool bEnable); virtual void
Process(float *pInBuf, float *pOutBuf, unsigned int
len);
};
// class source file myclass.cpp
// for Class MyClassBase void * MyClassBase::operator
new(size_t size) { void *p =
NULL; p =
IOMalloc(size); return
p; }
void MyClassBase::operator delete(void * mem,
size_t size) {
if(mem)
{ IOFree
(mem, size); } }
// for Class MyClass void * MyClass::operator
new(size_t size) { void *p =
NULL; p =
IOMalloc(size); return
p; }
void MyClass::operator delete(void * mem, size_t
size) {
if(mem)
{ IOFree
(mem, size); } }
MyClass:: MyClass() {
m_Val1 = 2; m_Val2 =
48000; m_bEnable =
false; }
MyClass::~ MyClass() {
release(); }
void
MyClass::release() { m_Val1 =
2; m_Val2 =
48000; m_bEnable =
false; }
void MyClass::Enable(bool
bEnable) { m_bEnable =
bEnable; }
void MyClass::Process(float *pInBuf, float *pOutBuf,
unsigned int len) {
if(m_bEnable)
{ // process
... } }
// used by driver // Create
MyClass *myClsss =
NULL; myClsss = new
MyClass();
if(myClsss)
{ myClsss->
Enable(true); }
// Release
if(myClsss)
{ delete
myClsss; } myClsss
= NULL;
//////////////// end /////////////////
This source code bring system crash, why ?
Thanks in advance.
|