From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmiU4-0001Wl-DC for qemu-devel@nongnu.org; Tue, 20 May 2014 07:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmiTu-0001YM-6p for qemu-devel@nongnu.org; Tue, 20 May 2014 07:45:28 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:59240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmiTt-0001Xy-V9 for qemu-devel@nongnu.org; Tue, 20 May 2014 07:45:18 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 May 2014 12:45:17 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id D7FD32190061 for ; Tue, 20 May 2014 12:45:05 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s4KBjFJB66125898 for ; Tue, 20 May 2014 11:45:15 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s4KBjDx4000828 for ; Tue, 20 May 2014 05:45:14 -0600 From: Cornelia Huck Date: Tue, 20 May 2014 13:45:00 +0200 Message-Id: <1400586302-3253-8-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1400586302-3253-1-git-send-email-cornelia.huck@de.ibm.com> References: <1400586302-3253-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PULL 7/9] s390x: remove duplicate definitions of DIAG 501 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, borntraeger@de.ibm.com, agraf@suse.de, David Hildenbrand , Jens Freimann , aliguori@amazon.com, Cornelia Huck From: David Hildenbrand When restoring the previously saved instruction in kvm_arch_remove_sw_breakpoint(), we only restored one byte. Let's use the sizeof() operator to make sure we restore the entire instruction. While we are at it, let's remove the duplicate definitions of DIAG 501 and replace its size (used when reading/writing the instruction) with a sizeof() operator to make the code self explaining and less error-prone. Signed-off-by: David Hildenbrand Reviewed-by: Cornelia Huck Signed-off-by: Jens Freimann Signed-off-by: Cornelia Huck --- target-s390x/kvm.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index bb731a0..4d12f70 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -320,12 +320,16 @@ static void *legacy_s390_alloc(size_t size) return mem == MAP_FAILED ? NULL : mem; } +/* DIAG 501 is used for sw breakpoints */ +static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; + int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) { - static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; - if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || - cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)diag_501, 4, 1)) { + if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, + sizeof(diag_501), 0) || + cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)diag_501, + sizeof(diag_501), 1)) { return -EINVAL; } return 0; @@ -333,14 +337,14 @@ int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) { - uint8_t t[4]; - static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; + uint8_t t[sizeof(diag_501)]; - if (cpu_memory_rw_debug(cs, bp->pc, t, 4, 0)) { + if (cpu_memory_rw_debug(cs, bp->pc, t, sizeof(diag_501), 0)) { return -EINVAL; - } else if (memcmp(t, diag_501, 4)) { + } else if (memcmp(t, diag_501, sizeof(diag_501))) { return -EINVAL; - } else if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) { + } else if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, + sizeof(diag_501), 1)) { return -EINVAL; } -- 1.7.9.5