Skip to contentSkip to conversation

Whizzy New Feature: Paged segmented memory

DISCUSSION Jacques Gelinas 4 participants 9 messages Jan 8, 2002

lore
Share & tools
lore
#0 lore raw

On Sun, 6 Jan 2002 14:14:30 -0500, Marcin Tustin wrote

Quoted 8 lines

Any comments on how useful it would be to have paged, segmented,
memory support for Pentium? I was thinking that by having separate segments for text, stack, and heap, buffer overrun exploits would be eliminated (I'm aware that this would require GCC patching as well).
Obviously, I'm thinking that I (and any similar fools I could rope
in) would try this (Probably delivering for a kernel at least a year out of date by the time we had a patch).

Another solution would be to have two stacks. One for variable (auto data) and one for program execution (call). Beside cache effect, this would provide mostly the same performance as we get now. Just wondering if someone had toyed with this idea.

---------------------------------------------------------
Jacques Gelinas <[email protected]>
vserver: run general purpose virtual servers on one box, full speed!
http://www.solucorp.qc.ca/miscprj/s_context.hc

#1 lore raw
Quoted 4 lines · Jacques Gelinas

Another solution would be to have two stacks. One for variable (auto data) and one for program execution (call). Beside cache effect, this would provide mostly the same performance as we get now. Just wondering if someone had toyed with this idea.

A nice thing about two stacks is that it can be a completely userspace thing. No need to involve the kernel at all; just gcc and friends.

#2 lore raw
In reply to Jacques Gelinas
Quoted 4 lines · Anthony DeRobertis

A nice thing about two stacks is that it can be a completely userspace thing. No need to involve the kernel at all; just gcc and friends.

Doesn't it have ABI implications as well?

If so, why not go all the way and have stacks grow upwards? :-)

Jeroen

#3 lore raw
In reply to Jacques Gelinas
Quoted 5 lines · jtv
Quoted 2 lines · Anthony DeRobertis

A nice thing about two stacks is that it can be a completely userspace thing. No need to involve the kernel at all; just gcc and friends.

Doesn't it have ABI implications as well?

On every architecture I'm familiar with. But that's a userland issue. I don't believe the kernel cares how userland uses its stacks.

Change gcc. Recompile world. All should work, assuming your gcc changes are bug-free, no one made assumptions about stack layout, no one wrote assembly code, etc. [In other words, after 4 months of debugging you might get X running again...]

Quoted 2 lines

If so, why not go all the way and have stacks grow upwards? :-)

Some architectures have hardware assistance for downward growing stacks. One example is 68K. I think x86 does too. OTOH, I don't think PPC does, though I haven't read the Green Book recently.

Actually, if I were to be implementing split-stack, I'd probably have one grow upward. Probably the data stack, because some architectures (68K, at least) force the address stack to grow downwards.

Put an unmapped page between the two stacks, and all should be fine.

Quoted 4 lines

Jeroen

#4 lore raw
Quoted 25 lines · Anthony DeRobertis
Quoted 7 lines · jtv
Quoted 4 lines · Anthony DeRobertis

A nice thing about two stacks is that it can be a completely userspace thing. No need to involve the kernel at all; just gcc and friends.

Doesn't it have ABI implications as well?

On every architecture I'm familiar with. But that's a userland issue. I don't believe the kernel cares how userland uses its stacks.

Change gcc. Recompile world. All should work, assuming your gcc changes are bug-free, no one made assumptions about stack layout, no one wrote assembly code, etc. [In other words, after 4 months of debugging you might get X running again...]

Quoted 2 lines

If so, why not go all the way and have stacks grow upwards? :-)

Some architectures have hardware assistance for downward growing stacks. One example is 68K. I think x86 does too. OTOH, I don't think PPC does, though I haven't read the Green Book recently.

Quoted 5 lines

Actually, if I were to be implementing split-stack, I'd probably have one grow upward. Probably the data stack, because some architectures (68K, at least) force the address stack to grow downwards.

Put an unmapped page between the two stacks, and all should be fine.

At least with Intel ix8*, even though one can create a discriptor for a (backwards) stack, you would have a hard time using it. 'Push' op-codes decrement the stack-pointer and 'pop' increments it regardless of the characteristics of the stack-selector. I don't know if this is a bug or a feature.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (797.90 BogoMips).

I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any.

#7 lore raw
In reply to Jacques Gelinas
Quoted 5 lines · Anthony DeRobertis

Change gcc. Recompile world. All should work, assuming your gcc changes are bug-free, no one made assumptions about stack layout, no one wrote assembly code, etc. [In other words, after 4 months of debugging you might get X running again...]

And, of course, the same for all other software. But for a highly secure project, for instance, that might be worth it.

Quoted 3 lines

Some architectures have hardware assistance for downward growing stacks. One example is 68K. I think x86 does too. OTOH, I don't think PPC does, though I haven't read the Green Book recently.

68K has predecrement/postincrement addressing modes (I'm not sure that counts as "forcing" the stack to grow downwards); PPC has a symmetrical load/store-with-update IIRC.

Jeroen

#8 lore raw
Quoted 3 lines · jtv

And, of course, the same for all other software. But for a highly secure project, for instance, that might be worth it.

I'd imagine most things would just work. It's only going to be the things that make assumptions about memory layout that will break.

I picked X as an example because it cares quite a bit about memory layout, especially when mapping in framebuffers and whatnot.

Quoted 3 lines

68K has predecrement/postincrement addressing modes (I'm not sure that counts as "forcing" the stack to grow downwards);

The address stack on 68K grows downwards because JSR, BSR, etc. do the stack manipulation for you.

Sure, you _could_ use JMP and BRA and maintain your own linkage, but that'd take a large performance hit. Much larger than making the data stack grow upwards, I dare say.

Quoted 2 lines

PPC has a symmetrical
load/store-with-update IIRC.

Right. I don't think it cares. Nice architecture ;-)

#5 lore raw
In reply to Richard B. Johnson
Quoted 4 lines · Richard B. Johnson

At least with Intel ix8*, even though one can create a discriptor for a (backwards) stack, you would have a hard time using it. 'Push' op-codes decrement the stack-pointer and 'pop' increments it regardless of the characteristics of the stack-selector.

You'd have to do it manually, without those instructions. That's what you get for using a CISC architecture from who-knows-when.

I'd guess most RISC architectures don't have this problem.

#6 lore raw
Quoted 9 lines · Anthony DeRobertis
Quoted 5 lines · Richard B. Johnson

At least with Intel ix8*, even though one can create a discriptor for a (backwards) stack, you would have a hard time using it. 'Push' op-codes
decrement the stack-pointer and 'pop' increments it regardless of the characteristics of the stack-selector.

Quoted 5 lines

You'd have to do it manually, without those instructions. That's what you get for using a CISC architecture from who-knows-when.

I'd guess most RISC architectures don't have this problem.

Yes, and you can choose any one of a zillion registers to address your "stack" although there are some de-facto standards, not enforced by the hardware. But this all comes with trade-offs discussed from about all perspectives in the past, context-switches come to mind. Using Intel, with the proper call-frame on the stack, iret switches context. Setting the proper call-frame and saved register values is easy because there are so few registers!

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (797.90 BogoMips).

I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any.