diff --git a/examples/Makefile b/examples/Makefile index 756d82d..444e135 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -7,7 +7,7 @@ all: examples #--------------------------------------------------------------------------------- @rm -fr bin @mkdir -p bin - @find . -name "*.3dsx" -exec cp -fv {} bin \; + @find . -name "*.3dsx" ! -path "./bin/*" -exec cp -fv {} bin \; examples: @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; diff --git a/examples/gpu/Makefile b/examples/gpu/Makefile index ee6b6e4..19c9ac9 100644 --- a/examples/gpu/Makefile +++ b/examples/gpu/Makefile @@ -161,7 +161,7 @@ $(OUTPUT).elf : $(OFILES) %_vsh.h %.vsh.o : %.vsh #--------------------------------------------------------------------------------- @echo $(notdir $<) - @python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin + @python3 $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin @bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@ @echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h @echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h diff --git a/libctru/Makefile b/libctru/Makefile index 966c20c..67b189e 100644 --- a/libctru/Makefile +++ b/libctru/Makefile @@ -9,8 +9,8 @@ endif include $(DEVKITARM)/base_rules export LIBCTRU_MAJOR := 0 -export LIBCTRU_MINOR := 4 -export LIBCTRU_PATCH := 1 +export LIBCTRU_MINOR := 5 +export LIBCTRU_PATCH := 0 VERSION := $(LIBCTRU_MAJOR).$(LIBCTRU_MINOR).$(LIBCTRU_PATCH) @@ -107,7 +107,7 @@ dist-bin: all @tar -cjf libctru-$(VERSION).tar.bz2 include lib default_icon.png dist-src: - @tar -cjf libctru-src-$(VERSION).tar.bz2 include source Makefile Doxyfile Doxyfile.internal default_icon.png + @tar -cjf libctru-src-$(VERSION).tar.bz2 include source data Makefile Doxyfile Doxyfile.internal default_icon.png dist: dist-src dist-bin diff --git a/libctru/source/allocator/mem_pool.cpp b/libctru/source/allocator/mem_pool.cpp index a2c312d..7482cc6 100644 --- a/libctru/source/allocator/mem_pool.cpp +++ b/libctru/source/allocator/mem_pool.cpp @@ -32,14 +32,34 @@ void MemPool::CoalesceRight(MemBlock* b) bool MemPool::Allocate(MemChunk& chunk, u32 size, int align) { - int alignM = (1 << align) - 1; - size = (size + alignM) &~ alignM; // Round the size + // Don't shift out of bounds (CERT INT34-C) + if(align >= 32 || align < 0) + return false; + + // Alignment must not be 0 + if(align == 0) + return false; + + u32 alignMask = (1 << align) - 1; + + // Check if size doesn't fit neatly in alignment + if(size & alignMask) + { + // Make sure addition won't overflow (CERT INT30-C) + if(size > UINT32_MAX - alignMask) + return false; + + // Pad size to next alignment + size = (size + alignMask) &~ alignMask; + } + // Find the first suitable block for (auto b = first; b; b = b->next) { auto addr = b->base; - u32 begWaste = (u32)addr & alignM; - if (begWaste > 0) begWaste = alignM + 1 - begWaste; + u32 begWaste = (u32)addr & alignMask; + if (begWaste > 0) begWaste = alignMask + 1 - begWaste; + if (begWaste > b->size) continue; addr += begWaste; u32 bSize = b->size - begWaste; if (bSize < size) continue;