From patchwork Wed Dec 12 23:41:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30657 Received: (qmail 86168 invoked by alias); 12 Dec 2018 23:41:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 86147 invoked by uid 89); 12 Dec 2018 23:41:44 -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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=201802, scattered, 976, figured X-HELO: mail-wm1-f67.google.com Received: from mail-wm1-f67.google.com (HELO mail-wm1-f67.google.com) (209.85.128.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Dec 2018 23:41:42 +0000 Received: by mail-wm1-f67.google.com with SMTP id a18so567697wmj.1 for ; Wed, 12 Dec 2018 15:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=KDEZ6nJeJOQ+gxIvXIzFkgypEL4doX/Zd1zJimUNOGc=; b=Z8sjRlqarfzAYvowuippS3gbLKn96Tv3MfhAzdH33K+cW2iUQtOzpCWUQmrBes6ZOi 9V50NJkWKLusum8CMoxQhOfVaKcJGS7ukme30+s4PeS44Op4qDojn3opWSWjKtxGq7lI uLw95DayCdKjjtaMzeK0/paIG9IOySPQde1gWE763r05gtWna+G7TuXXd9hyN5zGstpT IEFvj4dIdwGVTH3I4FvFa+fl6sbmiYF09qfx6a5G6bwTUfF/3FG1C3SEew0eP3qRF3fy koaHLle2TJtEqOLst0pzE1lfbgq3UvanKpWBoS9kqKwukqMUhU05XBgje+QEs6IJQOi+ Gceg== Return-Path: Received: from localhost ([2a00:23c5:3e8d:6c00:9cd0:87cb:29bd:5b8f]) by smtp.gmail.com with ESMTPSA id c13sm185971wrb.38.2018.12.12.15.41.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Dec 2018 15:41:38 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: vapier@gentoo.org, Andrew Burgess Subject: [PATCHv2] sim: Don't overwrite stored errno in sim_syscall_multi Date: Wed, 12 Dec 2018 23:41:34 +0000 Message-Id: <20181212234134.4049-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes I originally posted this patch back in February and figured it might be worth giving it a refresh. Here's the original submission, it hasn't changed: https://sourceware.org/ml/gdb-patches/2018-02/msg00062.html The sim/ maintainer has been rather absent of late, so I'm hoping someone else might approve this. I've been using this patch with an out-of-tree RISC-V simulator for over a year now without any problems. Thanks, Andrew --- The host syscall callback mechanism should take care of updating the errcode within the CB_SYSCALL struct, and we should not be adjusting the error code once the syscall has completed. We especially, should not be rewriting the syscall errcode based on the value of errno some time after running the host syscall, as there is no guarantee that errno has not be overwritten. To perform a syscall we call cb_syscall (in syscall.c). To return from cb_syscall control passes through one of two exit paths these are labeled FinishSyscall and ErrorFinish and are reached using goto statements scattered throughout the cb_syscall function. In FinishSyscall we store the syscall result in 'sc->result', and the error code is transated to target encoding, and stored in 'sc->errcode'. In ErrorFinish, we again store the syscall result in 'sc->result', and fill in 'sc->errcode' by fetching the actual errno from the host with the 'cb->get_errno' callback. In both cases 'sc->errcode' will have been filled in with an appropriate value. Further, if we look at a specific syscall example, CB_SYS_open, in this case the first thing we do is fetch the path to open from the target with 'get_path', if this fails then the errcode is returned, and we jump to FinishSyscall. Notice that in this case, no host syscall may have been performed, for example a failure to read the path to open out of simulated memory can return EINVAL without performing any host syscall. Given that no host syscall has been performed, reading the host errno makes absolutely no sense. This commit removes from sim_syscall_multi the rewriting of sc->errcode based on the value of errno, and instead relies on the value stored in the cb_syscall. sim/common/ChangeLog: * sim-syscall.c (sim_syscall_multi): Don't update sc->errcode at this point, it should have already been set in cb_syscall. --- sim/common/ChangeLog | 5 +++++ sim/common/sim-syscall.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sim/common/sim-syscall.c b/sim/common/sim-syscall.c index 7923160cb7f..34d2f0ec115 100644 --- a/sim/common/sim-syscall.c +++ b/sim/common/sim-syscall.c @@ -97,11 +97,6 @@ sim_syscall_multi (SIM_CPU *cpu, int func, long arg1, long arg2, long arg3, if (cb_target_to_host_syscall (cb, func) == CB_SYS_exit) sim_engine_halt (sd, cpu, NULL, sim_pc_get (cpu), sim_exited, arg1); - else if (sc.result == -1) - { - cb->last_errno = errno; - sc.errcode = cb->get_errno (cb); - } *result = sc.result; *result2 = sc.result2;