This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] malloc: Perform full initialization before __malloc_check_init


On 09/21/2017 08:15 PM, Wilco Dijkstra wrote:
Florian Weimer wrote:

Well it looks like the malloc initialization is insane. It sets default hooks for
malloc/realloc/etc which call ptmalloc_init, which is completely unguarded
from multi-threaded execution...

I have tried to explain repeatedly why this is not a problem: pthread_create calls malloc before launching a new thread, so ptmalloc_init is always run in single-thread mode.

Then it implicitly relies on have_fastchunks
being true (from zero-initialization of main_arena by inverting the meaning of
the flag), which should eventually result in a call to malloc_consolidate, which
assuming max_fast hasn't yet been set, finally calls malloc_init_state...

Sure, it's convoluted.

+    {
+      /* Perform full initialization.  */
+      malloc_consolidate (&main_arena);
+      __malloc_check_init ();
+    }

That's an improvement but ptmalloc_init should call malloc_init_state (&main_arena)
in all cases. The check in malloc_consolidate should then be removed (no idea why
anyone would want to delay initialization to that point...). Interestingly malloc_init_state
is called for other arenas...

I didn't want to touch until we remove the hooks and have to overhaul the initialization procedure anyway (i.e., detect whether malloc has been interposed, and if not, perform malloc initialization during process startup before calling ELF constructors and main).

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]