~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/xtensa/boot/lib/zmem.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/zlib.h>
  3 
  4 /* bits taken from ppc */
  5 
  6 extern void *avail_ram, *end_avail;
  7 void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp);
  8 
  9 static void exit(void)
 10 {
 11   for (;;);
 12 }
 13 
 14 static void *zalloc(unsigned int size)
 15 {
 16         void *p = avail_ram;
 17 
 18         size = (size + 7) & -8;
 19         avail_ram += size;
 20         if (avail_ram > end_avail) {
 21                 //puts("oops... out of memory\n");
 22                 //pause();
 23                 exit ();
 24         }
 25         return p;
 26 }
 27 
 28 #define HEAD_CRC        2
 29 #define EXTRA_FIELD     4
 30 #define ORIG_NAME       8
 31 #define COMMENT         0x10
 32 #define RESERVED        0xe0
 33 
 34 #define DEFLATED        8
 35 
 36 void gunzip (void *dst, int dstlen, unsigned char *src, int *lenp)
 37 {
 38         z_stream s;
 39         int r, i, flags;
 40 
 41         /* skip header */
 42         i = 10;
 43         flags = src[3];
 44         if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
 45                 //puts("bad gzipped data\n");
 46                 exit();
 47         }
 48         if ((flags & EXTRA_FIELD) != 0)
 49                 i = 12 + src[10] + (src[11] << 8);
 50         if ((flags & ORIG_NAME) != 0)
 51                 while (src[i++] != 0)
 52                         ;
 53         if ((flags & COMMENT) != 0)
 54                 while (src[i++] != 0)
 55                         ;
 56         if ((flags & HEAD_CRC) != 0)
 57                 i += 2;
 58         if (i >= *lenp) {
 59                 //puts("gunzip: ran out of data in header\n");
 60                 exit();
 61         }
 62 
 63         s.workspace = zalloc(zlib_inflate_workspacesize());
 64         r = zlib_inflateInit2(&s, -MAX_WBITS);
 65         if (r != Z_OK) {
 66                 //puts("inflateInit2 returned "); puthex(r); puts("\n");
 67                 exit();
 68         }
 69         s.next_in = src + i;
 70         s.avail_in = *lenp - i;
 71         s.next_out = dst;
 72         s.avail_out = dstlen;
 73         r = zlib_inflate(&s, Z_FINISH);
 74         if (r != Z_OK && r != Z_STREAM_END) {
 75                 //puts("inflate returned "); puthex(r); puts("\n");
 76                 exit();
 77         }
 78         *lenp = s.next_out - (unsigned char *) dst;
 79         zlib_inflateEnd(&s);
 80 }
 81 
 82 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php