* mpattach.c 2.7 9/14/90 12:18:59
* Copyright (c) 1988, Benjamin G. Zorn
* This defines MPROF intermediate functions that call the actual
* malloc and free functions that have been renamed.
extern char *__malloc__();
extern char *__realloc__();
extern unsigned int *mprof();
extern void mprof_note_free();
extern void mprof_cleanup();
#define MPROF_HEADER_SIZE (sizeof(mpheader))
/* malloc -- Allocate header for mprof information on top of user bytes.
* Note that all objects have the extra header, but not all require
* profiling if the flag is turned off.
result
= __malloc__(nbytes
+ MPROF_HEADER_SIZE
);
* Check for error on allocation.
force
= (mpheader
*) result
;
force
->creators
= mprof(nbytes
);
return (char *) ((int) result
+ MPROF_HEADER_SIZE
);
/* realloc -- do the work of free than malloc, but call realloc to do
* it. (Provided by Mark Eichin, eichin@athena.mit.edu) Thanks.
/* not really mips specific */
/* the stupid X server I'm working on does this */
realcp
= (char *) ((int) cp
- MPROF_HEADER_SIZE
);
force
= (mpheader
*) realcp
;
mprof_note_free(force
->creators
, force
->nbytes
);
result
= __realloc__(realcp
, nbytes
+ MPROF_HEADER_SIZE
);
force
= (mpheader
*) result
;
force
->creators
= mprof(nbytes
);
return (char *) ((int) result
+ MPROF_HEADER_SIZE
);
/* free -- Free an object, coercing it back to the correct size.
realcp
= (char *) ((int) cp
- MPROF_HEADER_SIZE
);
force
= (mpheader
*) realcp
;
mprof_note_free(force
->creators
, force
->nbytes
);
/* memalign -- Allocate aligned memory. This patch was provided by Robert
* Scheifler and handles calls to memalign and valloc on the Sun as long
* as the memory allocated is never later freed. Furthermore, unlike the
* real Sun memalign, the extra memory allocated is not freed.
#define round_to(i, nearest) \
((((i) + (nearest) - 1) / (nearest)) * (nearest))
memalign(alignment
, nbytes
)
* Check size and alignment parameters.
if (nbytes
== 0 || ((unsigned)(alignment
) & 3)) {
nbytes
= round_to(nbytes
, sizeof(int));
cp
= malloc(nbytes
+ alignment
);
return (char *) round_to((unsigned int) cp
, alignment
);
/* valloc -- Allocate memory on a page-aligned boundary. This function
* uses memalign so the same problems occur (i.e. the memory allocated
* cannot later be freed and the extra memory allocated is lost).
return memalign(getpagesize(), nbytes
);
/* exit -- mprof has its own version of exit so that the mprof file
* can be written and closed when mprof finishes.
* The sun doesn't need this because on_exit allows the user to add
* functions called on exit.
#if defined(vax) || defined(mips)
mprof_exit(status
, dummy
)