summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorhboehm <hboehm>2007-08-04 08:26:29 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:41 +0200
commit87b2e2602e766e448e7d65d7a7a7eb3e3cd020cb (patch)
tree0162d9d9de90bf1acb3653e4876d39b0e52d6439 /malloc.c
parent6db625e8a2a7d5d8b4faf8747b5688cd64f3949e (diff)
2007-08-03 Hans Boehm <Hans.Boehm@hp.com>
* alloc.c, backgraph.c, headers.c, include/private/gc_priv.h: Maintain GC_our_memory and GC_n_memory. * dbg_mlc.c (GC_print_smashed_obj): Improve message. (GC_print_all_smashed_proc): Pass client object address instead of base. * dyn_load.c (sort_heap_sects): New. (GC_register_map_entries): Register sections that are contiguous and merged with our heap. * malloc.c, os_dep.c (GC_text_mapping): Check for just base name of libraries. * malloc.c (calloc): Check for special callers even with USE_PROC_FOR_LIBRARIES. Move assertion. Add rudimentary malloc/free tracing. * misc.c: No longer call GC_init_lib_bounds explicitly. * thread_local_alloc.c (GC_malloc, GC_malloc_atomic): Always initialize on demand. * tests/test.c: Call GC_INIT only when required.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/malloc.c b/malloc.c
index 9403264..4795048 100644
--- a/malloc.c
+++ b/malloc.c
@@ -319,7 +319,7 @@ void * malloc(size_t lb)
return((void *)REDIRECT_MALLOC(lb));
}
-#ifdef GC_LINUX_THREADS
+#if defined(GC_LINUX_THREADS) /* && !defined(USE_PROC_FOR_LIBRARIES) */
static ptr_t GC_libpthread_start = 0;
static ptr_t GC_libpthread_end = 0;
static ptr_t GC_libld_start = 0;
@@ -330,17 +330,15 @@ void * malloc(size_t lb)
void GC_init_lib_bounds(void)
{
if (GC_libpthread_start != 0) return;
- if (!GC_text_mapping("/lib/tls/libpthread-",
- &GC_libpthread_start, &GC_libpthread_end)
- && !GC_text_mapping("/lib/libpthread-",
- &GC_libpthread_start, &GC_libpthread_end)) {
+ if (!GC_text_mapping("libpthread-",
+ &GC_libpthread_start, &GC_libpthread_end)) {
WARN("Failed to find libpthread.so text mapping: Expect crash\n", 0);
/* This might still work with some versions of libpthread, */
/* so we don't abort. Perhaps we should. */
/* Generate message only once: */
GC_libpthread_start = (ptr_t)1;
}
- if (!GC_text_mapping("/lib/ld-", &GC_libld_start, &GC_libld_end)) {
+ if (!GC_text_mapping("ld-", &GC_libld_start, &GC_libld_end)) {
WARN("Failed to find ld.so text mapping: Expect crash\n", 0);
}
}
@@ -348,7 +346,7 @@ void * malloc(size_t lb)
void * calloc(size_t n, size_t lb)
{
-# if defined(GC_LINUX_THREADS) && !defined(USE_PROC_FOR_LIBRARIES)
+# if defined(GC_LINUX_THREADS) /* && !defined(USE_PROC_FOR_LIBRARIES) */
/* libpthread allocated some memory that is only pointed to by */
/* mmapped thread stacks. Make sure it's not collectable. */
{
@@ -406,11 +404,13 @@ void GC_free(void * p)
if (p == 0) return;
/* Required by ANSI. It's not my fault ... */
+# ifdef LOG_ALLOCS
+ GC_err_printf("GC_free(%p): %d\n", p, GC_gc_no);
+# endif
h = HBLKPTR(p);
hhdr = HDR(h);
sz = hhdr -> hb_sz;
ngranules = BYTES_TO_GRANULES(sz);
- GC_ASSERT(GC_base(p) == p);
# if defined(REDIRECT_MALLOC) && \
(defined(GC_SOLARIS_THREADS) || defined(GC_LINUX_THREADS) \
|| defined(MSWIN32))
@@ -420,6 +420,7 @@ void GC_free(void * p)
/* Don't try to deallocate that memory. */
if (0 == hhdr) return;
# endif
+ GC_ASSERT(GC_base(p) == p);
knd = hhdr -> hb_obj_kind;
ok = &GC_obj_kinds[knd];
if (EXPECT((ngranules <= MAXOBJGRANULES), 1)) {