Pre-Allocating Space (At compiling time)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
astrocrep

Pre-Allocating Space (At compiling time)

Post by astrocrep »

My memory manger (though ineffiecent (sp?)) Uses a two part system.

A Memory Bit Map - A Char array that holds a value of wether or not a page is allocated (And its type 0 - free 1 - kernel 255 - rsvd)

A Ledger - A array of structures that hold information about each type of allocation, including owner, lenght, address, and type.

Originaly I had a

Code: Select all

char MemBitMap[4096];
But then realized That After allocating alot of pages, I was over writting memory in my kernel!

So I changed it to

Code: Select all

char MemBitMap[4096] = ""; (inside the "" is 4096 0's)
Thats all well in good, however,

Code: Select all

struct mledger
{
 blah
 blah
} MMLedger[256];
Might also start overwriting parts of ram, I know space isn't decalred for it because I can change 256 to anything and the kernel size stays the same

So my question is, how can I specify the base address for the MMLedger array, or How can I have the space pre-allocated in the kernel as I had already done, with the MemBitMap.

[Update]
MemBitMap is now aligned on a 4k pages sitting at the bottom of my memory manager free pool and isn't required to be filled up w/ zeros anymore. But what about the struct??

Thanks for the help.

Rich P.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Pre-Allocating Space (At compiling time)

Post by Candy »

astrocrep wrote: Thats all well in good, however,

Code: Select all

struct mledger
{
 blah
 blah
} MMLedger[256];
Might also start overwriting parts of ram, I know space isn't decalred for it because I can change 256 to anything and the kernel size stays the same
You don't initialize the MMLedger array. If you did, it wouldn't end up in .bss, so your kernel binary would grow. Now since you don't the loader is required to zero the BSS section (including this array) in which this array now resides. Check the binary code generated, and most particularly, where the array ends up (section name).
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Pre-Allocating Space (At compiling time)

Post by Pype.Clicker »

Code: Select all

   char bitmap[4096];
is allocated in the .bss section. Make sure you have it defined in your linker script and cleared in your loader.
astrocrep

Re:Pre-Allocating Space (At compiling time)

Post by astrocrep »

WEell the char array, Ive taken care of an asigned it to a page that is known free. I want to do the samething for the structure array.

I want an array of structs, and I want to specifically asign where the bottom of the array is located , like

Code: Select all

char *ptr = (char*) 0x140000;
I tried something like

Code: Select all

struct mystruct
{
 blah
 blah
};

mystruct *MMLedger[256]
I generate a bunch of errors... especial anytime blah was refrenced (either by a "." or a "->"

I know your saying use linked lists... and in theory its not a bad idea... but it would require much more overhead for me at this time...

Thanks for the help,

Rich
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Pre-Allocating Space (At compiling time)

Post by Candy »

not in a mood to explain anything

Code: Select all

struct mystruct
{
 blah;
 blah;
};

struct mystruct *MMLedger = (struct mystruct *)0xbadfood;
or

Code: Select all

struct mystruct
{
 blah;
 blah;
} *MMLedger = (struct mystruct *)0xbadfood;
or

Code: Select all

typedef struct mystruct
{
 blah;
 blah;
} mystruct;

mystruct *MMLedger = (struct mystruct *)0xbadfood;
astrocrep

Re:Pre-Allocating Space (At compiling time)

Post by astrocrep »

Awesome,

Exactly what I was looking for... thanks alot!

-Rich P.
Post Reply