C++ kernel placement constructor
Posted: Sun May 24, 2015 1:48 am
Hi all, like others I have been lurking in the shadows, learning enough to at least have interesting problems. I have been reading the many articles and tutorials on this and the other 'standard' sites and now I am at the physical page management stage.
My problem is this:
I am using a new placement allocator to position the SpanTable instance that I create using
I get a message indicating that the Table ctor and then the SpanTable ctor are called. I can see that the values are passed correctly via the stack, and yet if I do this after construction
The result is always zero, and this is true for all of the other Table members. I have checked and I can see that the SpanTable instance is correctly located at the placement address, no exception or interrupt thrown, and yet the values are still zero.
I am not expecting someone to debug this for me, but I am looking for any scenarios where this is possible so I can trace the problem. At this point I am out of ideas because nothing goes boom, and yet every thing in the Table class is zero.
I have chosen to build in C++, a rod for my own back but I felt there was little point in simply copying other solutions, perhaps not the best choice but I am persistent.
The only though I had was that the void* operator new(size_t,void*) method which I wrote was not calling the ctor but then the appropriate messages are displayed on the screen.
So in summary, the SpanTable and Table ctors are called, the stack arguments and local variables are correct but all of the member variables are zero. Note if I set the values of the member variables in the ctor, e.g. m_count = 12, this will display in the ctor correctly but if I attempt to display this value once the ctor has returned the value is once again zero.
So I am thinking this has something to do with the layout of the inherited class (Table) in memory, I thought the SpanTable address would begin with the Table vtab and members (although there are no virtuals in this code).
So suggestions anyone?
My problem is this:
Code: Select all
class Table
{
protected:
ui32_v m_size;
ui32_v m_count;
ui32_v m_total;
page_v* m_table;
inline
Table (ui32_v address,ui32_v total,ui32_v size)
:m_size (size)
,m_count (0)
,m_total (total)
,m_table (0)
{
m_size = size;
m_total = total;
m_count = m_total / size;
if (m_count * size < total)
{
m_count++;
}
Vga vga;
vga.setPos(0,10);
// vga << "t-ctor total=" << total << " size=" << size << " count=" << m_count;
vga << "t-ctor total=" << m_total << " size=" << m_size << " count=" << m_count;
m_table = new((void*)address) page_v[(std::size_t)m_count];
}
public:
inline
ui32_v count()
{
return m_count;
}
inline
ui32_v size()
{
return m_size;
}
};
class SpanTable : public Table
{
public:
inline
SpanTable (ui32_v address,ui32_v total,ui32_v size)
:Table (address,total,size)
{
Vga vga;
vga.setPos(0,11);
vga << "st-ctor total=" << total << " size=" << size << " count=" << (total / size);
}
};
Code: Select all
spanTable01 = new((void*)0x60000000) SpanTable(0x70000000,0xF0000000,4096);
Code: Select all
spanTable01->size()
I am not expecting someone to debug this for me, but I am looking for any scenarios where this is possible so I can trace the problem. At this point I am out of ideas because nothing goes boom, and yet every thing in the Table class is zero.
I have chosen to build in C++, a rod for my own back but I felt there was little point in simply copying other solutions, perhaps not the best choice but I am persistent.
The only though I had was that the void* operator new(size_t,void*) method which I wrote was not calling the ctor but then the appropriate messages are displayed on the screen.
So in summary, the SpanTable and Table ctors are called, the stack arguments and local variables are correct but all of the member variables are zero. Note if I set the values of the member variables in the ctor, e.g. m_count = 12, this will display in the ctor correctly but if I attempt to display this value once the ctor has returned the value is once again zero.
So I am thinking this has something to do with the layout of the inherited class (Table) in memory, I thought the SpanTable address would begin with the Table vtab and members (although there are no virtuals in this code).
So suggestions anyone?