mirror of
https://github.com/ptitSeb/box86.git
synced 2024-11-22 22:30:25 +00:00
Fix some wrapping error (#771)
This commit is contained in:
parent
70a2a2dd1b
commit
f682ca6bf0
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ build*/
|
||||
src/git_head.h
|
||||
backup/
|
||||
box86_update.sh
|
||||
restore_backup.sh
|
||||
restore_backup.sh
|
||||
.cache
|
@ -12,6 +12,7 @@ void FreeBridge(bridge_t** bridge);
|
||||
|
||||
uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char* name);
|
||||
uintptr_t CheckBridged(bridge_t* bridge, void* fnc);
|
||||
int IsBridge(void* func);
|
||||
uintptr_t AddCheckBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char* name);
|
||||
uintptr_t AddAutomaticBridge(x86emu_t* emu, bridge_t* bridge, wrapper_t w, void* fnc, int N);
|
||||
void* GetNativeFnc(uintptr_t fnc);
|
||||
|
@ -145,12 +145,21 @@ uintptr_t AddBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char*
|
||||
uintptr_t CheckBridged(bridge_t* bridge, void* fnc)
|
||||
{
|
||||
// check if function alread have a bridge (the function wrapper will not be tested)
|
||||
if (!fnc) return 0;
|
||||
khint_t k = kh_get(bridgemap, bridge->bridgemap, (uint32_t)fnc);
|
||||
if(k==kh_end(bridge->bridgemap))
|
||||
return 0;
|
||||
return kh_value(bridge->bridgemap, k);
|
||||
}
|
||||
|
||||
int IsBridge(void* fnc) {
|
||||
onebridge_t *b = (onebridge_t*)fnc;
|
||||
if(!b || b->CC != 0xCC || b->S!='S' || b->C!='C' || (b->C3!=0xC3 && b->C3!=0xC2)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uintptr_t AddCheckBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char* name)
|
||||
{
|
||||
if(!fnc && w)
|
||||
@ -207,18 +216,19 @@ void* GetNativeFnc(uintptr_t fnc)
|
||||
#undef PK
|
||||
#undef PK32
|
||||
// check if bridge exist
|
||||
onebridge_t *b = (onebridge_t*)fnc;
|
||||
if(b->CC != 0xCC || b->S!='S' || b->C!='C' || (b->C3!=0xC3 && b->C3!=0xC2))
|
||||
return NULL; // not a bridge?!
|
||||
return (void*)b->f;
|
||||
if (IsBridge((void*)fnc)) {
|
||||
return (void*)((onebridge_t*)fnc)->f;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* GetNativeFncOrFnc(uintptr_t fnc)
|
||||
{
|
||||
onebridge_t *b = (onebridge_t*)fnc;
|
||||
if(b->CC != 0xCC || b->S!='S' || b->C!='C' || (b->C3!=0xC3 && b->C3!=0xC2))
|
||||
return (void*)fnc; // not a bridge?!
|
||||
return (void*)b->f;
|
||||
if (IsBridge((void*)fnc)) {
|
||||
return (void*)((onebridge_t*)fnc)->f;
|
||||
} else {
|
||||
return (void*)fnc;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_TRACE
|
||||
|
@ -3178,6 +3178,8 @@ wrappedlibjpeg:
|
||||
- jpeg_start_decompress
|
||||
- pFp:
|
||||
- jpeg_std_error
|
||||
- vFpp:
|
||||
- jpeg_stdio_src
|
||||
- iFpi:
|
||||
- jpeg_read_header
|
||||
- vFpiL:
|
||||
@ -3201,6 +3203,8 @@ wrappedlibjpeg62:
|
||||
- jpeg_std_error
|
||||
- vFpi:
|
||||
- jpeg_start_compress
|
||||
- vFpp:
|
||||
- jpeg_stdio_src
|
||||
- iFpi:
|
||||
- jpeg_read_header
|
||||
- jpeg_resync_to_restart
|
||||
|
@ -16,6 +16,7 @@ typedef int32_t (*iFv_t)(void);
|
||||
typedef int32_t (*iFp_t)(void*);
|
||||
typedef void* (*pFp_t)(void*);
|
||||
typedef void (*vFpi_t)(void*, int32_t);
|
||||
typedef void (*vFpp_t)(void*, void*);
|
||||
typedef int32_t (*iFpi_t)(void*, int32_t);
|
||||
typedef void (*vFpii_t)(void*, int32_t, int32_t);
|
||||
typedef void (*vFpiL_t)(void*, int32_t, uintptr_t);
|
||||
@ -34,6 +35,7 @@ typedef void (*vFpipu_t)(void*, int32_t, void*, uint32_t);
|
||||
GO(jpeg_start_decompress, iFp_t) \
|
||||
GO(jpeg_std_error, pFp_t) \
|
||||
GO(jpeg_start_compress, vFpi_t) \
|
||||
GO(jpeg_stdio_src, vFpp_t) \
|
||||
GO(jpeg_read_header, iFpi_t) \
|
||||
GO(jpeg_resync_to_restart, iFpi_t) \
|
||||
GO(jpeg_set_quality, vFpii_t) \
|
||||
|
@ -14,6 +14,7 @@
|
||||
typedef int32_t (*iFv_t)(void);
|
||||
typedef int32_t (*iFp_t)(void*);
|
||||
typedef void* (*pFp_t)(void*);
|
||||
typedef void (*vFpp_t)(void*, void*);
|
||||
typedef int32_t (*iFpi_t)(void*, int32_t);
|
||||
typedef void (*vFpiL_t)(void*, int32_t, uintptr_t);
|
||||
typedef void (*vFpip_t)(void*, int32_t, void*);
|
||||
@ -24,6 +25,7 @@ typedef uint32_t (*uFppu_t)(void*, void*, uint32_t);
|
||||
GO(jpeg_finish_decompress, iFp_t) \
|
||||
GO(jpeg_start_decompress, iFp_t) \
|
||||
GO(jpeg_std_error, pFp_t) \
|
||||
GO(jpeg_stdio_src, vFpp_t) \
|
||||
GO(jpeg_read_header, iFpi_t) \
|
||||
GO(jpeg_CreateDecompress, vFpiL_t) \
|
||||
GO(jpeg_set_marker_processor, vFpip_t) \
|
||||
|
@ -63,6 +63,49 @@ typedef struct jpeg_common_struct_s {
|
||||
static struct __jmp_buf_tag jmpbuf;
|
||||
static int is_jmpbuf;
|
||||
|
||||
static jpeg_error_mgr_t native_err_mgr;
|
||||
|
||||
#define SUPER() \
|
||||
jpeg_common_struct_t temp_cinfo = *cinfo; \
|
||||
jpeg_error_mgr_t err = *cinfo->err; \
|
||||
temp_cinfo.err = &err; \
|
||||
GO(error_exit) \
|
||||
GO(emit_message) \
|
||||
GO(output_message) \
|
||||
GO(format_message) \
|
||||
GO(reset_error_mgr)
|
||||
|
||||
#define GO(A) \
|
||||
temp_cinfo.err->A = GetNativeFncOrFnc((uintptr_t)cinfo->err->A);
|
||||
|
||||
static void native_error_exit(jpeg_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.error_exit(&temp_cinfo);
|
||||
}
|
||||
|
||||
static void native_emit_message(jpeg_common_struct_t* cinfo, int msg_level) {
|
||||
SUPER();
|
||||
native_err_mgr.emit_message(&temp_cinfo, msg_level);
|
||||
}
|
||||
|
||||
static void native_output_message(jpeg_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.output_message(&temp_cinfo);
|
||||
}
|
||||
|
||||
static void native_format_message(jpeg_common_struct_t* cinfo, char* buffer) {
|
||||
SUPER();
|
||||
native_err_mgr.format_message(&temp_cinfo, buffer);
|
||||
}
|
||||
|
||||
static void native_reset_error_mgr(jpeg_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.reset_error_mgr(&temp_cinfo);
|
||||
}
|
||||
|
||||
#undef GO
|
||||
#undef SUPER
|
||||
|
||||
static void wrapErrorMgr(bridge_t* bridge, jpeg_error_mgr_t* mgr);
|
||||
static void unwrapErrorMgr(bridge_t* bridge, jpeg_error_mgr_t* mgr);
|
||||
|
||||
@ -309,6 +352,13 @@ EXPORT void* my_jpeg_std_error(x86emu_t* emu, void* errmgr)
|
||||
|
||||
wrapErrorMgr(my_lib->w.bridge, ret);
|
||||
|
||||
my->jpeg_std_error(&native_err_mgr);
|
||||
ret->error_exit = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_error_exit, 0, NULL);
|
||||
ret->emit_message = (void*)AddCheckBridge(my_lib->w.bridge, vFpi, native_emit_message, 0, NULL);
|
||||
ret->output_message = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_output_message, 0, NULL);
|
||||
ret->format_message = (void*)AddCheckBridge(my_lib->w.bridge, vFpp, native_format_message, 0, NULL);
|
||||
ret->reset_error_mgr = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_reset_error_mgr, 0, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -360,6 +410,10 @@ EXPORT void my_jpeg_set_marker_processor(x86emu_t* emu, jpeg_common_struct_t* ci
|
||||
WRAP(void, my->jpeg_set_marker_processor(cinfo, marker, findjpeg_marker_parser_methodFct(routine)));
|
||||
}
|
||||
|
||||
EXPORT void my_jpeg_stdio_src(x86emu_t* emu, jpeg_common_struct_t* cinfo, void* infile) {
|
||||
WRAP(void, my->jpeg_stdio_src(cinfo, infile));
|
||||
}
|
||||
|
||||
#undef WRAP
|
||||
|
||||
#define CUSTOM_INIT \
|
||||
|
@ -217,6 +217,49 @@ typedef struct i386_compress_ptr_s
|
||||
static struct __jmp_buf_tag jmpbuf;
|
||||
static int is_jmpbuf;
|
||||
|
||||
static jpeg62_error_mgr_t native_err_mgr;
|
||||
|
||||
#define SUPER() \
|
||||
jpeg62_common_struct_t temp_cinfo = *cinfo; \
|
||||
jpeg62_error_mgr_t err = *cinfo->err; \
|
||||
temp_cinfo.err = &err; \
|
||||
GO(error_exit) \
|
||||
GO(emit_message) \
|
||||
GO(output_message) \
|
||||
GO(format_message) \
|
||||
GO(reset_error_mgr)
|
||||
|
||||
#define GO(A) \
|
||||
temp_cinfo.err->A = GetNativeFncOrFnc((uintptr_t)cinfo->err->A);
|
||||
|
||||
static void native_error_exit(jpeg62_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.error_exit(&temp_cinfo);
|
||||
}
|
||||
|
||||
static void native_emit_message(jpeg62_common_struct_t* cinfo, int msg_level) {
|
||||
SUPER();
|
||||
native_err_mgr.emit_message(&temp_cinfo, msg_level);
|
||||
}
|
||||
|
||||
static void native_output_message(jpeg62_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.output_message(&temp_cinfo);
|
||||
}
|
||||
|
||||
static void native_format_message(jpeg62_common_struct_t* cinfo, char* buffer) {
|
||||
SUPER();
|
||||
native_err_mgr.format_message(&temp_cinfo, buffer);
|
||||
}
|
||||
|
||||
static void native_reset_error_mgr(jpeg62_common_struct_t* cinfo) {
|
||||
SUPER();
|
||||
native_err_mgr.reset_error_mgr(&temp_cinfo);
|
||||
}
|
||||
|
||||
#undef GO
|
||||
#undef SUPER
|
||||
|
||||
static void wrapErrorMgr(jpeg62_error_mgr_t* mgr);
|
||||
static void unwrapErrorMgr(jpeg62_error_mgr_t* mgr);
|
||||
static void wrapMemoryMgr(jpeg62_memory_mgr_t* mgr);
|
||||
@ -1254,6 +1297,13 @@ EXPORT void* my62_jpeg_std_error(x86emu_t* emu, void* errmgr)
|
||||
|
||||
wrapErrorMgr(ret);
|
||||
|
||||
my->jpeg_std_error(&native_err_mgr);
|
||||
ret->error_exit = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_error_exit, 0, NULL);
|
||||
ret->emit_message = (void*)AddCheckBridge(my_lib->w.bridge, vFpi, native_emit_message, 0, NULL);
|
||||
ret->output_message = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_output_message, 0, NULL);
|
||||
ret->format_message = (void*)AddCheckBridge(my_lib->w.bridge, vFpp, native_format_message, 0, NULL);
|
||||
ret->reset_error_mgr = (void*)AddCheckBridge(my_lib->w.bridge, vFp, native_reset_error_mgr, 0, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1329,6 +1379,10 @@ EXPORT void my62_jpeg_set_marker_processor(x86emu_t* emu, jpeg62_common_struct_t
|
||||
WRAP(void, my->jpeg_set_marker_processor(cinfo, marker, findjpeg_marker_parser_methodFct(routine)), 0);
|
||||
}
|
||||
|
||||
EXPORT void my62_jpeg_stdio_src(x86emu_t* emu, jpeg62_common_struct_t* cinfo, void* infile) {
|
||||
WRAP(void, my->jpeg_stdio_src(cinfo, infile), 0);
|
||||
}
|
||||
|
||||
EXPORT void my62_jpeg_destroy_decompress(x86emu_t* emu, jpeg62_common_struct_t* cinfo)
|
||||
{
|
||||
// no WRAP macro because we don't want to wrap at the exit
|
||||
|
@ -117,7 +117,7 @@ GOM(jpeg_start_decompress, iFEp)
|
||||
GO(jpeg_start_output, iFpi)
|
||||
GOM(jpeg_std_error, pFEp)
|
||||
GO(jpeg_stdio_dest, vFpp)
|
||||
GO(jpeg_stdio_src, vFpp)
|
||||
GOM(jpeg_stdio_src, vFEpp)
|
||||
DATA(jpeg_std_message_table, 4)
|
||||
GO(jpeg_suppress_tables, vFpi)
|
||||
GO(jpeg_write_coefficients, vFpp)
|
||||
|
@ -116,7 +116,7 @@ GOM(jpeg_start_decompress, iFEp)
|
||||
GO(jpeg_start_output, iFpi)
|
||||
GOM(jpeg_std_error, pFEp)
|
||||
GO(jpeg_stdio_dest, vFpp)
|
||||
GO(jpeg_stdio_src, vFpp)
|
||||
GOM(jpeg_stdio_src, vFEpp)
|
||||
DATA(jpeg_std_message_table, 4)
|
||||
GO(jpeg_suppress_tables, vFpi)
|
||||
GO(jpeg_write_coefficients, vFpp)
|
||||
|
Loading…
Reference in New Issue
Block a user