From patchwork Fri Jun 29 12:46:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 936855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-93811-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Oq9S2kho"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41HGcS5K7Gz9ry1 for ; Fri, 29 Jun 2018 22:46:48 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= hQpwBGedwkB2HNK1HH/Vop0w+25WNqVR7niBrz3vcPyq1hX/6l9TznOxzR++lY8n 4Ib2jWdNKRvWMBHOFZSQxVIE/tj3tN5eL0sdfpujWWMu3D5kWkZx2xNwXxs4yfp/ mH9gQYEI5CJpgEWPy9TUb5jQF6dWpVWscynXD44+S/M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=Ulcf+n gPTqxLsY5FMBnsh4WDVP8=; b=Oq9S2khoG0HLRjtcKz0fo0aKabKpSFeJDA/0J/ R10Bn0wqX0uEY+njH3mWWEGcHpJy8QHKkbdivC8xpggmh3ZH3zTUj5U8G7Fkjeyc iB6A+/pTs8BciJWJ60pz5mEC4OONO03JxD/qupNjUklrS7qOj/SRtC6s7tYPLRsh V49Tk= Received: (qmail 87285 invoked by alias); 29 Jun 2018 12:46:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 86501 invoked by uid 89); 29 Jun 2018 12:46:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=restoring X-HELO: mx1.redhat.com Date: Fri, 29 Jun 2018 14:46:33 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Update heap dumping/undumping comments [BZ #23351] User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20180629124633.2A33A43994575@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) Also remove a few now-unused declarations and definitions. 2018-06-29 Florian Weimer [BZ #23351] * malloc/hooks.c: Update comments on restoring of dumped heaps. (disallow_malloc_check): Remove variable. (__malloc_check_init): Adjust. (malloc_set_state): Update comment. * malloc/malloc.c (__malloc_get_state, __malloc_set_state): Remove declarations. Reviewed-by: Carlos O'Donell diff --git a/malloc/hooks.c b/malloc/hooks.c index 95aefd0bfc..ae7305b036 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -52,30 +52,10 @@ memalign_hook_ini (size_t alignment, size_t sz, const void *caller) /* Whether we are using malloc checking. */ static int using_malloc_checking; -/* A flag that is set by malloc_set_state, to signal that malloc checking - must not be enabled on the request from the user (via the MALLOC_CHECK_ - environment variable). It is reset by __malloc_check_init to tell - malloc_set_state that the user has requested malloc checking. - - The purpose of this flag is to make sure that malloc checking is not - enabled when the heap to be restored was constructed without malloc - checking, and thus does not contain the required magic bytes. - Otherwise the heap would be corrupted by calls to free and realloc. If - it turns out that the heap was created with malloc checking and the - user has requested it malloc_set_state just calls __malloc_check_init - again to enable it. On the other hand, reusing such a heap without - further malloc checking is safe. */ -static int disallow_malloc_check; - /* Activate a standard set of debugging hooks. */ void __malloc_check_init (void) { - if (disallow_malloc_check) - { - disallow_malloc_check = 0; - return; - } using_malloc_checking = 1; __malloc_hook = malloc_check; __free_hook = free_check; @@ -407,21 +387,11 @@ memalign_check (size_t alignment, size_t bytes, const void *caller) #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_25) -/* Get/set state: malloc_get_state() records the current state of all - malloc variables (_except_ for the actual heap contents and `hook' - function pointers) in a system dependent, opaque data structure. - This data structure is dynamically allocated and can be free()d - after use. malloc_set_state() restores the state of all malloc - variables to the previously obtained state. This is especially - useful when using this malloc as part of a shared library, and when - the heap contents are saved/restored via some other method. The - primary example for this is GNU Emacs with its `dumping' procedure. - `Hook' function pointers are never saved or restored by these - functions, with two exceptions: If malloc checking was in use when - malloc_get_state() was called, then malloc_set_state() calls - __malloc_check_init() if possible; if malloc checking was not in - use in the recorded state but the user requested malloc checking, - then the hooks are reset to 0. */ +/* Support for restoring dumped heaps contained in historic Emacs + executables. The heap saving feature (malloc_get_state) is no + longer implemented in this version of glibc, but we have a heap + rewriter in malloc_set_state which transforms the heap into a + version compatible with current malloc. */ #define MALLOC_STATE_MAGIC 0x444c4541l #define MALLOC_STATE_VERSION (0 * 0x100l + 5l) /* major*0x100 + minor */ @@ -476,7 +446,7 @@ malloc_set_state (void *msptr) if ((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2; - /* We do not need to perform locking here because __malloc_set_state + /* We do not need to perform locking here because malloc_set_state must be called before the first call into the malloc subsytem (usually via __malloc_initialize_hook). pthread_create always calls calloc and thus must be called only afterwards, so there diff --git a/malloc/malloc.c b/malloc/malloc.c index 9614954975..e247c77b7d 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -697,22 +697,6 @@ size_t __malloc_usable_size(void*); */ void __malloc_stats(void); -/* - malloc_get_state(void); - - Returns the state of all malloc variables in an opaque data - structure. -*/ -void* __malloc_get_state(void); - -/* - malloc_set_state(void* state); - - Restore the state of all malloc variables from data obtained with - malloc_get_state(). -*/ -int __malloc_set_state(void*); - /* posix_memalign(void **memptr, size_t alignment, size_t size);