Stack Segments

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
SFX

Stack Segments

Post by SFX »

Hi,

I have a question about stack segments in pmode.

What is the best way to setup a stack segment?

Should it be expand up or down?
Should it also have a base of 0, or should I limit the range that it can flow into?

For example if I have a 0 based stack segment, wouldn't this be able to overwrite below 1MB if it grew large enough?

What do you guys do for your stack in pmode?

All are welcome to answer, but I am really looking for an answer from someone who has a reasonably mature OS.

thanks guys.
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:Stack Segments

Post by Pype.Clicker »

most OSes (including Linux) do not use a special policy for stack segments (i.e. they're just flat 4GB data segments), protected by paging only (i.e. the top-page is absent and page faults are caught to extend the valid stack range).

However, such a policy isn't optimal and you can see programs like

Code: Select all

main()
{
     float big_matrix[1000000];

     printf("%i", sizeof(big_matrix));
}
issueing segmentation faults on some linux distro.

Personally, i chosed to have restricted stack segments for kernel stacks (using exp-down segment whose base is adjusted with the data segment base, and which limit is computed to stop at "top-of-stack").

I'm still unsure about the right stack policy for user programs.
SFX

Re:Stack Segments

Post by SFX »

What do you mean the stack segments base is adjusted to the data segment base, do you have a non-zero based data segment? Or have I misunderstood.

Actually with a exp-down data segment the base adjusts the size of the segment, I think. Is this right? If so then I think I sort of understand what you are saying.

Can you show me what your GDT entry looks like for your kernel stack?

thanks.
SFX

Re:Stack Segments

Post by SFX »

I also have another question about the stack, I thought that in protected mode the push/pop always push/pop 4 bytes, however when I push AX, ESP is only changed by 2 bytes and if I push EAX it is changed by 4 bytes, oddly enough if I push AL I get an exception??

Is this normal behaviour? Why cant I push AL?

thanks.
RuneOfFire

Re:Stack Segments

Post by RuneOfFire »

PUSH and POP deal with the size of the register you're pushing or popping, not with the current mode.

AX is 2 bytes wide (a word)
EAX is 4 bytes wide (a dword)

AL is an 8-bit register (1 byte) and cannot be used with PUSH/POP. You should just PUSH/POP AX or EAX (depending on what mode you're in) if you want to PUSH/POP AL.
Post Reply