From patchwork Tue May 19 02:53:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186908 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp3447038ilb; Mon, 18 May 2020 19:55:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyObnCOCCb6be6B8eC108lqnb6ab3tGxPd1gaUzvApJSkL5cY/EED+bfq/KkjGSLHuDPSuv X-Received: by 2002:a0c:f153:: with SMTP id y19mr18386849qvl.22.1589856953548; Mon, 18 May 2020 19:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589856953; cv=none; d=google.com; s=arc-20160816; b=X7X2M6Scy7F4jkB/02EmP+7rgmbzCuuhwtP5FpjUOb/quI23aa1ZZGqbbvMMHjGUF8 7kqVf9apOFsYEl1j6p5QcmVttEpd7oKistQ4BIAkzvuWCx0oS/gaAkUKnOLpPpjj/2la 4qj6PWx/J/QOLo3JwZaq+JqXrcJnKqg7vvfAUApwAUH0wrgtaPcnCagF7Gd14uzYRf0V wtsvpn4c8YEvHZI/JGfRJ0yI5UtMafjroFAuQWfuuOZGElN1Sqk+DzXlSAl9rIpf0RjB k1A+doHdgcQ2pWoNUCVzrBT71vxITPzYlMJ8xUemURJUyOKK4o+994MPAcr7yXUh7hoW Czgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=gp7XyqY5TSPLzgj7BvWTrIZcix0W6XLqOIrqT5GCvsY=; b=LPVSdPWeo2ITJ5Bpn4udmq+4vL8me92OiBtjG802rd2xQx0J7JafIaWuz0HFJuaQG9 ZxA0MQlbBpBLPNJS6HyDWKSXLHF/HEQMvtvp2KgupdMJFIZNGtEEUaQT1QQbjqXR5q8l 6BHZrA7hFoiH3PaPMJoFNZj27uuJJDI5TOkrZgfPD2ImiW20I/LW7hA1rYH3TKLPhCks AXb+QaN7rnnyDQkV6f7T9euGYrwVL5NRRLyPvz1ew7nUDWGomxGn+Dl+IJ4wk1YdVLfM DjOoptTOFKdMmjOnDMQO8MVwJdJsOlrUSs8riIpzjx/KhgCJK9UhdLm3DUYTabiomx/w mUsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HyIXsoxA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e19si8446565qtw.377.2020.05.18.19.55.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 May 2020 19:55:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HyIXsoxA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jasQ5-0000FJ-0U for patch@linaro.org; Mon, 18 May 2020 22:55:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jasOU-0005Oi-8x for qemu-devel@nongnu.org; Mon, 18 May 2020 22:54:14 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:38280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jasOS-0002QT-9l for qemu-devel@nongnu.org; Mon, 18 May 2020 22:54:13 -0400 Received: by mail-pl1-x633.google.com with SMTP id m7so5030170plt.5 for ; Mon, 18 May 2020 19:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gp7XyqY5TSPLzgj7BvWTrIZcix0W6XLqOIrqT5GCvsY=; b=HyIXsoxAP0wm0sYWYWZhjK6tlGuJOz37NebDzEA3e7y8poh5KhOnNV2xrvh0kT3h18 95+L7kkD6xE8XAtgUMsYO1zE+xE8f29S7/uz0iedk8wMRwzUezX9yu0grqj/5W8ke7Vu JRiEcu2/HltpqkWL2C8LJ8eVjsIs7ZBzyw+VdXx0XgvuHxmT5xpXj3AEkQSo0wFc1ke9 0VeCrAekKiVaOxE1ejGGp1SHlVql/GHlkNFQi+64w54oAFYXi4VWZ7gOeF9cvZ8R75nU 9iimmt8JOeqXAIZytaj1QDbrhZOm66BK4+h5NkcK64+/x/+ilSWfK7wq+9+QYN4f+laF NIXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gp7XyqY5TSPLzgj7BvWTrIZcix0W6XLqOIrqT5GCvsY=; b=ofLZDHTzZqONKtocMSSSlmfXjwANL3LCtd0E93Nz5zLutLhTxWDvpSqIokmsiHiGsp RXbW/K00vzBEZ4KOKAXNhIsY7SJ3XLv0knI6tEdjF8WJzNMBZTVIAip3lLn/FDSZK9Dm D+g9gE8efSgOysOCtfJhN1ivi3sYjdgwbD8lkBc5co1I6vxARtcMma/n9ftqTPPrcOdi +b4l2e1V3PkJTv0a8TK3o6Kr6KVInNspfqSi71cT9lytNfdhuBgKcPkW+gkL3xUpdxTF CVIQcks7JxX+QBtpq5Suq9U9eP7/gOusJ+MKOWR2YNIope0TmlbxlrU/w2ZDyf0I8+c/ t6DQ== X-Gm-Message-State: AOAM532Ir89+OrbWzslATEGGiylfp+qhO9AYdnFaOpyafH4ef2YElOAM CelGMeoyZZbwmPpYYQJ0mJ5yOnWIWWM= X-Received: by 2002:a17:90a:ee91:: with SMTP id i17mr2400729pjz.45.1589856847730; Mon, 18 May 2020 19:54:07 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id a2sm8772418pgh.57.2020.05.18.19.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 19:54:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [RISU v2 08/17] Add enum RisuResult Date: Mon, 18 May 2020 19:53:46 -0700 Message-Id: <20200519025355.4420-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200519025355.4420-1-richard.henderson@linaro.org> References: <20200519025355.4420-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Formalize the random set of numbers into an enum. Doing this makes it easy to see that one of the responses in recv_and_compare_register_info was inconsistent. Signed-off-by: Richard Henderson --- risu.h | 25 +++++++++++++++++-------- reginfo.c | 32 ++++++++++++++++---------------- risu.c | 18 +++++++++--------- 3 files changed, 42 insertions(+), 33 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/risu.h b/risu.h index a7aa929..e6d07eb 100644 --- a/risu.h +++ b/risu.h @@ -57,6 +57,14 @@ typedef enum { OP_COMPAREMEM = 4, } RisuOp; +/* Result of operation */ +typedef enum { + RES_OK = 0, + RES_END, + RES_MISMATCH, + RES_BAD_IO, +} RisuResult; + /* The memory block should be this long */ #define MEMBLOCKLEN 8192 @@ -82,20 +90,21 @@ typedef struct { */ typedef int (*write_fn) (void *ptr, size_t bytes); typedef int (*read_fn) (void *ptr, size_t bytes); -typedef void (*respond_fn) (int response); +typedef void (*respond_fn) (RisuResult response); -/* Send the register information from the struct ucontext down the socket. - * Return the response code from the master. +/* + * Send the register information from the struct ucontext down the socket. * NB: called from a signal handler. */ -int send_register_info(write_fn write_fn, void *uc); +RisuResult send_register_info(write_fn write_fn, void *uc); -/* Read register info from the socket and compare it with that from the - * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. +/* + * Read register info from the socket and compare it with that from the + * ucontext. * NB: called from a signal handler. */ -int recv_and_compare_register_info(read_fn read_fn, - respond_fn respond, void *uc); +RisuResult recv_and_compare_register_info(read_fn read_fn, + respond_fn respond, void *uc); /* Print a useful report on the status of the last comparison * done in recv_and_compare_register_info(). This is called on diff --git a/reginfo.c b/reginfo.c index 2d67c93..b909a1f 100644 --- a/reginfo.c +++ b/reginfo.c @@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN]; static int mem_used; static int packet_mismatch; -int send_register_info(write_fn write_fn, void *uc) +RisuResult send_register_info(write_fn write_fn, void *uc) { struct reginfo ri; trace_header_t header; @@ -34,7 +34,7 @@ int send_register_info(write_fn write_fn, void *uc) header.pc = get_pc(&ri); header.risu_op = op; if (write_fn(&header, sizeof(header)) != 0) { - return -1; + return RES_BAD_IO; } switch (op) { @@ -46,10 +46,10 @@ int send_register_info(write_fn write_fn, void *uc) * (b) end of test (c) a non-risuop UNDEF */ if (write_fn(&ri, reginfo_size()) != 0) { - return -1; + return RES_BAD_IO; } /* For OP_TEST_END, force return 1 to exit. */ - return op == OP_TESTEND; + return op == OP_TESTEND ? RES_END : RES_OK; case OP_SETMEMBLOCK: memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri); break; @@ -63,7 +63,7 @@ int send_register_info(write_fn write_fn, void *uc) default: abort(); } - return 0; + return RES_OK; } /* Read register info from the socket and compare it with that from the @@ -74,10 +74,10 @@ int send_register_info(write_fn write_fn, void *uc) * that says whether it is register or memory data, so if the two * sides get out of sync then we will fail obscurely. */ -int recv_and_compare_register_info(read_fn read_fn, - respond_fn resp_fn, void *uc) +RisuResult recv_and_compare_register_info(read_fn read_fn, + respond_fn resp_fn, void *uc) { - int resp = 0; + RisuResult resp = RES_OK; trace_header_t header; RisuOp op; @@ -85,18 +85,18 @@ int recv_and_compare_register_info(read_fn read_fn, op = get_risuop(&master_ri); if (read_fn(&header, sizeof(header)) != 0) { - return -1; + return RES_BAD_IO; } if (header.risu_op != op) { /* We are out of sync */ - resp = 2; + resp = RES_BAD_IO; resp_fn(resp); return resp; } /* send OK for the header */ - resp_fn(0); + resp_fn(RES_OK); switch (op) { case OP_COMPARE: @@ -107,12 +107,12 @@ int recv_and_compare_register_info(read_fn read_fn, */ if (read_fn(&apprentice_ri, reginfo_size())) { packet_mismatch = 1; - resp = 2; + resp = RES_BAD_IO; } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { /* register mismatch */ - resp = 2; + resp = RES_MISMATCH; } else if (op == OP_TESTEND) { - resp = 1; + resp = RES_END; } resp_fn(resp); break; @@ -127,10 +127,10 @@ int recv_and_compare_register_info(read_fn read_fn, mem_used = 1; if (read_fn(apprentice_memblock, MEMBLOCKLEN)) { packet_mismatch = 1; - resp = 2; + resp = RES_BAD_IO; } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) { /* memory mismatch */ - resp = 2; + resp = RES_MISMATCH; } resp_fn(resp); break; diff --git a/risu.c b/risu.c index 24ada8f..8796975 100644 --- a/risu.c +++ b/risu.c @@ -69,7 +69,7 @@ int write_trace(void *ptr, size_t bytes) return (res == bytes) ? 0 : 1; } -void respond_sock(int r) +void respond_sock(RisuResult r) { send_response_byte(comm_fd, r); } @@ -98,11 +98,11 @@ int read_trace(void *ptr, size_t bytes) return (res == bytes) ? 0 : 1; } -void respond_trace(int r) +void respond_trace(RisuResult r) { switch (r) { - case 0: /* test ok */ - case 1: /* end of test */ + case RES_OK: + case RES_END: break; default: /* mismatch - if tracing we need to report, otherwise barf */ @@ -115,7 +115,7 @@ void respond_trace(int r) static void master_sigill(int sig, siginfo_t *si, void *uc) { - int r; + RisuResult r; signal_count++; if (trace) { @@ -125,7 +125,7 @@ static void master_sigill(int sig, siginfo_t *si, void *uc) } switch (r) { - case 0: + case RES_OK: /* match OK */ advance_pc(uc); return; @@ -137,7 +137,7 @@ static void master_sigill(int sig, siginfo_t *si, void *uc) static void apprentice_sigill(int sig, siginfo_t *si, void *uc) { - int r; + RisuResult r; signal_count++; if (trace) { @@ -147,11 +147,11 @@ static void apprentice_sigill(int sig, siginfo_t *si, void *uc) } switch (r) { - case 0: + case RES_OK: /* match OK */ advance_pc(uc); return; - case 1: + case RES_END: /* end of test */ exit(EXIT_SUCCESS); default: