From patchwork Sun Oct 7 18:05:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 148336 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2779741lji; Sun, 7 Oct 2018 11:05:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV61ETlaLdtU43PGPlsgCfJZ1iuUAxsM+uACRrPn928dSoxnQk4960stSBmkotnzyoD4yWcz6 X-Received: by 2002:ae9:f10c:: with SMTP id k12-v6mr15691109qkg.114.1538935548184; Sun, 07 Oct 2018 11:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538935548; cv=none; d=google.com; s=arc-20160816; b=WrNhEuhDfZ5FFVf+e41p3SUmozxSZImOANOjhgWvpfjppknr0paqdVhBDwypOxsuPa 2ooXNqD7/dAzuvoNbAbpynDrwQ+1Qf2hAZKWJQUFM82DV5Kb1IC/SqMyRgPu6n7ifAHc 98rQhwrKsNUnevmF9RG23SJqrbsoRC887gt4fDzWh0bk/fSGTTLyQ8NOVv/FNy6Pf9oS HvuXKf0RLUwWXgYMlz+cuo0tspBmMCtgSGYr+ayE2/ZfQW41VCllQZ+INL+HsXodmfWk Ky0KMdtDiG5o1WnZdMUB4IBKF3hBVHoovRuEiZsJZQa2whLtJs3GfZggNeHjg2fEg3ZI iGLA== 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; bh=YvNx31Q/Gv5cYFF/BotdGlvFcBKhrwYlAThsAyzOpUc=; b=i+icQqv3S2w2oDa0IbpjMFk6bR+hXm0OmIJZ4if+RbVx57ey2CqF6TxGhddJOSC96Z gC8VOL/M52wxZErWY8F1+NWXktDhDI8TX5Jj5j3gsjH2i1DqhFBlrtgzPoGsNhbWeAU+ bVKGoeryv8l86Ao+gRWMIfOezBper5FN6oYgMLVINDyrXVKTZJMVpisWsYT9KaP+dSCC 9nIBkDhnFQv38uz8ne3mLXlT093Sum/sceh6ETGv4yLi2bFJups7PMKLV+j43OeG72uQ 0FG3yhgIQQ/lN2xpGT1By981C/5eVyj14eveNyWjqtTSg+aDZsDl/rDR4R/e/VcsAKo1 B16Q== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p86-v6si3675086qkl.335.2018.10.07.11.05.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 07 Oct 2018 11:05:48 -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; 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" Received: from localhost ([::1]:43135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DR5-0008VM-MO for patch@linaro.org; Sun, 07 Oct 2018 14:05:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DQn-0008VG-MN for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9DQk-000116-OW for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:29 -0400 Received: from hera.aquilenet.fr ([2a0c:e300::1]:54630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9DQi-0000vJ-3U for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:24 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 54315297; Sun, 7 Oct 2018 20:05:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j5GJEnLToivr; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 3ECB34A4; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1g9DQc-0001Mq-BY; Sun, 07 Oct 2018 20:05:18 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 7 Oct 2018 20:05:16 +0200 Message-Id: <20181007180518.5212-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> References: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULL 1/3] slirp: document mbuf pointers and sizes 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: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell and fix confusing datasize name into gapsize in m_inc. Signed-off-by: Peter Maydell Signed-off-by: Samuel Thibault --- slirp/mbuf.c | 14 +++++++------- slirp/mbuf.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) -- 2.19.0 diff --git a/slirp/mbuf.c b/slirp/mbuf.c index 1b7868355a..aa1f28afb1 100644 --- a/slirp/mbuf.c +++ b/slirp/mbuf.c @@ -151,7 +151,7 @@ m_cat(struct mbuf *m, struct mbuf *n) void m_inc(struct mbuf *m, int size) { - int datasize; + int gapsize; /* some compilers throw up on gotos. This one we can fake. */ if (M_ROOM(m) > size) { @@ -159,17 +159,17 @@ m_inc(struct mbuf *m, int size) } if (m->m_flags & M_EXT) { - datasize = m->m_data - m->m_ext; - m->m_ext = g_realloc(m->m_ext, size + datasize); + gapsize = m->m_data - m->m_ext; + m->m_ext = g_realloc(m->m_ext, size + gapsize); } else { - datasize = m->m_data - m->m_dat; - m->m_ext = g_malloc(size + datasize); + gapsize = m->m_data - m->m_dat; + m->m_ext = g_malloc(size + gapsize); memcpy(m->m_ext, m->m_dat, m->m_size); m->m_flags |= M_EXT; } - m->m_data = m->m_ext + datasize; - m->m_size = size + datasize; + m->m_data = m->m_ext + gapsize; + m->m_size = size + gapsize; } diff --git a/slirp/mbuf.h b/slirp/mbuf.h index 33b84485d6..bfdf8c4577 100644 --- a/slirp/mbuf.h +++ b/slirp/mbuf.h @@ -47,6 +47,19 @@ * free the m_ext. This is inefficient memory-wise, but who cares. */ +/* + * mbufs allow to have a gap between the start of the allocated buffer (m_ext if + * M_EXT is set, m_dat otherwise) and the in-use data: + * + * |--gapsize----->|---m_len-------> + * |----------m_size------------------------------> + * |----M_ROOM--------------------> + * |-M_FREEROOM--> + * + * ^ ^ ^ + * m_dat/m_ext m_data end of buffer + */ + /* * How much room is in the mbuf, from m_data to the end of the mbuf */