home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / os2 / programm / 4344 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.3 KB

  1. Xref: sparky comp.os.os2.programmer:4344 comp.lang.c:12572
  2. 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
  3. From: rommel@Informatik.TU-Muenchen.DE (Kai-Uwe Rommel)
  4. Newsgroups: comp.os.os2.programmer,comp.lang.c
  5. Subject: Re: malloc causes a segmentation violation!?
  6. Message-ID: <1992Aug20.140945.12855@Informatik.TU-Muenchen.DE>
  7. Date: 20 Aug 92 14:09:45 GMT
  8. References: <harris.714243433@garfield.catt.ncsu.edu> <1992Aug20.092700.8373@wsl.ie>
  9. Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
  10. Organization: Technische Universitaet Muenchen, Germany
  11. Lines: 40
  12.  
  13. In article <1992Aug20.092700.8373@wsl.ie> jja@wsl.ie (John J. Allen) writes:
  14. >harris@garfield.catt.ncsu.edu (Michael Harris) writes:
  15. >: Memory protection in OS/2 protects one process from another... not a process
  16. >: from itself.
  17. >
  18. >OS/2 2.0 = Flat memory model
  19. >OS/2 1.x = Segmented memory model.
  20. >
  21. >The segmented memory model had some advantages over the flat model. If I
  22. >used DosAllocSeg() to create a 20k block and then ran off the end of
  23. >it I'd get a segmentation violation as soon as I did that. (As in Win 3.x)
  24. >
  25. >So although the FLAT memory model simplifies programming it hampers
  26. >debugging.
  27.  
  28. This is not entirely true. To make it similar, some programming would be
  29. needed, however.
  30.  
  31. One could implement a malloc() and friends library which does not only
  32. allocate memory in the usual manner but also two additional pages, one
  33. before and one after some chunk of memory. These pages should then be
  34. set up as "guard pages", this means, that any access to these pages
  35. triggers an exception. A handler set up for this exception could then
  36. write an entry to a log file and abort the program.
  37.  
  38. This method has the advantage over the 1.x segmented model that it is
  39. not restricted to whole segments but it is still restricted to 4k
  40. granularity (page size). Of course, it wastes memory too, but this
  41. should not matter for a development cycle.
  42.  
  43. Note: I have not implemented such a library, but the memory management
  44. API in OS/2 2.0 can be used to implement such a debugging aid, according
  45. to the documentation.
  46.  
  47. Kai Uwe Rommel
  48.  
  49. /* Kai Uwe Rommel --- rommel@informatik.tu-muenchen.de */
  50.  
  51. DOS ... is still a real mode only non-reentrant interrupt
  52. handler, and always will be.                -Russell Williams
  53.