1 /* Finish access to a mmap'd malloc managed region.
2 Copyright 1992 Free Software Foundation, Inc.
4 Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com
5 This file was then part of the GNU C Library. */
7 /* Copyright (c) 2010. The SimGrid Team.
8 * All rights reserved. */
10 /* This program is free software; you can redistribute it and/or modify it
11 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include <unistd.h> /* close */
14 #include <sys/types.h>
15 #include "mmprivate.h"
17 /* Terminate access to a mmalloc managed region by unmapping all memory pages
18 associated with the region, and closing the file descriptor if it is one
21 Returns NULL on success.
23 Returns the malloc descriptor on failure, which can subsequently be used
24 for further action, such as obtaining more information about the nature of
25 the failure by examining the preserved errno value.
27 Note that the malloc descriptor that we are using is currently located in
28 region we are about to unmap, so we first make a local copy of it on the
29 stack and use the copy. */
32 mmalloc_detach (void *md)
39 mtemp = *(struct mdesc *) md;
40 xbt_os_mutex_destroy(((struct mdesc*)md)->mutex);
42 /* Now unmap all the pages associated with this region by asking for a
43 negative increment equal to the current size of the region. */
45 if ((mtemp.morecore (&mtemp, (char*)mtemp.base - (char*)mtemp.breakval)) == NULL)
47 /* Deallocating failed. Update the original malloc descriptor
49 *(struct mdesc *) md = mtemp;
53 if (mtemp.flags & MMALLOC_DEVZERO)