home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / aix / 9352 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.9 KB  |  59 lines

  1. Newsgroups: comp.unix.aix
  2. Path: sparky!uunet!mcsun!Germany.EU.net!math.fu-berlin.de!umn.edu!mmm.serc.3m.com!pwcs!medtron!israel!sh0001
  3. From: sh0001@israel (Scott Hansohn)
  4. Subject: AIX malloc and fault tolerance
  5. Message-ID: <1992Sep3.135156.9166@medtron.medtronic.com>
  6. Sender: news@medtron.medtronic.com (USENET News Administration)
  7. Nntp-Posting-Host: israel.inst.medtronic.com
  8. Organization: Medtronic, Inc.
  9. Date: Thu, 3 Sep 1992 13:51:56 GMT
  10. Lines: 47
  11.  
  12. In AIX, a nonzero return from malloc does not guarantee that the
  13. memory requested has been allocated to the process.  Neither does
  14. a successful launch of a program containing a large static buffer
  15. guarantee that the buffer may be fully usable.
  16.  
  17. I was quite surprised to discover this in a recent conversation that
  18. my program had with the malloc function.  The dialog when something
  19. like this:
  20.     program: Hey malloc!  I'd like a few megabytes please.
  21.     malloc:  No problem, here you go -- it's at this address.
  22.     program: Thanks very much.  I'll just go and fill this memory, and --
  23.     malloc:  Just kidding!  I didn't really give you the memory.  And by
  24.              the way, you're going to die if you continue to use it.  Ha!
  25.  
  26. It turns out that when my program went to fill in the memory, it was sent
  27. a SIGKILL by AIX.  This was clearly a bug of some kind, so I reported it.
  28. I sent a demo program that just malloc'd as big a buffer as it could get,
  29. and then started zeroing a byte every 4k.  When I started up a couple of
  30. them, they all died.  Some got bus errors, others were sent SIGKILL.
  31.  
  32. IBM's response is that this is working as designed!
  33.  
  34. IBM said that they don't allocate the paging space until it's needed, in
  35. order to accommodate programs which ask for large amounts of memory that
  36. they never use (some nonsense about sparse arrays).  I said that I need
  37. to know if the memory is really there before I start using it.  They
  38. referred me to some sample code.  If it weren't so sad, it would have
  39. been funny.
  40.  
  41. The sample code contained a malloc wrapper that returns nonzero only if
  42. the memory is actually there.  It sets up a handler for SIGDANGER, then
  43. calls malloc.  If it returns nonzero (a virtual certainty) it proceeds
  44. to touch pages of memory.  If it gets SIGDANGER, the handler longjmps to
  45. code which "untouches" the memory, frees the successfully-malloc'd-but-
  46. not-really-there buffer and causes the malloc wrapper to return zero.
  47.  
  48. I have questions:
  49.     1) Has anyone seen a system where static memory may not really be
  50.        there, or where a nonzero malloc doesn't guarantee the successful
  51.        usage of the memory?
  52.     2) Has anyone heard of SIGDANGER before?
  53.     3) Read the POSIX standard for malloc from a "legal" standpoint.
  54.        If IBM claims POSIX compliance, can I use this as a weapon?
  55.     4) Even if I use this malloc wrapper everywhere in my own code,
  56.        how do I deal with third-party code I purchase that calls the
  57.        unwrapped malloc?
  58.  
  59.