diff options
author | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-06-29 05:19:15 +0000 |
---|---|---|
committer | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-06-29 05:19:15 +0000 |
commit | 2c4e5358db11e4d69efb7d9c3ef2baa4a87af220 (patch) | |
tree | 57753d1ad4133ef0719131a1ae7164defeeacc17 | |
parent | eb4e0b615fe3f4ac68290d2d411c0c152a398ab9 (diff) | |
download | valgrind-2c4e5358db11e4d69efb7d9c3ef2baa4a87af220.tar.gz |
Add a comment.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10383 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r-- | coregrind/m_replacemalloc/vg_replace_malloc.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index b36e80282..e1ed9fde3 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -106,7 +106,8 @@ static struct vg_mallocfunc_info info; static int init_done; /* Startup hook - called as init section */ -static void init(void) __attribute__((constructor)); +__attribute__((constructor)) +static void init(void); #define MALLOC_TRACE(format, args...) \ if (info.clo_trace_malloc) { \ @@ -794,10 +795,27 @@ ZONE_CHECK(VG_Z_LIBC_SONAME, malloc_zone_check); /* All the code in here is unused until this function is called */ +__attribute__((constructor)) static void init(void) { int res; + // This doesn't look thread-safe, but it should be ok... Bart says: + // + // Every program I know of calls malloc() at least once before calling + // pthread_create(). So init_done gets initialized before any thread is + // created, and is only read when multiple threads are active + // simultaneously. Such an access pattern is safe. + // + // If the assignment to the variable init_done would be triggering a race + // condition, both DRD and Helgrind would report this race. + // + // By the way, although the init() function in + // coregrind/m_replacemalloc/vg_replace_malloc.c has been declared + // __attribute__((constructor)), it is not safe to remove the variable + // init_done. This is because it is possible that malloc() and hence + // init() gets called before shared library initialization finished. + // if (init_done) return; @@ -808,5 +826,5 @@ static void init(void) } /*--------------------------------------------------------------------*/ -/*--- end vg_replace_malloc.c ---*/ +/*--- end ---*/ /*--------------------------------------------------------------------*/ |