home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / mmalloc / detach.c < prev    next >
C/C++ Source or Header  |  1995-08-01  |  2KB  |  72 lines

  1. /* Finish access to a mmap'd malloc managed region.
  2.    Copyright 1992 Free Software Foundation, Inc.
  3.  
  4.    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
  5.  
  6. This file is part of the GNU C Library.
  7.  
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version.
  12.  
  13. The GNU C Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with the GNU C Library; see the file COPYING.LIB.  If
  20. not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.  */
  22.  
  23. #include <sys/types.h>
  24. #include <fcntl.h> /* After sys/types.h, at least for dpx/2.  */
  25. #include "mmprivate.h"
  26.  
  27. /* Terminate access to a mmalloc managed region by unmapping all memory pages
  28.    associated with the region, and closing the file descriptor if it is one
  29.    that we opened.
  30.  
  31.    Returns NULL on success.
  32.  
  33.    Returns the malloc descriptor on failure, which can subsequently be used
  34.    for further action, such as obtaining more information about the nature of
  35.    the failure by examining the preserved errno value.
  36.  
  37.    Note that the malloc descriptor that we are using is currently located in
  38.    region we are about to unmap, so we first make a local copy of it on the
  39.    stack and use the copy. */
  40.  
  41. PTR
  42. mmalloc_detach (md)
  43.      PTR md;
  44. {
  45.   struct mdesc mtemp;
  46.  
  47.   if (md != NULL)
  48.     {
  49.  
  50.       mtemp = *(struct mdesc *) md;
  51.       
  52.       /* Now unmap all the pages associated with this region by asking for a
  53.      negative increment equal to the current size of the region. */
  54.       
  55.       if ((mtemp.morecore (&mtemp, mtemp.base - mtemp.top)) == NULL)
  56.     {
  57.       /* Update the original malloc descriptor with any changes */
  58.       *(struct mdesc *) md = mtemp;
  59.     }
  60.       else
  61.     {
  62.       if (mtemp.flags & MMALLOC_DEVZERO)
  63.         {
  64.           close (mtemp.fd);
  65.         }
  66.       md = NULL;
  67.     }
  68.     }
  69.  
  70.   return (md);
  71. }
  72.