From patchwork Wed Jun 21 15:42:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 106101 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1995127qgd; Wed, 21 Jun 2017 08:44:12 -0700 (PDT) X-Received: by 10.55.188.71 with SMTP id m68mr40509755qkf.169.1498059852500; Wed, 21 Jun 2017 08:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498059852; cv=none; d=google.com; s=arc-20160816; b=GnzUaYZdaqYk9VButk+jzpr6Mb+xpKH6TdwAAIs4acv3zE4lCIiJcQ0Rx/ooU8Q1HX hp4bl+tmz+er+zQW49O4el7P9Z+0htqeMsi9QIWh8ntt1qZUUJCFFZo3tFNa8L+qQvzw mc8foUmTK7DQ0mwN88nWxfrSrRADeKzrBDaiAIMFSuqmTycHEetJOvlXbiyS3GbMZkcw Loz+2plo8Ff7BLDCsoWZmR5nWMNoY7/5pW/yPKtdsgbsSaLHhVvIAw4Db6i5+rsvL0Sz 9xWZT+KlQV3LPKaviDkG8061W/64zYleoBo+0IGVPMaV9ntN/ewupeZtrQtUULTepGGg Wjsw== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=vwqteoGYppvNNxVT4gzgCtsJQIQqedXw7/a0zMX+Ps0=; b=IIfVnCr7d9VnN9L6sQ60zAv9z5raW4R/QycV/YcDNDj2jp/kGuZ4DpIiFITLi7hcAy xOraHwtNYjvpBsS73t0+3maQ1oB2a/JoRV14wkeTyRoO5oB++1E9m0J6KGx8dV0shceI hG4wI97Kb7+1eC76AsnQquvL42zFZNJAm+kA1Fw9QFf3OSiMVS4Yk3TF9WI5zwjb4rIF w3rX6b4UM3KoDZOAYLsHMgSfes+Rk3oqhiqxp8jp4P7GiQVAmnn9eYSNb8bCHGveEgIm QdR9APvxwqSKXs9RR4lv50XxEuuuLiNdLqDIL/L34ClECDwWfcc6lhFH2932Fsz/pedV eW7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=gTn8Vnvo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d200si15431142qke.245.2017.06.21.08.44.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Jun 2017 08:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.b=gTn8Vnvo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhnd-0007QQ-Rf for patch@linaro.org; Wed, 21 Jun 2017 11:44:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhlm-0006D3-PW for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNhlk-0002qD-HC for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:14 -0400 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]:33521) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNhlk-0002ps-7N for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:12 -0400 Received: by mail-wr0-x229.google.com with SMTP id r103so140131701wrb.0 for ; Wed, 21 Jun 2017 08:42:12 -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=vwqteoGYppvNNxVT4gzgCtsJQIQqedXw7/a0zMX+Ps0=; b=gTn8VnvoeebySomZANUYl5YtVzYCCbWgldMrLwXSnl2jRrEFY3xOQ5ajSQAttRLcbZ fYNv87FfDuaulNJz2Dlnqf/JDRwSVKqzLOQZrpSzDfFVqEC0tDKpniguPMSx2Cfd2qbw H1P1IhtT3ARfwwZs366or0hub8xdZVtGJqsFI= 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=vwqteoGYppvNNxVT4gzgCtsJQIQqedXw7/a0zMX+Ps0=; b=I9AAV9n6nb0y89cOkF0S1b1LtGr8AZo8Kn50DGcyu2e38gGjiRQgn5V7Yb2UMYIedh o6okx+nF7Tv/DvJz3uNfh1pJ+k/hxuyEUY0UQvTGtBt/B5C01oP8npg/O++/tu0z/DYi q9m76W8azeNMSB5m0ocAv/V6Bdl9sJx4pwK3phGAPu85Z9YCw7d4yUB2TPqoc0sP/Wty HjfGi3IuZluDSLYPo8xJe9HGqVnSmdDkO3CSPO7GemepbgL4mmj6vfLaodJd6a/Ngob1 u7NprGQy7kFrOHJHyIzwvzQZXwTex7IaHf0g06X+sZbcx3ut/T5/xTqthnGFGDHQDsve HogQ== X-Gm-Message-State: AKS2vOw2CBJ8b9AMdc47ocR0zX/dG02Vtv7Ev8rQOk7XzbbJK++BRGxb M3DwaHdyxQrw7DOu X-Received: by 10.28.214.148 with SMTP id n142mr7099586wmg.35.1498059731026; Wed, 21 Jun 2017 08:42:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z101sm13019864wrb.41.2017.06.21.08.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 08:42:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 536F73E0F74; Wed, 21 Jun 2017 16:42:51 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 21 Jun 2017 16:42:38 +0100 Message-Id: <20170621154244.28309-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170621154244.28309-1-alex.bennee@linaro.org> References: <20170621154244.28309-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::229 Subject: [Qemu-devel] [RISU PATCH v6 04/10] risu: paramterise send/receive functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function. Signed-off-by: Alex Bennée --- v6 - restore OP_TESTEND to return write_fn() - clean up wording on helper function prototypes v5 - re-base without tab/format cleanps v4 - split header code - fix formatting foo-bar's v3 - new for v3 - arm, aarch64, ppc64 --- reginfo.c | 38 ++++++++++++++++++-------------------- risu.c | 23 +++++++++++++++++++++-- risu.h | 14 ++++++++++++-- 3 files changed, 51 insertions(+), 24 deletions(-) -- 2.13.0 diff --git a/reginfo.c b/reginfo.c index 31bb99f..b69d11f 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(int sock, void *uc) +int send_register_info(write_fn write_fn, void *uc) { struct reginfo ri; int op; @@ -29,24 +29,24 @@ int send_register_info(int sock, void *uc) op = get_risuop(&ri); switch (op) { - case OP_COMPARE: case OP_TESTEND: - default: - /* Do a simple register compare on (a) explicit request - * (b) end of test (c) a non-risuop UNDEF - */ - return send_data_pkt(sock, &ri, sizeof(ri)); + return write_fn(&ri, sizeof(ri)); case OP_SETMEMBLOCK: - memblock = (void *) (uintptr_t) get_reginfo_paramreg(&ri); + memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri); break; case OP_GETMEMBLOCK: set_ucontext_paramreg(uc, - get_reginfo_paramreg(&ri) + - (uintptr_t) memblock); + get_reginfo_paramreg(&ri) + (uintptr_t)memblock); break; case OP_COMPAREMEM: - return send_data_pkt(sock, memblock, MEMBLOCKLEN); + return write_fn(memblock, MEMBLOCKLEN); break; + case OP_COMPARE: + default: + /* Do a simple register compare on (a) explicit request + * (b) end of test (c) a non-risuop UNDEF + */ + return write_fn(&ri, sizeof(ri)); } return 0; } @@ -59,7 +59,7 @@ int send_register_info(int sock, 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(int sock, void *uc) +int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc) { int resp = 0, op; @@ -73,36 +73,34 @@ int recv_and_compare_register_info(int sock, void *uc) /* Do a simple register compare on (a) explicit request * (b) end of test (c) a non-risuop UNDEF */ - if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) { + if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) { packet_mismatch = 1; resp = 2; - } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { /* register mismatch */ resp = 2; - } else if (op == OP_TESTEND) { resp = 1; } - send_response_byte(sock, resp); + resp_fn(resp); break; case OP_SETMEMBLOCK: - memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri); + memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri); break; case OP_GETMEMBLOCK: set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) + - (uintptr_t) memblock); + (uintptr_t)memblock); break; case OP_COMPAREMEM: mem_used = 1; - if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) { + if (read_fn(apprentice_memblock, MEMBLOCKLEN)) { packet_mismatch = 1; resp = 2; } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) { /* memory mismatch */ resp = 2; } - send_response_byte(sock, resp); + resp_fn(resp); break; } diff --git a/risu.c b/risu.c index a10422a..88e586c 100644 --- a/risu.c +++ b/risu.c @@ -37,9 +37,28 @@ sigjmp_buf jmpbuf; /* Should we test for FP exception status bits? */ int test_fp_exc; +/* Master functions */ + +int read_sock(void *ptr, size_t bytes) +{ + return recv_data_pkt(master_socket, ptr, bytes); +} + +void respond_sock(int r) +{ + send_response_byte(master_socket, r); +} + +/* Apprentice function */ + +int write_sock(void *ptr, size_t bytes) +{ + return send_data_pkt(apprentice_socket, ptr, bytes); +} + void master_sigill(int sig, siginfo_t *si, void *uc) { - switch (recv_and_compare_register_info(master_socket, uc)) { + switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) { case 0: /* match OK */ advance_pc(uc); @@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc) void apprentice_sigill(int sig, siginfo_t *si, void *uc) { - switch (send_register_info(apprentice_socket, uc)) { + switch (send_register_info(write_sock, uc)) { case 0: /* match OK */ advance_pc(uc); diff --git a/risu.h b/risu.h index 3fbeda8..20bb824 100644 --- a/risu.h +++ b/risu.h @@ -52,17 +52,27 @@ struct reginfo; /* Functions operating on reginfo */ +/* Function prototypes for read/write helper functions. + * + * We pass the helper function to send_register_info and + * recv_and_compare_register_info which can either be backed by the + * traditional network socket or a trace file. + */ +typedef int (*write_fn) (void *ptr, size_t bytes); +typedef int (*read_fn) (void *ptr, size_t bytes); +typedef void (*respond_fn) (int response); + /* Send the register information from the struct ucontext down the socket. * Return the response code from the master. * NB: called from a signal handler. */ -int send_register_info(int sock, void *uc); +int 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. * NB: called from a signal handler. */ -int recv_and_compare_register_info(int sock, void *uc); +int 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