#endif
-#if defined(HAVE_MMAP)
-
/* Forward declarations/prototypes for local functions */
-static struct mdesc *reuse PARAMS ((int));
+static struct mdesc *reuse (int fd);
/* Initialize access to a mmalloc managed region.
On failure returns NULL. */
-PTR
-mmalloc_attach (fd, baseaddr)
- int fd;
- PTR baseaddr;
-{
+void * mmalloc_attach (int fd, void *baseaddr) {
struct mdesc mtemp;
struct mdesc *mdp;
- PTR mbase;
+ void* mbase;
struct stat sbuf;
/* First check to see if FD is a valid file descriptor, and if so, see
if (fd >= 0)
{
if (fstat (fd, &sbuf) < 0)
- return (NULL);
+ return (NULL);
else if (sbuf.st_size > 0)
- return ((PTR) reuse (fd));
+ return ((void*) reuse (fd));
}
/* If the user provided NULL BASEADDR then fail */
/* If we have not been passed a valid open file descriptor for the file
to map to, then open /dev/zero and use that to map to. */
-/* if (mdp -> fd < 0)*/
-/* {*/
-/* if ((mdp -> fd = open ("/dev/zero", O_RDWR)) < 0)*/
-/* {*/
-/* return (NULL);*/
-/* }*/
-/* else*/
-/* {*/
-/* mdp -> flags |= MMALLOC_DEVZERO;*/
-/* }*/
-/* }*/
-
/* Now try to map in the first page, copy the malloc descriptor structure
there, and arrange to return a pointer to this new copy. If the mapping
fails, then close the file descriptor if it was opened by us, and arrange
if ((mbase = mdp -> morecore (mdp, sizeof (mtemp))) != NULL)
{
memcpy (mbase, mdp, sizeof (mtemp));
-// mdp = (struct mdesc *) mbase;
+ // mdp = (struct mdesc *) mbase;
}
else
{
abort();
-// mdp = NULL;
+ // mdp = NULL;
}
-
- return ((PTR) mbase);
+
+ { /* create the mutex within that heap */
+ void*old_heap=mmalloc_get_current_heap();
+ mmalloc_set_current_heap(mbase);
+ mdp->mutex =xbt_os_mutex_init();
+ mmalloc_set_current_heap(old_heap);
+ }
+
+ return ((void*) mbase);
}
/* Given an valid file descriptor on an open file, test to see if that file
unsuccessful for some reason. */
static struct mdesc *
-reuse (fd)
- int fd;
+reuse (int fd)
{
struct mdesc mtemp;
struct mdesc *mdp = NULL;
if (__mmalloc_remap_core (&mtemp) == mtemp.base)
{
mdp = (struct mdesc *) mtemp.base;
- mdp -> fd = fd;
- mdp -> morecore = __mmalloc_mmap_morecore;
- if (mdp -> mfree_hook != NULL)
- {
- mmcheckf ((PTR) mdp, (void (*) PARAMS ((void))) NULL, 1);
- }
+ mdp -> fd = fd;
+ mdp -> morecore = __mmalloc_mmap_morecore;
+ mdp->mutex =xbt_os_mutex_init();
+ if (mdp -> mfree_hook != NULL)
+ {
+ mmcheckf ((void*) mdp, (void (*) (void)) NULL, 1);
+ }
}
- return (mdp);
-}
-
-#else /* !defined (HAVE_MMAP) */
-/* For systems without mmap, the library still supplies an entry point
- to link to, but trying to initialize access to an mmap'd managed region
- always fails. */
+ { /* create the mutex within that heap */
+ void*old_heap=mmalloc_get_current_heap();
+ mmalloc_set_current_heap(mdp);
+ mdp->mutex =xbt_os_mutex_init();
+ mmalloc_set_current_heap(old_heap);
+ }
-/* ARGSUSED */
-PTR
-mmalloc_attach (fd, baseaddr)
- int fd;
- PTR baseaddr;
-{
- return (NULL);
+ return (mdp);
}
-#endif /* defined (HAVE_MMAP) */
-