mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-02 19:22:47 +00:00
rtld_malloc: add cp2op() helper
converting user allocation address into overhead pointer Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150
This commit is contained in:
parent
bc7e86106d
commit
86c7368f2b
@ -106,6 +106,12 @@ static int pagesz; /* page size */
|
||||
* increasing order.
|
||||
*/
|
||||
|
||||
static union overhead *
|
||||
cp2op(void *cp)
|
||||
{
|
||||
return ((union overhead *)((caddr_t)cp - sizeof(union overhead)));
|
||||
}
|
||||
|
||||
void *
|
||||
__crt_malloc(size_t nbytes)
|
||||
{
|
||||
@ -209,7 +215,7 @@ __crt_free(void *cp)
|
||||
|
||||
if (cp == NULL)
|
||||
return;
|
||||
op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
|
||||
op = cp2op(cp);
|
||||
if (op->ov_magic != MAGIC)
|
||||
return; /* sanity */
|
||||
size = op->ov_index;
|
||||
@ -227,7 +233,7 @@ __crt_realloc(void *cp, size_t nbytes)
|
||||
|
||||
if (cp == NULL)
|
||||
return (__crt_malloc(nbytes));
|
||||
op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
|
||||
op = cp2op(cp);
|
||||
if (op->ov_magic != MAGIC)
|
||||
return (NULL); /* Double-free or bad argument */
|
||||
i = op->ov_index;
|
||||
|
Loading…
Reference in New Issue
Block a user