Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Separate segments for stack & data

5 views
Skip to first unread message

Gyruss

unread,
Jun 24, 2005, 2:22:25 AM6/24/05
to
Apparently there's a version of MINIX where the stack and data each have
their own segments. In version 2.0 I believe the stack and data segments
are the same.

What are the advantages of one vs the other?

Cheers!

David Given

unread,
Jun 24, 2005, 7:04:52 AM6/24/05
to
Gyruss wrote:
[...]

> What are the advantages of one vs the other?

Assuming you're using a traditional 8086 implementation with normal-sized
pointers, then having seperate stack and data segments means that you can't
address structures on the stack and structures on the heap using the same
kind of pointer; which rules out C as a programming language. However, your
application can now access 128kB of RAM.

The problem is that when the 8086 dereferences a pointer, it needs to be
told what segment the pointer is referring to, but the C compiler can't
know this. For example:

void doSomethingWithPointer(void* ptr);

{
char ThisIsOnTheStack[100];
char* ThisIsOnTheHeap = malloc(100);

doSomethingWithPointer(ThisIsOnTheStack);
doSomethingWithPointer(ThisIsOnTheHeap);
}

What form of instructions does the function use?

That said, this is an old and solved problem in the DOS world; it's usually
managed with compiler extensions that allow you to qualify pointers as
either only ever pointing at one particular segment, or else carry around
extra information to specify which segment they're pointing at ('far
pointers'). However, I don't think there are any Minix compilers that
support that.

--
+- David Given --McQ-+ "There is nothing in the world so dangerous ---
| d...@cowlark.com | and I mean *nothing* --- as a children's story that
| (d...@tao-group.com) | happens to be true." --- Master Li Kao, _The Bridge
+- www.cowlark.com --+ of Birds_

Giovanni

unread,
Jun 24, 2005, 8:01:44 AM6/24/05
to


As far as I know Minix executable have and always had common data and
stack segment. What Minix has is separate/common text and data segments
and you can choose with -i (or -com/-sep) argument to cc.

As default separate text and data should be used. This format allows
text sharing among processes, i.e. if two processes run the same program
the text segment is loaded once in memory but each process will have its
own data/stack segment.

Ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
Registered Linux user #337974 <http://counter.li.org/>

0 new messages