Memory Manager - Bitmap

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
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Memory Manager - Bitmap

Post by mark3094 »

I'm working on a memory manager using a bitmap.
I'm still having some difficulty understanding how much memory to mark as allocated for the Kernel.

I've read this article on the memory layout for C programs:
http://www.geeksforgeeks.org/archives/14268

From there I can see that the code and the initialised data are part of the Kernel binary, but it looks like there is more memory allocated for the unitialised data, heap and stack.
Problem is that i'm not sure how much to mark as allocated.

I've read that other people use a linker script to determine how much to allocate, however I'm using VC++ (but I'm using C not C++) not gcc, so I'm not sure if that's an option.

I used a program called PE explorer to see if I could get any useful information there, but I don't think it will help (attached).

Any ideas? Even just a pointer in the right direction would be great.
Attachments
PE header details
PE header details
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Memory Manager - Bitmap

Post by mark3094 »

I have found a few things that may help, but I'm still not 100% sure...

In this article, it says:
A field in the PE header tells the system how much memory needs to be set aside for mapping the executable into memory.
http://msdn.microsoft.com/en-us/magazine/cc301805.aspx

Unfortunately it doesn't say which field exactly...

This article says that "SizeOfStackCommit" and "SizeOfHeapCommit" are the amounts of memory that are actually used in memory. In the case of the screenshot I attached, this is 4KB each.
http://www.thehackerslibrary.com/?p=377

There is also "SizeOfUninitializedData" for the BSS.

Can I get the size of the executable (the PE image - 0x6e00 in my case) and add 4KB for stack, 4KB for heap and the size of uninitialised data to get the total size of memory that I need to allocate in my memory bitmap?
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Memory Manager - Bitmap

Post by mark3094 »

Thanks for your help.
Appreciate it a lot. I've been stuck for a while now.
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Memory Manager - Bitmap

Post by mark3094 »

If anyone comes across this post in future and is interested, I have found some more information.

Visual Studio seems to put uninitialised data in the .data section instead of .bss
I occasionally wondered why my kernel, which doesn't do much more than print hello world and initialise the PIT/PIC would use up 28K. It's because uninitialised data is zeroed and put into the binary. There are some ways to work around this, but portability seems limited.
http://forums.codeguru.com/showthread.p ... lized-data
http://stackoverflow.com/questions/7719 ... ata-in-bss

berkus wrote:In the PE screenshot, size of code + size of initialized data does not equal to size of image, I suspect that's due to section alignment, although I don't know enough about how PE files are supposed to be loaded/relocated to say for sure.
The size is 0x0400 bytes (1KB) larger than the code plus initialised data. The base of code is at 0x0400. This is because the PE file will pad the header up to a 512b boundary.
http://www.deinmeister.de/w32asm5e.htm

Hope someone finds this helpful.
Post Reply