#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <string.h>
#include "mmalloc.h"
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
+
+#if defined(HAVE_MMAP)
+
/* Forward declarations/prototypes for local functions */
static struct mdesc *reuse PARAMS ((int));
On failure returns NULL. */
-
-#if defined(HAVE_MMAP)
-
PTR
mmalloc_attach (fd, baseaddr)
int fd;
then initialize the fields that we know values for. */
mdp = &mtemp;
- memset ((char *) mdp, 0, sizeof (mtemp));
- strncpy (mdp -> magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE);
+ (void) memset ((char *) mdp, 0, sizeof (mtemp));
+ (void) strncpy (mdp -> magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE);
mdp -> headersize = sizeof (mtemp);
mdp -> version = MMALLOC_VERSION;
mdp -> morecore = __mmalloc_mmap_morecore;
if ((mbase = mdp -> morecore (mdp, sizeof (mtemp))) != NULL)
{
- memcpy (mbase, mdp, sizeof (mtemp));
+ (void) memcpy (mbase, mdp, sizeof (mtemp));
mdp = (struct mdesc *) mbase;
}
else
after we've switched over to using the mapped in malloc descriptor
rather than the temporary one on the stack.
+ Once we've switched over to using the mapped in malloc descriptor, we
+ have to update the pointer to the morecore function, since it almost
+ certainly will be at a different address if the process reusing the
+ mapped region is from a different executable.
+
Also note that if the heap being remapped previously used the mmcheck()
routines, we need to update the hooks since their target functions
will have certainly moved if the executable has changed in any way.
{
mdp = (struct mdesc *) mtemp.base;
mdp -> fd = fd;
+ mdp -> morecore = __mmalloc_mmap_morecore;
if (mdp -> mfree_hook != NULL)
{
(void) mmcheck ((PTR) mdp, (void (*) PARAMS ((void))) NULL);
to link to, but trying to initialize access to an mmap'd managed region
always fails. */
+/* ARGSUSED */
PTR
mmalloc_attach (fd, baseaddr)
int fd;