home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.os.os2.programmer:4344 comp.lang.c:12572
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!cs.utexas.edu!usc!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!informatik.tu-muenchen.de!rommel
- From: rommel@Informatik.TU-Muenchen.DE (Kai-Uwe Rommel)
- Newsgroups: comp.os.os2.programmer,comp.lang.c
- Subject: Re: malloc causes a segmentation violation!?
- Message-ID: <1992Aug20.140945.12855@Informatik.TU-Muenchen.DE>
- Date: 20 Aug 92 14:09:45 GMT
- References: <harris.714243433@garfield.catt.ncsu.edu> <1992Aug20.092700.8373@wsl.ie>
- Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
- Organization: Technische Universitaet Muenchen, Germany
- Lines: 40
-
- In article <1992Aug20.092700.8373@wsl.ie> jja@wsl.ie (John J. Allen) writes:
- >harris@garfield.catt.ncsu.edu (Michael Harris) writes:
- >: Memory protection in OS/2 protects one process from another... not a process
- >: from itself.
- >
- >OS/2 2.0 = Flat memory model
- >OS/2 1.x = Segmented memory model.
- >
- >The segmented memory model had some advantages over the flat model. If I
- >used DosAllocSeg() to create a 20k block and then ran off the end of
- >it I'd get a segmentation violation as soon as I did that. (As in Win 3.x)
- >
- >So although the FLAT memory model simplifies programming it hampers
- >debugging.
-
- This is not entirely true. To make it similar, some programming would be
- needed, however.
-
- One could implement a malloc() and friends library which does not only
- allocate memory in the usual manner but also two additional pages, one
- before and one after some chunk of memory. These pages should then be
- set up as "guard pages", this means, that any access to these pages
- triggers an exception. A handler set up for this exception could then
- write an entry to a log file and abort the program.
-
- This method has the advantage over the 1.x segmented model that it is
- not restricted to whole segments but it is still restricted to 4k
- granularity (page size). Of course, it wastes memory too, but this
- should not matter for a development cycle.
-
- Note: I have not implemented such a library, but the memory management
- API in OS/2 2.0 can be used to implement such a debugging aid, according
- to the documentation.
-
- Kai Uwe Rommel
-
- /* Kai Uwe Rommel --- rommel@informatik.tu-muenchen.de */
-
- DOS ... is still a real mode only non-reentrant interrupt
- handler, and always will be. -Russell Williams
-