From 19cafa332c67ff75943870a3a578e33f7f4985c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sun, 5 Jan 2025 13:08:33 -0500 Subject: [PATCH] Fix array indexing in sandbox-bindgen.rb --- retro/Makefile | 18 ++++++++++++++++-- retro/sandbox-bindgen.rb | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/retro/Makefile b/retro/Makefile index 2719f87c..64e66a35 100644 --- a/retro/Makefile +++ b/retro/Makefile @@ -32,7 +32,21 @@ GIT := git CLONE := $(GIT) clone -q --depth 1 GITHUB := https://github.com -default: $(OUTDIR)/mkxp-retro-dist.zip.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby.h $(OUTDIR)/mkxp-sandbox-bindgen.cpp $(OUTDIR)/mkxp-sandbox-bindgen.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c $(OUTDIR)/libretro.h +all default: deps ruby-dist ruby-bindings + +ruby-dist: $(OUTDIR)/mkxp-retro-dist.zip.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby.h + +ruby-bindings: $(OUTDIR)/mkxp-sandbox-bindgen.cpp $(OUTDIR)/mkxp-sandbox-bindgen.h + +deps: $(OUTDIR)/libretro.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c + +clean: + rm -rf $(BUILD_PREFIX) + +clean-ruby-bindings: + rm -f $(OUTDIR)/mkxp-sandbox-bindgen.cpp; \ + rm -f $(OUTDIR)/mkxp-sandbox-bindgen.h; \ + rm -f $(LIBDIR)/tags $(OUTDIR)/libretro.h: mkdir -p $(OUTDIR); \ @@ -99,7 +113,7 @@ $(OUTDIR)/mkxp-sandbox-bindgen.cpp $(OUTDIR)/mkxp-sandbox-bindgen.h: $(LIBDIR)/t mv mkxp-sandbox-bindgen.cpp $(OUTDIR) $(LIBDIR)/tags: $(LIBDIR)/include/ruby-$(RUBY_VERSION).0 - $(CTAGS) -R --output-format=e-ctags --fields=S --kinds-c=p --kinds-c++=p -o $(LIBDIR)/tags $(LIBDIR)/include/ruby-$(RUBY_VERSION).0 + $(CTAGS) -R --fields=S --kinds-c=p --kinds-c++=p -o $(LIBDIR)/tags $(LIBDIR)/include/ruby-$(RUBY_VERSION).0 $(RUBY) $(LIBDIR)/include/ruby-$(RUBY_VERSION).0: $(DOWNLOADS)/baseruby/Makefile cd $(DOWNLOADS)/baseruby; \ diff --git a/retro/sandbox-bindgen.rb b/retro/sandbox-bindgen.rb index 5cb0da85..f044bfb5 100644 --- a/retro/sandbox-bindgen.rb +++ b/retro/sandbox-bindgen.rb @@ -60,7 +60,7 @@ ARG_HANDLERS = { buf_size: 'PREV_ARG * sizeof(wasm_ptr_t)', serialize: <<~HEREDOC for (int i = 0; i < PREV_ARG; ++i) { - ((wasm_ptr_t *)module_instance->w2c_memory.data + BUF)[i] = SERIALIZE_PTR(ARG[i]); + ((wasm_ptr_t *)(module_instance->w2c_memory.data + BUF))[i] = SERIALIZE_PTR(ARG[i]); } HEREDOC }, @@ -355,7 +355,7 @@ File.readlines('tags', chomp: true).each do |line| std::va_list a; va_start(a, a#{args.length - 2}); for (long i = 0; i < a#{args.length - 2}; ++i) { - ((wasm_ptr_t *)module_instance->w2c_memory.data + v)[i] = SERIALIZE_PTR(va_arg(a, wasm_ptr_t)); + ((wasm_ptr_t *)(module_instance->w2c_memory.data + v))[i] = SERIALIZE_PTR(va_arg(a, wasm_ptr_t)); } va_end(a); HEREDOC @@ -378,7 +378,7 @@ File.readlines('tags', chomp: true).each do |line| throw SandboxOutOfMemoryException(); } for (wasm_ptr_t i = 0; i < n; ++i) { - ((wasm_ptr_t *)module_instance->w2c_memory.data + v)[i] = SERIALIZE_PTR(va_arg(a, wasm_ptr_t)); + ((wasm_ptr_t *)(module_instance->w2c_memory.data + v))[i] = SERIALIZE_PTR(va_arg(a, wasm_ptr_t)); } HEREDOC binding += "\n"