From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 99AD13858006 for ; Tue, 29 Dec 2020 13:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99AD13858006 Received: by mail-oi1-x234.google.com with SMTP id s75so14639327oih.1 for ; Tue, 29 Dec 2020 05:39:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UEj2Ne9aScIx7G9T7YUpwEP7zBL++OXHWiVdLWxCNfg=; b=pvec0zma0Y6MI/dVC1EGJs/ohT9N8bYiVLwyiAJdffqiV4noFHSKPvT/7Fw4BVj8Y8 44SrRnmX158E9e73qMQQie2AHZZ535IICapkVVN+Wk7cdhUAzzFdTQkfiXRC2l0u2c74 CcRb6q9bkFJNMJ497dERLwDJMQPSZKcm4Wk1JXj2ouNYb38OUQwjRPLZOzTyOGuer2Af dfVbMhMQQaSknxzpvPWd4TN7q7SAF1k9qckJJZ+1QAPsUV2b0qcFueSydaSBwcLHODTM TJZs7q27vRB+5Yhumgkb/XAPv1vQnb6M0BzNkH46e7X5Di1rjE1RkNCZniiY05ew4x+k zb0w== X-Gm-Message-State: AOAM5327XZmk8JP3slEh4NmH1lYxh5T1OTJPFE90JAx1StLDabO2mgTR QDFfcy2Wly1aLszDtQIjtBwoPDXMMg/uJt1vb2E= X-Google-Smtp-Source: ABdhPJxEmO2JeljEu1VwGZTDyHMtuO+L8T7vouYQh2NzfltYuSXTPhb9at+vQ7cQqIT08PezTJYo00yzAYGlRekO1eI= X-Received: by 2002:aca:f456:: with SMTP id s83mr2260790oih.58.1609249157063; Tue, 29 Dec 2020 05:39:17 -0800 (PST) MIME-Version: 1.0 References: <20201220202556.3714-1-eggert@cs.ucla.edu> <871rfjzep6.fsf@oldenburg2.str.redhat.com> <11ae3757-fe3b-4bd8-92d2-a8d0a1af9ad4@linaro.org> <3d69d844-afce-c4b7-3ea6-bb9c4f034b29@cs.ucla.edu> In-Reply-To: From: "H.J. Lu" Date: Tue, 29 Dec 2020 05:38:40 -0800 Message-ID: Subject: Re: [PATCH] free: preserve errno [BZ#17924] To: Adhemerval Zanella Cc: Paul Eggert , Florian Weimer , GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3030.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Dec 2020 13:39:19 -0000 On Mon, Dec 28, 2020 at 11:24 AM Adhemerval Zanella via Libc-alpha wrote: > > > > On 23/12/2020 22:03, Paul Eggert wrote: > > Thanks for the comments about the patch's test case. I modified the tes= t case to reflect nearly all the comments, resulting in the attached revise= d patch. I'm replying below only to the comments that didn't result in a ch= ange to the patch. > > > > On 12/23/20 11:19 AM, Adhemerval Zanella wrote: > > > >> Fixing in a more fine grained would require a lot of more work to chec= k if > >> the shared routines that calls mmap, madvise or brk won't interfere wi= th other > >> symbols; so maybe it should be ok to use this large hammer for now. > > > > Yes, that was my thought as well. > > I will try to revise this for 2.33. > > > > >>> +The @code{free} function preserves the value of @code{errno}, so tha= t > >>> +cleanup code need not worry about saving and restoring @code{errno} > >>> +around a call to @code{free}. Although neither @w{ISO C} nor > >>> +POSIX.1-2017 requires @code{free} to preserve @code{errno}, a future > >>> +version of POSIX is planned to require it. > > ... > >> Not sure if this is worth to add, since we will need to update the man= ual > >> once the POSIX does require it. > > > > I'll volunteer to update the manual. :-) > > > > It's worth mentioning that preserving errno is not something that porta= ble C or POSIX code should assume for 'free'. If there's a better way for t= he manual to warn its readers about this, that'd be fine of course. > > > > I did consider changing "Although neither @w{ISO C} nor POSIX.1-2017 re= quires @code{free} to preserve @code{errno}, a future version of POSIX is p= lanned to require it" to "Neither @w{ISO C} nor POSIX requires @code{free} = to preserve @code{errno}", but that wording would be less informative and w= ould still need updating once POSIX does require 'free' to preserve errno. > > Thanks. > > > From afbf4ff042cf3a5c8f983d5aa3bd0de3fb696dd3 Mon Sep 17 00:00:00 2001 > > From: Paul Eggert > > Date: Wed, 23 Dec 2020 11:27:25 -0800 > > Subject: [PATCH] free: preserve errno [BZ#17924] > > > > In the next release of POSIX, free must preserve errno > > . > > Modify __libc_free to save and restore errno, so that > > any internal munmap etc. syscalls do not disturb the caller's errno. > > Add a test malloc/tst-free-errno.c (almost all by Bruno Haible), > > and document that free preserves errno. > > LGTM with the small test change below. > > Reviewed-by: Adhemerval Zanella > On a machine with 192 GB RAM, I got [hjl@gnu-clx-1 build-x86_64-linux]$ cat malloc/tst-free-errno-mcheck.out error: tst-free-errno.c:124: not true: get_errno () =3D=3D 1789 error: 1 test failures [hjl@gnu-clx-1 build-x86_64-linux]$ --=20 H.J.