1
1

* update ptmalloc2 to build properly and intercept user-level calls to

munmap

This commit was SVN r6867.
Этот коммит содержится в:
Brian Barrett 2005-08-14 03:11:54 +00:00
родитель 683e80c48b
Коммит da89e06238
6 изменённых файлов: 112 добавлений и 62 удалений

Просмотреть файл

@ -38,6 +38,8 @@ doc_DATA = ptmalloc2-COPYRIGHT
noinst_LTLIBRARIES = libmca_memory_ptmalloc2.la
libmca_memory_ptmalloc2_la_SOURCES = \
ptmalloc2_component.c \
ptmalloc2_munmap.c \
malloc.c \
malloc-stats.c \
malloc.h

Просмотреть файл

@ -564,9 +564,9 @@ public_sET_STATe(Void_t* msptr)
/* There are no fastchunks. */
clear_fastchunks(&main_arena);
set_max_fast(&main_arena, DEFAULT_MXFAST);
for (i=0; i<NFASTBINS; ++i)
for (i=0; i<(int)NFASTBINS; ++i)
main_arena.fastbins[i] = 0;
for (i=0; i<BINMAPSIZE; ++i)
for (i=0; i<(int)BINMAPSIZE; ++i)
main_arena.binmap[i] = 0;
top(&main_arena) = ms->av[2];
main_arena.last_remainder = 0;
@ -576,8 +576,8 @@ public_sET_STATe(Void_t* msptr)
assert(ms->av[2*i+3] == 0);
first(b) = last(b) = b;
} else {
if(i<NSMALLBINS || (largebin_index(chunksize(ms->av[2*i+2]))==i &&
largebin_index(chunksize(ms->av[2*i+3]))==i)) {
if(i<(int)NSMALLBINS || ((int)largebin_index(chunksize(ms->av[2*i+2]))==i &&
(int)largebin_index(chunksize(ms->av[2*i+3]))==i)) {
first(b) = ms->av[2*i+2];
last(b) = ms->av[2*i+3];
/* Make sure the links to the bins within the heap are correct. */

Просмотреть файл

@ -91,7 +91,7 @@ void public_mSTATs()
struct malloc_global_info mgi;
struct malloc_arena_info mai;
unsigned long in_use_b, system_b, avail_b;
#if THREAD_STATS
#if defined(THREAD_STATS) && THREAD_STATS
long stat_lock_direct = 0, stat_lock_loop = 0, stat_lock_wait = 0;
#endif
@ -120,7 +120,7 @@ void public_mSTATs()
#endif
system_b += mai.system_mem;
in_use_b += mai.system_mem - avail_b;
#if THREAD_STATS
#if defined(THREAD_STATS) && THREAD_STATS
stat_lock_direct += mai.stat_lock_direct;
stat_lock_loop += mai.stat_lock_loop;
stat_lock_wait += mai.stat_lock_wait;
@ -142,7 +142,7 @@ void public_mSTATs()
fprintf(stderr, "max mmap bytes = %10lu\n",
(unsigned long)mgi.max_mmapped_mem);
#endif
#if THREAD_STATS
#if defined(THREAD_STATS) && THREAD_STATS
fprintf(stderr, "heaps created = %10d\n", mgi.stat_n_heaps);
fprintf(stderr, "locked directly = %10ld\n", stat_lock_direct);
fprintf(stderr, "locked in loop = %10ld\n", stat_lock_loop);

Просмотреть файл

@ -2,40 +2,11 @@
#define OMPI_DISABLE_ENABLE_MEM_DEBUG 1
#include "ompi_config.h"
#include <unistd.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "opal/mca/memory/memory.h"
#include "opal/memory/memory_internal.h"
const opal_memory_base_component_1_0_0_t mca_memory_ptmalloc2_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
/* Indicate that we are a memory v1.0.0 component (which also
implies a specific MCA version) */
OPAL_MEMORY_BASE_VERSION_1_0_0,
/* Component name and version */
"ptmalloc2s",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL
},
/* Next the MCA v1.0.0 component meta data */
{
/* Whether the component is checkpointable or not */
true
},
};
/*
* Not all systems have sbrk() declared, since it's technically not a
* POSIX function.
@ -55,12 +26,7 @@ opal_mem_free_ptmalloc2_sbrk(int inc)
return sbrk(inc);
}
static int
opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
{
opal_mem_free_release_hook(start, length);
return munmap(start, length);
}
extern int opal_mem_free_ptmalloc2_munmap(void *start, size_t length);
#define MORECORE opal_mem_free_ptmalloc2_sbrk
#define munmap(a,b) opal_mem_free_ptmalloc2_munmap(a,b)
@ -78,24 +44,6 @@ opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
#define __const const
#endif
/* need to intercept munmap from the user as well as the usual
malloc. 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) {
{
static int (*realmunmap)(void*, size_t);
/* dispatch about the pending release */
opal_mem_free_release_hook(addr, len);
if (NULL == realmunmap) {
realmunmap = dlsym(RTLD_NEXT, "munmap");
}
return realmunmap(addr, len);
}
/********************* BEGIN OMPI CHANGES ******************************/
@ -955,7 +903,7 @@ Void_t* public_mALLOc();
#ifdef libc_hidden_proto
libc_hidden_proto (public_mALLOc)
#endif
static void here(void);
/*
free(Void_t* p)
Releases the chunk of memory pointed to by p, that had been previously
@ -3729,7 +3677,7 @@ public_cALLOc(size_t n, size_t elem_size)
#if MORECORE_CLEARS < 2
/* Only newly allocated memory is guaranteed to be cleared. */
if (av == &main_arena &&
oldtopsize < mp_.sbrk_base + av->max_system_mem - (char *)oldtop)
oldtopsize < (INTERNAL_SIZE_T)(mp_.sbrk_base + av->max_system_mem - (char *)oldtop))
oldtopsize = (mp_.sbrk_base + av->max_system_mem - (char *)oldtop);
#endif
#endif

Просмотреть файл

@ -0,0 +1,45 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* 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 "ompi_config.h"
#include "opal/mca/memory/memory.h"
const opal_memory_base_component_1_0_0_t mca_memory_ptmalloc2_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
/* Indicate that we are a memory v1.0.0 component (which also
implies a specific MCA version) */
OPAL_MEMORY_BASE_VERSION_1_0_0,
/* Component name and version */
"ptmalloc2",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL
},
/* Next the MCA v1.0.0 component meta data */
{
/* Whether the component is checkpointable or not */
true
},
};

Просмотреть файл

@ -0,0 +1,55 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* 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/memory/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_free_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_free_release_hook(start, length);
if (NULL == realmunmap) {
realmunmap = (int (*)(void*, size_t)) dlsym(RTLD_NEXT, "munmap");
}
return realmunmap(start, length);
}