From patchwork Tue Feb 28 11:28:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tankut Baris Aktemur X-Patchwork-Id: 65757 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7A6A383EC51 for ; Tue, 28 Feb 2023 11:32:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7A6A383EC51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677583946; bh=gIjob7XCXmkda0pa2BnCwm7LLSlpPuA3IoSZHsps8ZY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kWOpWuSDd0PFluPWZtFvVy6MQ+6fxjaabgYDY6Mw2dLpMrBTMYFTaJhRQ575Zm/tc LFnLBmvSfnmniBPm2RPtiPTD0lJWNLB9ss5RVycSf9P4CcnMlTjGiRHIqWejn4sEkP b1dRqEc3ZzBAQ9xs1HDufaAUZoTqXsA/Mk+9X8YI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by sourceware.org (Postfix) with ESMTPS id 26C96384B10F for ; Tue, 28 Feb 2023 11:31:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26C96384B10F X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="336401728" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="336401728" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:06 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="817058248" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="817058248" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:04 -0800 To: gdb-patches@sourceware.org Subject: [PATCH 22/26] gdbserver: zero-out register values in regcache-discard Date: Tue, 28 Feb 2023 12:28:20 +0100 Message-Id: <877c74ccb7fb99d36242d9246d2824f181752a5a.1677582745.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tankut Baris Aktemur via Gdb-patches From: Tankut Baris Aktemur Reply-To: Tankut Baris Aktemur Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Zero-out register values when a regcache is discarded so that we avoid garbage values left in the buffer. --- gdbserver/regcache.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 2befb30e337..644f436c681 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -136,6 +136,7 @@ regcache_invalidate (void) void regcache::discard () { + memset (registers, 0, tdesc->registers_size); #ifndef IN_PROCESS_AGENT memset ((void *) register_status, REG_UNKNOWN, tdesc->reg_defs.size ()); #endif @@ -149,16 +150,17 @@ regcache::initialize (const target_desc *tdesc, if (regbuf == NULL) { #ifndef IN_PROCESS_AGENT - /* Make sure to zero-initialize the register cache when it is - created, in case there are registers the target never - fetches. This way they'll read as zero instead of - garbage. */ this->tdesc = tdesc; this->registers - = (unsigned char *) xcalloc (1, tdesc->registers_size); + = (unsigned char *) xmalloc (tdesc->registers_size); this->registers_owned = true; this->register_status = (enum register_status *) xmalloc (tdesc->reg_defs.size ()); + + /* Make sure to zero-initialize the register cache when it is + created, in case there are registers the target never + fetches. This way they'll read as zero instead of + garbage. */ discard (); #else gdb_assert_not_reached ("can't allocate memory from the heap");