From patchwork Wed Aug 4 20:39:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44572 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98BA4395BC12 for ; Wed, 4 Aug 2021 20:40:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98BA4395BC12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628109612; bh=dHYTQR2xAkVAH6dqwu5blgsjn37MTQus/ZWeLd6ggCY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ReNzFWwnf6LgH4BuDJyErPdIFE5A4RZBwg+XIR1u0/xC/RhCgGg1+eo/PDiCLA+t7 spWTDznUMKs/6B+WAqw74Qj4dwUk5Zdg3ljhPtt9/b00R9VwyzgbLeg/PCTL4EQpNp lzP8PTeyFZZx5lshuMceJ0c9R7LQHwnp5HVrWWkg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 8CCD13857433 for ; Wed, 4 Aug 2021 20:39:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CCD13857433 Received: by mail-pj1-x102c.google.com with SMTP id mt6so4790007pjb.1 for ; Wed, 04 Aug 2021 13:39:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=dHYTQR2xAkVAH6dqwu5blgsjn37MTQus/ZWeLd6ggCY=; b=ZXaUtC+oklhb0BeKSDO6puUHOEBnew5GLO/MyRQjELNOPzIVFEFxiLu6evXfcezyVT aVfNosP7san48BiX5XADc3HQe8n9EfwgVj01EOgh4/Tfhzb4XXKYDgX52nV2VYDRwMSQ g8QIDW4O2cDDGCs9ILQNbBiPhVKrrZzTPrvmewkjpeHsgmZkpw5kN3fHFOOjjZF0w6SY /mvC3SkJAIwNtvH5nsLxTl3lVRpkbXCcpeM1YtWOZAKKH65bcDIWxJMRrwL714fO6qmr Y6WGSqOKQbpHvgzj3HZUxr+ewyD0L46aAo234yKzRhHbSBAs2NuUsndnlba7ssu+RAiL ox8Q== X-Gm-Message-State: AOAM531HC20QVSeAe8IP4oLMvNNERtVNtrccH75la5dZmFz4OlacB/hQ LzmBK3hubvvMzZYdle8g6SCjAHbN1S9N7A== X-Google-Smtp-Source: ABdhPJyKSVVQrp+XvAgIIU4SlSyQXuGevb4pIFOhs7eLzWokwJ+iwKOIyM14PrbRgsBGgE5UcGUuIQ== X-Received: by 2002:a62:a516:0:b029:333:1995:5e75 with SMTP id v22-20020a62a5160000b029033319955e75mr1130696pfm.67.1628109589424; Wed, 04 Aug 2021 13:39:49 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:76cd:ebc7:4201:855e:55a1]) by smtp.gmail.com with ESMTPSA id a21sm7355567pjo.15.2021.08.04.13.39.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 13:39:49 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Add sparck brk implementation Date: Wed, 4 Aug 2021 17:39:45 -0300 Message-Id: <20210804203945.1559122-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It turned that the generic implementation of brk() does not work for sparc, since on failure kernel will just return the previous input value without setting the conditional register. This patches adds back a sparc32 and sparc64 implementation removed by 720480934ab9107. Checked on sparc64-linux-gnu and sparcv9-linux-gnu. --- sysdeps/unix/sysv/linux/sparc/brk.c | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/sparc/brk.c diff --git a/sysdeps/unix/sysv/linux/sparc/brk.c b/sysdeps/unix/sysv/linux/sparc/brk.c new file mode 100644 index 0000000000..aafe9673e3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/brk.c @@ -0,0 +1,58 @@ +/* Change data segment. Linux SPARC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + +/* This must be initialized data because commons can't have aliases. */ +void *__curbrk = 0; + +#if HAVE_INTERNAL_BRK_ADDR_SYMBOL +/* Old braindamage in GCC's crtstuff.c requires this symbol in an attempt + to work around different old braindamage in the old Linux ELF dynamic + linker. */ +weak_alias (__curbrk, ___brk_addr) +#endif + +#ifdef __arch64__ +# define SYSCALL_NUM "0x6d" +#else +# define SYSCALL_NUM "0x10" +#endif + +int +__brk (void *addr) +{ + register long int g1 asm ("g1") = __NR_brk; + register long int o0 asm ("o0") = (long int) addr; + asm volatile ("ta " SYSCALL_NUM + : "=r"(o0) + : "r"(g1), "0"(o0) + : "cc"); + __curbrk = (void *) o0; + + if (__curbrk < addr) + { + __set_errno (ENOMEM); + return -1; + } + + return 0; +} +weak_alias (__brk, brk)