From nobody Wed Jul 26 14:30:15 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R9xBb3Qgdz4ny89; Wed, 26 Jul 2023 14:30:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R9xBb2R6jz3MMc; Wed, 26 Jul 2023 14:30:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690381815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=56j098e2mnEJapdKa+k2Yz3zrP4NlMFl5tMJznMR6S8=; b=IwZUdnIHIoIOXCO2CxuxP/yBdwwrMym2DJ+4zhT/SjVgE4IPWf9iL70E5EnidesSYnm45Z L26F9gMN4eGHpJrO4I5gf1tv3qGg8p+OKDwfS6UqUurOJQcVaxu2tYJ7MNJ6mxddrbPsCS Itn++wig10mPp3WYqkgmG7Lb8gu5n2zH51DXscivo5EBLdDHyRrb36ecXPsXWX46IS11Mt D3b4cAw5X+Rp6BVCL82AcwY7PE1waDB694ERp6KR0AGx6eOWAVzl/1iB033ZTlCVPTh/kT Wb4OgY1VmLz2iS4xCh4Lb7ECySFVDBA7jJa+oPb0ZFa56PIbEVujtwAMrDwx8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690381815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=56j098e2mnEJapdKa+k2Yz3zrP4NlMFl5tMJznMR6S8=; b=HjQBMpgPyGdZF/9rKkBs/yhs1KXSv0GTTRl6taFjEfj1kQ/Z1Wtsd/ge4PJsM/6FuGWenh 1IGMN7Md6Nh+U03UoNFlkwFv2Yi0pQAS5qSVK3HoBngTABT3VJ4UA0WD94fFnubo2KUrcX snHQOxDpVirAPZ0iZ2rkfhXUFUTXeSXdKTVHtiIM0UXjQRaaHBLlDf/gjZa2CKxyst2Ks0 oDyqINPK/l914zkaB9vrzdBgSkqIsM9ll0WZaApN2v+u9srh7Yb1KAwOifvwp1LGT0RC93 3LanvEf/yj+KAxjpF/zIAA7V/8aywS33VKv4VMyp+Q2e7CxMWonwazkQGdgWxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1690381815; a=rsa-sha256; cv=none; b=J+XBgceU3LFTwKyhpD6tPfAIzM8yo0Z7wbd+0FA1Aza/mYL3Tp/sXYlguaYdQaD7ID812Y h/i0nJDSKxMJdchieQf3cbdmFDmr61Sjhrl8vbrjTUkQgWxCIFCH5UfhfvpYcR58hKEBeg ZaYTRefJKgFgi47Vjesm3rqtgpv+ecLYniko8QHfuN6/qw6ULeranaflBhvnD5CmZmgFMJ ziFLQ5zGFl2idbwyu6g5/2Gu1sywCrRnse9ywFWGGiv673V0F5q2I5emLPcm/y6c9KjWIZ kbD5R2dsX8pOh9aBzD2OqYnMpojkS8GgBZUUXKtjwVvgl2ZWB+9yCD5lN3Hqgg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R9xBb1KkDzm6B; Wed, 26 Jul 2023 14:30:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36QEUFIk028435; Wed, 26 Jul 2023 14:30:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36QEUFuV028432; Wed, 26 Jul 2023 14:30:15 GMT (envelope-from git) Date: Wed, 26 Jul 2023 14:30:15 GMT Message-Id: <202307261430.36QEUFuV028432@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 86c7368f2bce - main - rtld_malloc: add cp2op() helper List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 86c7368f2bcefeb257f7dc40e4296261b295a674 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=86c7368f2bcefeb257f7dc40e4296261b295a674 commit 86c7368f2bcefeb257f7dc40e4296261b295a674 Author: Konstantin Belousov AuthorDate: 2023-07-22 04:24:03 +0000 Commit: Konstantin Belousov CommitDate: 2023-07-26 14:24:18 +0000 rtld_malloc: add cp2op() helper converting user allocation address into overhead pointer Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41150 --- libexec/rtld-elf/rtld_malloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libexec/rtld-elf/rtld_malloc.c b/libexec/rtld-elf/rtld_malloc.c index 45d3f743e348..3437f638d339 100644 --- a/libexec/rtld-elf/rtld_malloc.c +++ b/libexec/rtld-elf/rtld_malloc.c @@ -106,6 +106,12 @@ static int pagesz; /* page size */ * increasing order. */ +static union overhead * +cp2op(void *cp) +{ + return ((union overhead *)((caddr_t)cp - sizeof(union overhead))); +} + void * __crt_malloc(size_t nbytes) { @@ -209,7 +215,7 @@ __crt_free(void *cp) if (cp == NULL) return; - op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); + op = cp2op(cp); if (op->ov_magic != MAGIC) return; /* sanity */ size = op->ov_index; @@ -227,7 +233,7 @@ __crt_realloc(void *cp, size_t nbytes) if (cp == NULL) return (__crt_malloc(nbytes)); - op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); + op = cp2op(cp); if (op->ov_magic != MAGIC) return (NULL); /* Double-free or bad argument */ i = op->ov_index;