mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-23 23:33:45 +02:00
Make sure sandbox stack grows upwards in big-endian libretro builds
This commit is contained in:
parent
3ba12e5672
commit
58e6f71ef3
3 changed files with 30 additions and 5 deletions
|
@ -289,7 +289,13 @@ namespace mkxp_sandbox {
|
|||
fiber->stack.pop_back();
|
||||
}
|
||||
++fiber->stack_index;
|
||||
b.stack_ptr = w2c_ruby_rb_wasm_get_stack_pointer(&b.instance()) - CEIL_WASMSTACKALIGN(declared_slots_size<T>::value);
|
||||
b.stack_ptr = w2c_ruby_rb_wasm_get_stack_pointer(&b.instance())
|
||||
#ifdef MKXPZ_BIG_ENDIAN
|
||||
+
|
||||
#else
|
||||
-
|
||||
#endif // MKXPZ_BIG_ENDIAN
|
||||
CEIL_WASMSTACKALIGN(declared_slots_size<T>::value);
|
||||
assert(b.stack_ptr % sizeof(VALUE) == 0);
|
||||
assert(b.stack_ptr % WASMSTACKALIGN == 0);
|
||||
if (declared_slots_size<T>::value != 0) {
|
||||
|
@ -333,7 +339,16 @@ namespace mkxp_sandbox {
|
|||
|
||||
assert(fiber->stack.size() == fiber->stack_index);
|
||||
|
||||
w2c_ruby_rb_wasm_set_stack_pointer(&bind->instance(), fiber->stack.back().stack_ptr + CEIL_WASMSTACKALIGN(declared_slots_size<T>::value));
|
||||
w2c_ruby_rb_wasm_set_stack_pointer(
|
||||
&bind->instance(),
|
||||
fiber->stack.back().stack_ptr
|
||||
#ifdef MKXPZ_BIG_ENDIAN
|
||||
-
|
||||
#else
|
||||
+
|
||||
#endif // MKXPZ_BIG_ENDIAN
|
||||
CEIL_WASMSTACKALIGN(declared_slots_size<T>::value)
|
||||
);
|
||||
bind->stack_ptr = fiber->stack.back().stack_ptr;
|
||||
fiber->stack.pop_back();
|
||||
}
|
||||
|
|
|
@ -269,6 +269,16 @@ PRELUDE = <<~HEREDOC
|
|||
|
||||
bindings::bindings(std::shared_ptr<struct w2c_#{MODULE_NAME}> m) : binding_base(m) {}
|
||||
|
||||
static wasm_ptr_t _sbindgen_stack_push(wasm_ptr_t frame_pointer, wasm_size_t num_bytes) {
|
||||
return frame_pointer
|
||||
#ifdef MKXPZ_BIG_ENDIAN
|
||||
+
|
||||
#else
|
||||
-
|
||||
#endif // MKXPZ_BIG_ENDIAN
|
||||
num_bytes;
|
||||
}
|
||||
|
||||
static void _sbindgen_strcpy(char *dst, const char *src) {
|
||||
#ifdef MKXPZ_BIG_ENDIAN
|
||||
do {
|
||||
|
@ -512,7 +522,7 @@ File.readlines('tags', chomp: true).each do |line|
|
|||
coroutine_initializer += <<~HEREDOC
|
||||
{
|
||||
wasm_ptr_t fp = w2c_ruby_rb_wasm_get_stack_pointer(&bind.instance());
|
||||
wasm_ptr_t sp = fp - CEIL_WASMSTACKALIGN(a#{args.length - 2} * sizeof(VALUE));
|
||||
wasm_ptr_t sp = _sbindgen_stack_push(fp, CEIL_WASMSTACKALIGN(a#{args.length - 2} * sizeof(VALUE)));
|
||||
if (sp > fp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
@ -539,7 +549,7 @@ File.readlines('tags', chomp: true).each do |line|
|
|||
do ++n; while (va_arg(b, VALUE));
|
||||
va_end(b);
|
||||
wasm_ptr_t fp = w2c_ruby_rb_wasm_get_stack_pointer(&bind.instance());
|
||||
wasm_ptr_t sp = fp - CEIL_WASMSTACKALIGN(n * sizeof(VALUE));
|
||||
wasm_ptr_t sp = _sbindgen_stack_push(fp, CEIL_WASMSTACKALIGN(n * sizeof(VALUE)));
|
||||
if (sp > fp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
|
|
@ -1979,7 +1979,7 @@ void Bitmap::replaceRaw(void *pixel_data, int size)
|
|||
throw Exception(Exception::MKXPError, "Replacement bitmap data is not large enough (given %i bytes, need %i)", size, requiredsize);
|
||||
|
||||
#if defined(MKXPZ_RETRO) && defined(MKXPZ_BIG_ENDIAN)
|
||||
output -= output_size;
|
||||
pixel_data -= output_size;
|
||||
std::reverse((uint8_t *)pixel_data, (uint8_t *)pixel_data + size);
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue