From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 36CE73858D38 for ; Fri, 12 Apr 2024 10:56:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36CE73858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36CE73858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712919365; cv=none; b=IEBm06pZ9hgXhwAmCy66MATl2X/Eeb35XtApTCklhGNulzE2TO3ZFriXvQur+qGlGh6dWhEzzTDpITi8FZbIUdTfjtKGIqblWtcLU3X2aEqSfAT0UULcBVD9L7/UeNLDPMXheBs9woxWxGb8oYxVh0o0ZwXJT6kwveV4AVkOagk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712919365; c=relaxed/simple; bh=mzHj9QZ87cgw/z1v2CVPpSXShKiMZK5qVNpR8bHYk50=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GqMRyqrPWQC1Oom5MclgCzEriJnSQZ8UsST9scPNoGFVrtMpBbvAEdxQbaBm3/VDDhORE7S6WSzG6GKs+EEh7hHKL5yifrmFrREcNLIs4hBjWpv+Vc8c+va16K4Ziu4FaXCUswqRyJlFJq8EGtkHbXxV8JftaPrUlBno5VUQOBg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712919363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p0sfIfLUXvbBqnm8CcLzTaxIsyqXrY7+DS/lbaE7rX0=; b=dKAs6ZcEyFtwgsmN0HEpop4enUyZ58rOdQ1e+HhUZaFsX5XwW0GSfuvO3NV+TESAqEGtKI IRV669QVcXInmNnKvMsrTIRDCSaJWq/jN7Sb6Dqbi6M3Vnt5DLoVsZhYBka0ZHdcmBXKo3 cFH9ET5/A1lbQHMlW3HnQM51ngyczKM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-hQoNvl_iMZ2zulLqRLpxmw-1; Fri, 12 Apr 2024 06:56:02 -0400 X-MC-Unique: hQoNvl_iMZ2zulLqRLpxmw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-343e74dcf0bso509692f8f.0 for ; Fri, 12 Apr 2024 03:56:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712919361; x=1713524161; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p0sfIfLUXvbBqnm8CcLzTaxIsyqXrY7+DS/lbaE7rX0=; b=Ma+jk8LtNyownG6CnHZUi8MFhd80Bgnh9XVAt/8zLoKy8n+1p+nLgQI4j8ZTj8QQ9U CuRxwKE25XLAoxqOTEraRsHMvqpa2bSGO3WZz1vESYGeXQ0HfamdiyixDIXP/2ln46Xh MilazRu/oxpg9RYQQsGWIJwD6YS1+XAa9IAzj+PKnRwLru4ZxmgL4IfAvEvJTZkHNUjN UBYCIGRczHZ3lauQO9UGPw7cpBcr6agQ2L5XNOeXfCLVflsEfJu4QkiikY7ZDKHhfuVl D4bYQDVBOKgbhuPZmsuVJ/vcV83GAT32udlVwfacNLyOkbKxyNac3PTgUtALkE5298sl LnsQ== X-Forwarded-Encrypted: i=1; AJvYcCWMexrJvwTok41JvB8uHGsCzKSYiE1GFEQsLlGzqr488U2y6JfUEFhsaNtMjrXIRdemHKlRpnJJgG/wSKFYm2evfiG19LBN21F4jg== X-Gm-Message-State: AOJu0YymQLSayacyXy5LNSJUo1QgpVHcawH3TwXIzeR1AZs/G+87Ngai FHnAK1Hawf2t80snruz1EWuSf50yGcApaHHaTInzjCVuQ6tLBXinqD8RDZzvReA5oUgFZ1BkjjJ JJqybOxI6q00SFm7AcHwcu98WhT9NjT85hsi6zTUJMIQn76dsBKwNtXama2s= X-Received: by 2002:adf:eb03:0:b0:343:6cf9:9e38 with SMTP id s3-20020adfeb03000000b003436cf99e38mr1355929wrn.20.1712919361161; Fri, 12 Apr 2024 03:56:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDmyMGD2mpXH2d0bMC2al3vcgZvFqEyf0PMwI1016Zp1dGR2B3Yiqe3+Z9xhWNwSI4ZFt2rQ== X-Received: by 2002:adf:eb03:0:b0:343:6cf9:9e38 with SMTP id s3-20020adfeb03000000b003436cf99e38mr1355915wrn.20.1712919360527; Fri, 12 Apr 2024 03:56:00 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id q3-20020adff943000000b00346cc85c821sm3286458wrr.89.2024.04.12.03.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 03:56:00 -0700 (PDT) From: Andrew Burgess To: Bernd Edlinger , "gdb-patches@sourceware.org" Subject: Re: [PATCH] sim: riscv: Fix newlib issue with brk syscall In-Reply-To: References: Date: Fri, 12 Apr 2024 11:55:59 +0100 Message-ID: <878r1i6e9s.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Bernd Edlinger writes: > There is an issue with riscv newlib which uses > a brk syscall when malloc is used, and when > this syscall is not implemented, the malloc fails. > This adds a simple handling for this syscall > in order to make newlib happy. > --- > sim/riscv/sim-main.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c > index 9c0d070aa60..4e3672505c6 100644 > --- a/sim/riscv/sim-main.c > +++ b/sim/riscv/sim-main.c > @@ -30,6 +30,7 @@ > #include "sim-main.h" > #include "sim-signal.h" > #include "sim-syscall.h" > +#include "target-newlib-syscall.h" > > #include "opcode/riscv.h" > > @@ -629,6 +630,14 @@ execute_i (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op) > break; > case MATCH_ECALL: > TRACE_INSN (cpu, "ecall;"); > + if (riscv_cpu->a7 == TARGET_NEWLIB_RISCV_SYS_brk) > + { > + TRACE_SYSCALL (cpu, "brk[%i](%#lx)", TARGET_NEWLIB_RISCV_SYS_brk, > + (long)riscv_cpu->a0); > + if (riscv_cpu->a0 == 0) > + riscv_cpu->a0 = DEFAULT_MEM_SIZE / 2; > + break; > + } This doesn't seem like the right solution. I would have expected some changes in sim/common/syscall.c in the function cb_syscall. This would mean that the syscall would be handled via the sim_syscall call below. Thanks, Andrew > riscv_cpu->a0 = sim_syscall (cpu, riscv_cpu->a7, riscv_cpu->a0, > riscv_cpu->a1, riscv_cpu->a2, riscv_cpu->a3); > break; > -- > 2.25.1