[MINIX LOGO]

Separate stack and data segments?

modified: 28 Jun 2005


Could Minix use separate segments for stack and data?

Minix uses the Intel i386 protection mechanisms to define code, data, and stack segments. Executable instructions in the code segment are read-only, and it is impossible for data in the data or stack areas to be treated as executable code. However, Minix, in the tradition of other Unix-like systems, does not distinguish between data and stack areas -- although data and stack use separate segment descriptors and could be protected from each other by the hardware, Minix initializes the data and stack descriptors to point to the same area of memory.

A question was asked on the comp.os.minix newsgroup as to whether separate data and stack areas could be used, and what would be the advantages and disadvantages of doing it either way.

David Given <dg@cowlark.com> wrote this reply (newsgroup headers appear at end of this page):

Assuming you're using a traditional 8086 implementation with normal-sized pointers, then having separate 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.

Abbreviated newsgroup headers:
From: David Given
Newsgroups: comp.os.minix
Subject: Re: Separate segments for stack & data
Date: Fri, 24 Jun 2005 11:04:52 GMT
References: <42bba6a1$1@dnews.tpgi.com.au>


[HOME] [HINTS/FAQ] [MINIX DOWNLOADS] [CONTRIB SOFTWARE]
[NET SOFTWARE] [MINIX-VMD] [TEXTBOOK] [LINKS]

All material on this site not otherwise attributed is copyright ©1994-2005 Albert S. Woodhull
Click here for information on copying and other use.
Mail comments on this page to: Al Woodhull <awoodhull@hampshire.edu>
[Viewable With Any Browser]
Valid CSS!
[Valid XHTML 1.0!]