1
1
openmpi/opal/mca/memory/ptmalloc2/ptmalloc2_munmap.c
Brian Barrett 79bf8843d2 * update memory hooks interface to allow for callbacks on both allocations
and dealllocations, per request from Galen and Tim

This commit was SVN r8303.
2005-11-29 04:46:14 +00:00

58 строки
1.7 KiB
C

/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include <sys/types.h>
#include "opal/memoryhooks/memory_internal.h"
#include <stdlib.h>
#include <sys/mman.h>
#define __USE_GNU
#include <dlfcn.h>
static int (*realmunmap)(void*, size_t);
/* munmap is a weak symbol on any platform that I know of that
supports malloc hooks, so we can just intercept it like this... */
int
munmap(void* addr, size_t len)
{
/* dispatch about the pending release */
opal_mem_hooks_release_hook(addr, len);
if (NULL == realmunmap) {
realmunmap = (int (*)(void*, size_t)) dlsym(RTLD_NEXT, "munmap");
}
return realmunmap(addr, len);
}
/* put this here beacuse malloc.c really doesn't like dlfcn.h, but we
need it for getting the right munmap... */
int
opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
{
opal_mem_hooks_release_hook(start, length);
if (NULL == realmunmap) {
realmunmap = (int (*)(void*, size_t)) dlsym(RTLD_NEXT, "munmap");
}
return realmunmap(start, length);
}