compress: Replace tinf's inflate implementation with stb_image's zlib
This commit is contained in:
parent
caaf4f94a5
commit
71b3ae548b
|
@ -5,6 +5,7 @@
|
|||
/freestanding-headers
|
||||
/libgcc-binaries
|
||||
/common/term
|
||||
/common/stb/stb_image.h
|
||||
/ovmf*
|
||||
*.o
|
||||
*.d
|
||||
|
|
|
@ -299,7 +299,7 @@ distclean: clean
|
|||
|
||||
.PHONY: maintainer-clean
|
||||
maintainer-clean: distclean
|
||||
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/term freestanding-headers libgcc-binaries limine-efi cross-detect configure build-aux *'~' autom4te.cache *.tar.xz *.tar.gz
|
||||
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf common/term common/stb/stb_image.h freestanding-headers libgcc-binaries limine-efi cross-detect configure build-aux *'~' autom4te.cache *.tar.xz *.tar.gz
|
||||
|
||||
.PHONY: common-uefi-x86-64
|
||||
common-uefi-x86-64:
|
||||
|
|
|
@ -8,6 +8,7 @@ test -z "$srcdir" && srcdir=.
|
|||
cd "$srcdir"
|
||||
|
||||
[ -d common/term ] || git clone https://github.com/limine-bootloader/terminal.git common/term
|
||||
[ -f common/stb/stb_image.h ] || ( curl -Lo common/stb/stb_image.h https://github.com/nothings/stb/raw/master/stb_image.h && patch -p0 < common/stb_image.patch )
|
||||
[ -d cross-detect ] || git clone https://github.com/mintsuki/cross-detect.git
|
||||
[ -d freestanding-headers ] || git clone https://github.com/mintsuki/freestanding-headers.git
|
||||
[ -d limine-efi ] || git clone https://github.com/limine-bootloader/limine-efi.git
|
||||
|
|
|
@ -51,7 +51,6 @@ override CROSS_CFLAGS += \
|
|||
-DCOM_OUTPUT=$(COM_OUTPUT) \
|
||||
-DE9_OUTPUT=$(E9_OUTPUT) \
|
||||
-I../freestanding-headers \
|
||||
-I'$(call SHESCAPE,$(BUILDDIR))/tinf' \
|
||||
-I'$(call SHESCAPE,$(BUILDDIR))/..' \
|
||||
-I. \
|
||||
-I..
|
||||
|
@ -191,20 +190,6 @@ else ifeq ($(TARGET),uefi-aarch64)
|
|||
all: $(call MKESCAPE,$(BUILDDIR))/BOOTAA64.EFI
|
||||
endif
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/tinf-copied: ../tinf/*
|
||||
rm -rf '$(call SHESCAPE,$(BUILDDIR))/tinf'
|
||||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
cp -r ../tinf '$(call SHESCAPE,$(BUILDDIR))/'
|
||||
touch '$(call SHESCAPE,$(BUILDDIR))/tinf-copied'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
|
||||
|
||||
ifeq ($(TARGET),bios)
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/stage2.bin.gz: $(call MKESCAPE,$(BUILDDIR))/stage2.bin
|
||||
|
@ -242,7 +227,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker_nos2map.ld: linker_bios.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef -DLINKER_NOMAP -DLINKER_NOS2MAP linker_bios.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker_nos2map.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker_nos2map.ld'
|
||||
$(CROSS_LD) '$(call OBJESCAPE,$^)' $(CROSS_LDFLAGS) -T'$(call SHESCAPE,$(BUILDDIR))/linker_nos2map.ld' -o '$(call SHESCAPE,$@)'
|
||||
$(CROSS_OBJCOPY) -O binary --only-section=.note.gnu.build-id '$(call SHESCAPE,$@)' '$(call SHESCAPE,$(BUILDDIR))/build-id.s2.bin'
|
||||
|
@ -257,7 +242,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker_nomap.ld: linker_bios.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef -DLINKER_NOMAP linker_bios.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nos3map.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o $(call MKESCAPE,$(BUILDDIR))/stage2.map.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nos3map.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/stage2.map.o
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
$(CROSS_LD) '$(call OBJESCAPE,$^)' $(CROSS_LDFLAGS) -T'$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld' -o '$(call SHESCAPE,$@)'
|
||||
$(CROSS_OBJCOPY) -O binary --only-section=.note.gnu.build-id '$(call SHESCAPE,$@)' '$(call SHESCAPE,$(BUILDDIR))/build-id.s2.bin'
|
||||
|
@ -272,7 +257,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker.ld: linker_bios.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef linker_bios.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o $(call MKESCAPE,$(BUILDDIR))/stage2.map.o $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/stage2.map.o $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
$(CROSS_LD) '$(call OBJESCAPE,$^)' $(CROSS_LDFLAGS) -T'$(call SHESCAPE,$(BUILDDIR))/linker.ld' -o '$(call SHESCAPE,$@)'
|
||||
$(CROSS_OBJCOPY) -O binary --only-section=.note.gnu.build-id '$(call SHESCAPE,$@)' '$(call SHESCAPE,$(BUILDDIR))/build-id.s2.bin'
|
||||
|
@ -312,7 +297,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker_nomap.ld: linker_uefi_x86_64.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef -DLINKER_NOMAP linker_uefi_x86_64.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-x86_64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_x86_64.o $(OBJ) ../libgcc-binaries/libgcc-x86_64-no-red-zone.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-x86_64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_x86_64.o $(OBJ) ../libgcc-binaries/libgcc-x86_64-no-red-zone.a
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld' \
|
||||
|
@ -322,7 +307,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker.ld: linker_uefi_x86_64.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef linker_uefi_x86_64.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-x86_64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_x86_64.o $(OBJ) ../libgcc-binaries/libgcc-x86_64-no-red-zone.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-x86_64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_x86_64.o $(OBJ) ../libgcc-binaries/libgcc-x86_64-no-red-zone.a $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker.ld' \
|
||||
|
@ -353,7 +338,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker_nomap.ld: linker_uefi_aarch64.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef -DLINKER_NOMAP linker_uefi_aarch64.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-aarch64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_aarch64.o $(OBJ) ../libgcc-binaries/libgcc-aarch64.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-aarch64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_aarch64.o $(OBJ) ../libgcc-binaries/libgcc-aarch64.a
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld' \
|
||||
|
@ -363,7 +348,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker.ld: linker_uefi_aarch64.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef linker_uefi_aarch64.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-aarch64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_aarch64.o $(OBJ) ../libgcc-binaries/libgcc-aarch64.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-aarch64.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_aarch64.o $(OBJ) ../libgcc-binaries/libgcc-aarch64.a $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker.ld' \
|
||||
|
@ -393,7 +378,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker_nomap.ld: linker_uefi_ia32.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef -DLINKER_NOMAP linker_uefi_ia32.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-ia32.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_ia32.o $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-ia32.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_ia32.o $(OBJ) ../libgcc-binaries/libgcc-i686.a
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker_nomap.ld' \
|
||||
|
@ -403,7 +388,7 @@ $(call MKESCAPE,$(BUILDDIR))/linker.ld: linker_uefi_ia32.ld.in
|
|||
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
|
||||
$(CROSS_CC) -x c -E -P -undef linker_uefi_ia32.ld.in -o '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-ia32.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_ia32.o $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/crt0-efi-ia32.o $(call MKESCAPE,$(BUILDDIR))/limine-efi/gnuefi/reloc_ia32.o $(OBJ) ../libgcc-binaries/libgcc-i686.a $(call MKESCAPE,$(BUILDDIR))/full.map.o
|
||||
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/linker.ld'
|
||||
$(CROSS_LD) \
|
||||
-T'$(call SHESCAPE,$(BUILDDIR))/linker.ld' \
|
||||
|
@ -414,25 +399,25 @@ endif
|
|||
-include $(HEADER_DEPS)
|
||||
|
||||
ifeq ($(TARGET),uefi-x86-64)
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET),uefi-aarch64)
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET),uefi-ia32)
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/limine-efi
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET),bios)
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
|
||||
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c
|
||||
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
|
||||
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* tinfgzip - tiny gzip decompressor
|
||||
*
|
||||
* Copyright (c) 2003-2019 Joergen Ibsen
|
||||
* Copyright (c) 2023 mintsuki and contributors to the Limine project
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must
|
||||
* not claim that you wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must
|
||||
* not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
typedef enum {
|
||||
FTEXT = 1,
|
||||
FHCRC = 2,
|
||||
FEXTRA = 4,
|
||||
FNAME = 8,
|
||||
FCOMMENT = 16
|
||||
} tinf_gzip_flag;
|
||||
|
||||
int tinf_gzip_uncompress(void *dest, unsigned int limit,
|
||||
const void *source, unsigned int sourceLen) {
|
||||
const unsigned char *src = (const unsigned char *) source;
|
||||
unsigned char *dst = (unsigned char *) dest;
|
||||
const unsigned char *start;
|
||||
int res;
|
||||
unsigned char flg;
|
||||
|
||||
/* -- Check header -- */
|
||||
|
||||
/* Check room for at least 10 byte header and 8 byte trailer */
|
||||
if (sourceLen < 18) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check id bytes */
|
||||
if (src[0] != 0x1F || src[1] != 0x8B) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check method is deflate */
|
||||
if (src[2] != 8) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get flag byte */
|
||||
flg = src[3];
|
||||
|
||||
/* Check that reserved bits are zero */
|
||||
if (flg & 0xE0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -- Find start of compressed data -- */
|
||||
|
||||
/* Skip base header of 10 bytes */
|
||||
start = src + 10;
|
||||
|
||||
/* Skip extra data if present */
|
||||
if (flg & FEXTRA) {
|
||||
unsigned int xlen = *start;
|
||||
|
||||
if (xlen > sourceLen - 12) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
start += xlen + 2;
|
||||
}
|
||||
|
||||
/* Skip file name if present */
|
||||
if (flg & FNAME) {
|
||||
do {
|
||||
if (((unsigned int)(start - src)) >= sourceLen) {
|
||||
return -1;
|
||||
}
|
||||
} while (*start++);
|
||||
}
|
||||
|
||||
/* Skip file comment if present */
|
||||
if (flg & FCOMMENT) {
|
||||
do {
|
||||
if (((unsigned int)(start - src)) >= sourceLen) {
|
||||
return -1;
|
||||
}
|
||||
} while (*start++);
|
||||
}
|
||||
|
||||
if (flg & FHCRC) {
|
||||
start += 2;
|
||||
}
|
||||
|
||||
/* -- Decompress data -- */
|
||||
|
||||
if ((src + sourceLen) - start < 8) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = stbi_zlib_decode_noheader_buffer((char *)dst, limit, (const char *)start, (src + sourceLen) - start - 8);
|
||||
|
||||
return res == -1 ? res : 0;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef __COMPRESS__TINFGZIP_H__
|
||||
#define __COMPRESS__TINFGZIP_H__
|
||||
|
||||
int tinf_gzip_uncompress(void *dest, unsigned int limit,
|
||||
const void *source, unsigned int sourceLen);
|
||||
|
||||
#endif
|
|
@ -8,7 +8,7 @@
|
|||
#include <mm/pmm.h>
|
||||
#include <lib/print.h>
|
||||
#include <pxe/tftp.h>
|
||||
#include <tinf.h>
|
||||
#include <compress/tinfgzip.h>
|
||||
#include <menu.h>
|
||||
#include <lib/readline.h>
|
||||
#include <crypt/blake2b.h>
|
||||
|
@ -275,7 +275,7 @@ struct file_handle *uri_open(char *uri) {
|
|||
fread(ret, &compressed_fd->size, ret->size - 4, sizeof(uint32_t));
|
||||
compressed_fd->fd = ext_mem_alloc(compressed_fd->size);
|
||||
void *src = freadall(ret, MEMMAP_BOOTLOADER_RECLAIMABLE);
|
||||
if (tinf_gzip_uncompress(compressed_fd->fd, src, ret->size)) {
|
||||
if (tinf_gzip_uncompress(compressed_fd->fd, compressed_fd->size, src, ret->size)) {
|
||||
panic(true, "tinf error");
|
||||
}
|
||||
compressed_fd->vol = ret->vol;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
|
||||
#include <stb/stb_image.h>
|
|
@ -0,0 +1,62 @@
|
|||
--- common/stb/stb_image.h 2023-02-15 10:53:10.719623884 +0100
|
||||
+++ common/stb/stb_image.h 2023-02-15 10:54:43.312960410 +0100
|
||||
@@ -127,6 +127,37 @@
|
||||
#ifndef STBI_INCLUDE_STB_IMAGE_H
|
||||
#define STBI_INCLUDE_STB_IMAGE_H
|
||||
|
||||
+#include <stddef.h>
|
||||
+#include <lib/libc.h>
|
||||
+#include <mm/pmm.h>
|
||||
+
|
||||
+#define INT_MAX __INT_MAX__
|
||||
+#define INT_MIN (-INT_MAX - 1)
|
||||
+
|
||||
+#define UINT_MAX ((size_t)INT_MAX * 2 + 1)
|
||||
+#define UINT_MIN (-UINT_MAX - 1)
|
||||
+
|
||||
+#define SHRT_MAX __SHRT_MAX__
|
||||
+#define SHRT_MIN (-SHRT_MAX - 1)
|
||||
+
|
||||
+#define STBI_ASSERT(x)
|
||||
+
|
||||
+#define STBI_MALLOC(x) ext_mem_alloc(x)
|
||||
+#define STBI_REALLOC(x, y) ({ \
|
||||
+ void *STBI_REALLOC_new_buf = ext_mem_alloc(y); \
|
||||
+ memcpy(STBI_REALLOC_new_buf, x, y); \
|
||||
+ STBI_REALLOC_new_buf; \
|
||||
+})
|
||||
+#define STBI_FREE(x)
|
||||
+
|
||||
+#define STBI_NO_THREAD_LOCALS
|
||||
+#define STBI_NO_STDIO
|
||||
+#define STBI_NO_SIMD
|
||||
+#define STBI_NO_LINEAR
|
||||
+
|
||||
+#define STBI_ONLY_ZLIB
|
||||
+#define STBI_SUPPORT_ZLIB
|
||||
+
|
||||
// DOCUMENTATION
|
||||
//
|
||||
// Limitations:
|
||||
@@ -381,7 +412,7 @@
|
||||
STBI_rgb_alpha = 4
|
||||
};
|
||||
|
||||
-#include <stdlib.h>
|
||||
+// #include <stdlib.h>
|
||||
typedef unsigned char stbi_uc;
|
||||
typedef unsigned short stbi_us;
|
||||
|
||||
@@ -584,9 +615,9 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h> // ptrdiff_t on osx
|
||||
-#include <stdlib.h>
|
||||
-#include <string.h>
|
||||
-#include <limits.h>
|
||||
+// #include <stdlib.h>
|
||||
+// #include <string.h>
|
||||
+// #include <limits.h>
|
||||
|
||||
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
|
||||
#include <math.h> // ldexp, pow
|
Loading…
Reference in New Issue