From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id C309D3857373 for ; Mon, 16 May 2022 13:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C309D3857373 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-f16a3e0529so9596788fac.2 for ; Mon, 16 May 2022 06:04:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=PeyIyAfWkcnsa3/VYnHUmYI8WE4wpxHhPLsvX0m97zY=; b=XewTtFLh/Wn35A+CwNSaF8H2sBQ4R6VS4DpTbxNN5Jp+zBt7Ypr83T39yAiiPj2VnR yeQis/UgU4aOV8bx3BZCEKlW7YCc+/uKd5f1cF5X4nDujl6+aFu48Yb6Rp/BL3LD4dwg 9qP+mtTu94iFEGp0zORloq8xQz2valfrXkBHiyruDQSkQsGLynM45mX7kb8/+6DDccIA l7+ZgYQOAaeMET1JQMMUNvtDW7MbQ5OX5o929r0nM+Qn6ShHxqt+jD/2WOBrYa5ItO8o DpyEGtGjKUy3OSGqRu90QlVvPBAtzFsvLefRuJr3Tc7V8540z2EpbDvr5VtcEp2xpS25 I4Ww== X-Gm-Message-State: AOAM530JvDY9Njm4u/ZCTj+a7sNHe+My1UjvQNmIlNwzW2FAj8XsFefK fE6+5doWcnvSQs6jSAr31bPMzPLOISpFng== X-Google-Smtp-Source: ABdhPJwP6SAb/eTR4lkh0ZNfh4rhY/UWIqWkqSnPggQcr+BN6oNyVbyxZltNwytcgHJCqEyJyuBVcg== X-Received: by 2002:a05:6870:5248:b0:ec:4732:8978 with SMTP id o8-20020a056870524800b000ec47328978mr14590019oai.254.1652706276734; Mon, 16 May 2022 06:04:36 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:cdd6:545a:8832:b9c2:3a47? ([2804:431:c7cb:cdd6:545a:8832:b9c2:3a47]) by smtp.gmail.com with ESMTPSA id p6-20020acabf06000000b00325cda1ffa6sm3787049oif.37.2022.05.16.06.04.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 May 2022 06:04:36 -0700 (PDT) Message-ID: <13d3a2db-7851-f744-59fc-190dfd7be2a9@linaro.org> Date: Mon, 16 May 2022 10:04:34 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v5 2/2] csu: Implement and use _dl_early_allocate during static startup Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <63d4e062-b5a5-a430-fa56-da09912f1d1a@linaro.org> <87lev6siky.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87lev6siky.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Mon, 16 May 2022 13:04:40 -0000 On 12/05/2022 15:37, Florian Weimer wrote: > * Adhemerval Zanella: > >>> +void * >>> +_dl_early_allocate (size_t size) >>> +{ >>> + void *result; >>> + >>> + if (__curbrk != NULL) >>> + /* If the break has been initialized, brk must have run before, >>> + so just call it once more. */ >>> + { >>> + result = __sbrk (size); >>> + if (result == (void *) -1) >>> + result = NULL; >>> + } >>> + else >>> + { >>> + /* If brk has not been invoked, there is no need to update >>> + __curbrk. The first call to brk will take care of that. */ >>> + void *previous = __brk_call (0); >>> + result = __brk_call (previous + size); >>> + if (result == previous) >>> + result = NULL; >>> + else >>> + result = previous; >>> + } >> >> Why do you need to avoid update __curbrk here? Otherwise it seems that a >> __sbrk() should be suffice here. > > A subsequent call to _dl_early_allocate would then take the first (sbrk) > branch, which may or may not be correct, depending on whether the TCB > has been initialized at that point or not. OK, LGTM then. I think I might try later to consolidate the mmap syscall, although not sure if it would be worth. Reviewed-by: Adhemerval Zanella