From: diaz AT margaux DOT inria DOT fr (diaz daniel) Newsgroups: comp.os.msdos.djgpp Subject: mmap() or equivalent ??? Date: 23 Jan 1997 10:02:04 GMT Organization: INRIA Rocquencourt Lines: 55 Distribution: world Message-ID: <5c7cus$m8k@news-rocq.inria.fr> NNTP-Posting-Host: tobago.inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Hello, I have developped a compiler for a Prolog under linux. It translates Prolog to asm. Then as produces an object file. This .o file needs to be linked with a library (containing the prolog engine + builtin prolog predicates). This library has been written in C. Now I'd like to port it under w95. DJGPP seems a the simplest tool to use. However, the linux system use the mmap() facility to avoid to test for stack overflows. I explain this in few words: the prolog engine needs 3 stacks which are widely used. A software test to detect overflows is very costly and should be icorporated in too parts of my code. So I use a hardware detection. I use the mmap() function which "maps" a file in memory so readings and writings on this file come down to read/write the memory. I use the device /dev/zero (which always returns 0 on 1st reading and does not "repercut" the writings). I then mmap() a big space (sum of the size of the 3 stacks + 3 pages) and I munmap() the page just after each stack. I recall that munmap gives back a page to the MMU. So we have: +------------+ | free page | +------------+ | : | | stack #3 |<- sp3 | : | +------------+ | free page | +------------+ | : | | stack #2 |<- sp2 | : | +------------+ | free page | +------------+ | : | | stack #1 |<- sp1 | : | +------------+ So as soon as an overflow occurs (trying to read/write just after a stack) the MMU trigger a signal SIGSEGV. I just recove it via an handler set by the signal() function. In this function I recove the fault addr and then I detect which stack has overflowed. Q: how could I do this (or equivalent) under DJGPP ? Thank you for you attention. -- Daniel Diaz INRIA Rocquencourt - 78153 Le Chesnay Cedex FRANCE tel: +33 1 39 63 52 67 email: Daniel DOT Diaz AT inria DOT fr ============================================