OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 11:13 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Free addresses stack use
PostPosted: Sat Oct 20, 2018 5:45 am 
Offline

Joined: Wed Oct 17, 2018 9:56 am
Posts: 19
Once I pushed all the free addresses to the stack, I wondered how to push a just free address. That is, when I want to push an address do I have to test if it is usable from the memory map? I think not. I just have to increment and decrement the stack pointer to manage it because of the addresses which remains effectively there. Then to scan the stack I pass from the stack pointer pStack to the end of the kernel, is it OK?


Top
 Profile  
 
 Post subject: Re: Free addresses stack use
PostPosted: Sat Oct 20, 2018 7:31 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Hi,

More information needed.

From what I gather, you are building a physical page allocation stack. You have presumable found enough space for it in the system memory map so that there is enough space for it even if every page is free.

Given the above, I'm not quite sure what the question is, but you do not need to check the system memory map each time you free a page - just when you build the initial stack.

Cheers,
Adam


Top
 Profile  
 
 Post subject: Re: Free addresses stack use
PostPosted: Sat Oct 20, 2018 11:13 am 
Offline

Joined: Wed Oct 17, 2018 9:56 am
Posts: 19
Yes. I've pushed the free usable addresses came from the GRUB memory map to the stack at the end of the kernel (knew it from the "flag" end set in the linker), but then a doubt has came up to me. I wondered how to manage it.

To pop an address from the stack I should decrement the stack pointer (in my case *pStack), but I'm not physically popping off it and overwriting the memory location, so it should be possible to re-push it simply by incrementing pStack. Am I right? I intend, when I pop an address I theoretically have to cancel the content and then decrement the stack pointer, but so when I push an address I don't know whether an address is usable or not. Thus I thought that I could not cancel the popped off address and, when I want to push an address, I don't push a specific one but I push the last popped address. But the problem came up anyway when I want to allocate a specific address, how should I check if it is usable or not?

Another thing is to scan the stack to test if an address is free (to allocate a specific address for example). should it be enough to scan from pStack down to the end of the kernel (where the stack has started)?


Top
 Profile  
 
 Post subject: Re: Free addresses stack use
PostPosted: Sun Oct 21, 2018 9:50 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
Xcp wrote:
To pop an address from the stack I should decrement the stack pointer (in my case *pStack), but I'm not physically popping off it and overwriting the memory location, so it should be possible to re-push it simply by incrementing pStack. Am I right?

wrong

physical addresses are rarely ever freed in the same (reverse) order they are allocated in, so yes, you must place the value back onto the stack (overwriting whatever was at that address before -- because what was there before was probably a different address)

Quote:
I intend, when I pop an address I theoretically have to cancel the content and then decrement the stack pointer, but so when I push an address I don't know whether an address is usable or not. Thus I thought that I could not cancel the popped off address and, when I want to push an address, I don't push a specific one but I push the last popped address. But the problem came up anyway when I want to allocate a specific address, how should I check if it is usable or not?

if you are freeing non-existant pages, then you have a very serious problem in your code, and this check will not help you

basically, you will never free a page unless you were using that page, and if you were using that page, then you know it does exist, therefore, there is no need to check the memory map to see if that page really exists, because if it didn't exist you wouldn't be freeing it (and if you were freeing pages incorrectly, checking the memory map wouldn't help, because you could be freeing the wrong address but still a valid address)

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 91 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group