From nobody Mon Feb 9 21:36:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1713976570; cv=pass; d=zohomail.com; s=zohoarc; b=fb8uiiSS37t8bh6eFLZrGQ+/n+bhtLIXP3nb5o8/vkDLCNYS65EjDaOgap8bikq/YxiYt+yXgie6fXIcDWJFJ3pa7O1wtjCbOGQnzY37FSkaHw4M2+vtgjxSlYLtMdqePpUz87blXYRWy7cRplugCf1lUS+ajynKV+4EZdyV0hA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713976570; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GpHnI7vIWP3t83v9jzSRMXedCoJS9I7Zt1oRPss2CLE=; b=RDYjrdzaJc6kep0iqJ90MLaV5fjFwSyaulLoeTkBQLu/aHcyx7Mjp55XwmtTVu+FVU4FLjksTlgqHOerzbbpWyVf0FsoQm3708w8MDb3qDfN35eHXvyCL1J/wyVkLByGhnVunvsPvUs77vYoeX6nHnJoxgAvJdFEAZPrNjtoGBg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1713976570847864.9074101725568; Wed, 24 Apr 2024 09:36:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.711552.1111605 (Exim 4.92) (envelope-from ) id 1rzfbC-0005vU-FZ; Wed, 24 Apr 2024 16:35:58 +0000 Received: by outflank-mailman (output) from mailman id 711552.1111605; Wed, 24 Apr 2024 16:35:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzfbC-0005vJ-Bt; Wed, 24 Apr 2024 16:35:58 +0000 Received: by outflank-mailman (input) for mailman id 711552; Wed, 24 Apr 2024 16:35:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzfbB-0004Nw-2R for xen-devel@lists.xenproject.org; Wed, 24 Apr 2024 16:35:57 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b8426cb6-0258-11ef-909a-e314d9c70b13; Wed, 24 Apr 2024 18:35:56 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1713976478817631.4787800889635; Wed, 24 Apr 2024 09:34:38 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b8426cb6-0258-11ef-909a-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; t=1713976481; cv=none; d=zohomail.com; s=zohoarc; b=iy161XWEdMWeHGi5/d6N6NuNIP9cFCBte8hJoHPhdy4++8Hq3wEaaAlNwZytx7dfr+bBnufvJnm4iVw580R8Gr/FoY70a4Qckwf3xHyMCQ8+ozw2tZ+d9jRY/zl7sMXytr8Khjyz6lSt/kl7YDsvMOc8gltQFKwaPxFTHADaito= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713976481; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=GpHnI7vIWP3t83v9jzSRMXedCoJS9I7Zt1oRPss2CLE=; b=P1HgrRqD6eO8JbW79RTdYKeVG+KJTOMOBWD2RoJRemZAscaMIsITUCQNFUkALo1cESWYQk9DZ8GE44K+hgZfoaVruSggum7XBjDcIXl8+lHJJwjJNMOfYkOjO8aYtQVG0aTtJgpjvV443dDipZ0z7sAJZ77dJyQ7keM9HhypPig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1713976480; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=GpHnI7vIWP3t83v9jzSRMXedCoJS9I7Zt1oRPss2CLE=; b=mZyhqngeFPP2CXkxuNutxlvM/J0wKqNzZGIFoRKoj2DyOZFufBVqjgjwk5xfn+GM hHj1Q3yeSl5niQt6T4EFk2tgCx2qL6+GceT5VVHD2ZVycNjw1fa9NE9ApP7pPDqwOdk MfHgOScUb5ysjYQkN5qEnMPHVdQYRWdAbrC4LS8U= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , "Daniel P. Smith" , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 5/8] gzip: move input buffer handling into gunzip state Date: Wed, 24 Apr 2024 12:34:19 -0400 Message-Id: <20240424163422.23276-6-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240424163422.23276-1-dpsmith@apertussolutions.com> References: <20240424163422.23276-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1713976573057100001 Content-Type: text/plain; charset="utf-8" Move the input buffer handling, buffer pointer(inbuf), size(insize), and index(inptr), into gunzip state. Adjust functions and macros that consumed = the input buffer to accept a struct gunzip_state reference. Signed-off-by: Daniel P. Smith --- xen/common/gzip/gunzip.c | 23 +++++----- xen/common/gzip/inflate.c | 92 +++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/xen/common/gzip/gunzip.c b/xen/common/gzip/gunzip.c index 11bfe45d8222..3fb9589b069e 100644 --- a/xen/common/gzip/gunzip.c +++ b/xen/common/gzip/gunzip.c @@ -10,13 +10,12 @@ struct gunzip_state { unsigned char *window; /* window pointer: */ unsigned int wp; -}; - -static unsigned char *__initdata inbuf; -static unsigned int __initdata insize; =20 -/* Index of next byte to be processed in inbuf: */ -static unsigned int __initdata inptr; + unsigned char *inbuf; + size_t insize; + /* Index of next byte to be processed in inbuf: */ + unsigned int inptr; +}; =20 #define malloc(a) xmalloc_bytes(a) #define free(a) xfree(a) @@ -51,14 +50,14 @@ static __init void error(const char *x) panic("%s\n", x); } =20 -static __init uch get_byte(void) { - if ( inptr >=3D insize ) +static __init uch get_byte(struct gunzip_state *s) { + if ( s->inptr >=3D s->insize ) { error("ran out of input data"); return 0; /* should never reach */ } =20 - return inbuf[inptr++]; + return s->inbuf[s->inptr++]; } =20 #include "inflate.c" @@ -111,9 +110,9 @@ __init int perform_gunzip(char *output, char *image, un= signed long image_len) return -ENOMEM; =20 s->window =3D (unsigned char *)output; - inbuf =3D (unsigned char *)image; - insize =3D image_len; - inptr =3D 0; + s->inbuf =3D (unsigned char *)image; + s->insize =3D image_len; + s->inptr =3D 0; bytes_out =3D 0; =20 makecrc(); diff --git a/xen/common/gzip/inflate.c b/xen/common/gzip/inflate.c index 78b2f20a97ba..f1a3b04cef8f 100644 --- a/xen/common/gzip/inflate.c +++ b/xen/common/gzip/inflate.c @@ -220,8 +220,8 @@ static const ush mask_bits[] =3D { 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff }; =20 -#define NEXTBYTE() (get_byte()) /* get_byte will panic on failure */ -#define NEEDBITS(n) {while(k<(n)){b|=3D((ulg)NEXTBYTE())<>=3D(n);k-=3D(n);} =20 /* @@ -562,14 +562,14 @@ static int __init inflate_codes( md =3D mask_bits[bd]; for (;;) /* do until end of block */ { - NEEDBITS((unsigned)bl); + NEEDBITS(s, (unsigned)bl); if ((e =3D (t =3D tl + ((unsigned)b & ml))->e) > 16) do { if (e =3D=3D 99) return 1; DUMPBITS(t->b); e -=3D 16; - NEEDBITS(e); + NEEDBITS(s, e); } while ((e =3D (t =3D t->v.t + ((unsigned)b & mask_bits[e]))-= >e) > 16); DUMPBITS(t->b); if (e =3D=3D 16) /* then it's a literal */ @@ -590,22 +590,22 @@ static int __init inflate_codes( break; =20 /* get length of block to copy */ - NEEDBITS(e); + NEEDBITS(s, e); n =3D t->v.n + ((unsigned)b & mask_bits[e]); DUMPBITS(e); =20 /* decode distance of block to copy */ - NEEDBITS((unsigned)bd); + NEEDBITS(s, (unsigned)bd); if ((e =3D (t =3D td + ((unsigned)b & md))->e) > 16) do { if (e =3D=3D 99) return 1; DUMPBITS(t->b); e -=3D 16; - NEEDBITS(e); + NEEDBITS(s, e); } while ((e =3D (t =3D t->v.t + ((unsigned)b & mask_bits[e= ]))->e) > 16); DUMPBITS(t->b); - NEEDBITS(e); + NEEDBITS(s, e); d =3D w - t->v.n - ((unsigned)b & mask_bits[e]); DUMPBITS(e); Tracevv((stderr,"\\[%d,%d]", w-d, n)); @@ -665,10 +665,10 @@ static int __init inflate_stored(struct gunzip_state = *s) =20 =20 /* get the length and its complement */ - NEEDBITS(16); + NEEDBITS(s, 16); n =3D ((unsigned)b & 0xffff); DUMPBITS(16); - NEEDBITS(16); + NEEDBITS(s, 16); if (n !=3D (unsigned)((~b) & 0xffff)) return 1; /* error in compressed data */ DUMPBITS(16); @@ -676,7 +676,7 @@ static int __init inflate_stored(struct gunzip_state *s) /* read and output the compressed data */ while (n--) { - NEEDBITS(8); + NEEDBITS(s, 8); s->window[w++] =3D (uch)b; if (w =3D=3D WSIZE) { @@ -798,13 +798,13 @@ static int noinline __init inflate_dynamic(struct gun= zip_state *s) k =3D bk; =20 /* read in table lengths */ - NEEDBITS(5); + NEEDBITS(s, 5); nl =3D 257 + ((unsigned)b & 0x1f); /* number of literal/length co= des */ DUMPBITS(5); - NEEDBITS(5); + NEEDBITS(s, 5); nd =3D 1 + ((unsigned)b & 0x1f); /* number of distance codes */ DUMPBITS(5); - NEEDBITS(4); + NEEDBITS(s, 4); nb =3D 4 + ((unsigned)b & 0xf); /* number of bit length codes = */ DUMPBITS(4); if (nl > 286 || nd > 30) @@ -818,7 +818,7 @@ static int noinline __init inflate_dynamic(struct gunzi= p_state *s) /* read in bit-length-code lengths */ for (j =3D 0; j < nb; j++) { - NEEDBITS(3); + NEEDBITS(s, 3); ll[border[j]] =3D (unsigned)b & 7; DUMPBITS(3); } @@ -845,7 +845,7 @@ static int noinline __init inflate_dynamic(struct gunzi= p_state *s) i =3D l =3D 0; while ((unsigned)i < n) { - NEEDBITS((unsigned)bl); + NEEDBITS(s, (unsigned)bl); j =3D (td =3D tl + ((unsigned)b & m))->b; DUMPBITS(j); j =3D td->v.n; @@ -853,7 +853,7 @@ static int noinline __init inflate_dynamic(struct gunzi= p_state *s) ll[i++] =3D l =3D j; /* save last length in l */ else if (j =3D=3D 16) /* repeat last length 3 to 6 times= */ { - NEEDBITS(2); + NEEDBITS(s, 2); j =3D 3 + ((unsigned)b & 3); DUMPBITS(2); if ((unsigned)i + j > n) { @@ -865,7 +865,7 @@ static int noinline __init inflate_dynamic(struct gunzi= p_state *s) } else if (j =3D=3D 17) /* 3 to 10 zero length codes */ { - NEEDBITS(3); + NEEDBITS(s, 3); j =3D 3 + ((unsigned)b & 7); DUMPBITS(3); if ((unsigned)i + j > n) { @@ -878,7 +878,7 @@ static int noinline __init inflate_dynamic(struct gunzi= p_state *s) } else /* j =3D=3D 18: 11 to 138 zero length = codes */ { - NEEDBITS(7); + NEEDBITS(s, 7); j =3D 11 + ((unsigned)b & 0x7f); DUMPBITS(7); if ((unsigned)i + j > n) { @@ -969,12 +969,12 @@ static int __init inflate_block(struct gunzip_state *= s, int *e) k =3D bk; =20 /* read in last block bit */ - NEEDBITS(1); + NEEDBITS(s, 1); *e =3D (int)b & 1; DUMPBITS(1); =20 /* read in block type */ - NEEDBITS(2); + NEEDBITS(s, 2); t =3D (unsigned)b & 3; DUMPBITS(2); =20 @@ -1019,7 +1019,7 @@ static int __init inflate(struct gunzip_state *s) */ while (bk >=3D 8) { bk -=3D 8; - inptr--; + s->inptr--; } =20 /* flush out window */ @@ -1100,9 +1100,9 @@ static int __init gunzip(struct gunzip_state *s) ulg orig_len =3D 0; /* original uncompressed length */ int res; =20 - magic[0] =3D NEXTBYTE(); - magic[1] =3D NEXTBYTE(); - method =3D NEXTBYTE(); + magic[0] =3D NEXTBYTE(s); + magic[1] =3D NEXTBYTE(s); + method =3D NEXTBYTE(s); =20 if (magic[0] !=3D 037 || /* octal-ok */ ((magic[1] !=3D 0213) && (magic[1] !=3D 0236))) { /* octal-ok */ @@ -1116,7 +1116,7 @@ static int __init gunzip(struct gunzip_state *s) return -1; } =20 - flags =3D (uch)get_byte(); + flags =3D (uch)get_byte(s); if ((flags & ENCRYPTED) !=3D 0) { error("Input is encrypted"); return -1; @@ -1129,29 +1129,29 @@ static int __init gunzip(struct gunzip_state *s) error("Input has invalid flags"); return -1; } - NEXTBYTE(); /* Get timestamp */ - NEXTBYTE(); - NEXTBYTE(); - NEXTBYTE(); + NEXTBYTE(s); /* Get timestamp */ + NEXTBYTE(s); + NEXTBYTE(s); + NEXTBYTE(s); =20 - NEXTBYTE(); /* Ignore extra flags for the moment */ - NEXTBYTE(); /* Ignore OS type for the moment */ + NEXTBYTE(s); /* Ignore extra flags for the moment */ + NEXTBYTE(s); /* Ignore OS type for the moment */ =20 if ((flags & EXTRA_FIELD) !=3D 0) { - unsigned len =3D (unsigned)NEXTBYTE(); - len |=3D ((unsigned)NEXTBYTE())<<8; - while (len--) (void)NEXTBYTE(); + unsigned len =3D (unsigned)NEXTBYTE(s); + len |=3D ((unsigned)NEXTBYTE(s))<<8; + while (len--) (void)NEXTBYTE(s); } =20 /* Get original file name if it was truncated */ if ((flags & ORIG_NAME) !=3D 0) { /* Discard the old name */ - while (NEXTBYTE() !=3D 0) /* null */ ; + while (NEXTBYTE(s) !=3D 0) /* null */ ; } =20 /* Discard file comment if any */ if ((flags & COMMENT) !=3D 0) { - while (NEXTBYTE() !=3D 0) /* null */ ; + while (NEXTBYTE(s) !=3D 0) /* null */ ; } =20 /* Decompress */ @@ -1181,15 +1181,15 @@ static int __init gunzip(struct gunzip_state *s) /* crc32 (see algorithm.doc) * uncompressed input size modulo 2^32 */ - orig_crc =3D (ulg) NEXTBYTE(); - orig_crc |=3D (ulg) NEXTBYTE() << 8; - orig_crc |=3D (ulg) NEXTBYTE() << 16; - orig_crc |=3D (ulg) NEXTBYTE() << 24; - - orig_len =3D (ulg) NEXTBYTE(); - orig_len |=3D (ulg) NEXTBYTE() << 8; - orig_len |=3D (ulg) NEXTBYTE() << 16; - orig_len |=3D (ulg) NEXTBYTE() << 24; + orig_crc =3D (ulg) NEXTBYTE(s); + orig_crc |=3D (ulg) NEXTBYTE(s) << 8; + orig_crc |=3D (ulg) NEXTBYTE(s) << 16; + orig_crc |=3D (ulg) NEXTBYTE(s) << 24; + + orig_len =3D (ulg) NEXTBYTE(s); + orig_len |=3D (ulg) NEXTBYTE(s) << 8; + orig_len |=3D (ulg) NEXTBYTE(s) << 16; + orig_len |=3D (ulg) NEXTBYTE(s) << 24; =20 /* Validate decompression */ if (orig_crc !=3D CRC_VALUE) { --=20 2.30.2