Skip to content

Commit

Permalink
Fixed wrapped __gmp_get_memory_functions and added __gmp_set_memory_f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
ptitSeb committed Aug 18, 2023
1 parent 80c77ba commit 58b0338
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,7 @@ wrappedgmodule2:
wrappedgmp:
- vFppp:
- __gmp_get_memory_functions
- __gmp_set_memory_functions
wrappedgnutls:
- vFp:
- gnutls_global_set_log_function
Expand Down
3 changes: 2 additions & 1 deletion src/wrapped/generated/wrappedgmptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
typedef void (*vFppp_t)(void*, void*, void*);

#define SUPER() ADDED_FUNCTIONS() \
GO(__gmp_get_memory_functions, vFppp_t)
GO(__gmp_get_memory_functions, vFppp_t) \
GO(__gmp_set_memory_functions, vFppp_t)

#endif // __wrappedgmpTYPES_H_
41 changes: 39 additions & 2 deletions src/wrapped/wrappedgmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ static void* find_alloc_func_Fct(void* fct)
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 alloc_func callback\n");
return NULL;
}
static void* reverse_alloc_func_Fct(void* fct)
{
if(!fct) return fct;
if(CheckBridged(my_lib->w.bridge, fct))
return (void*)CheckBridged(my_lib->w.bridge, fct);
#define GO(A) if(my_alloc_func_##A == fct) return (void*)my_alloc_func_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(my_lib->w.bridge, pFL, fct, 0, NULL);
}
// realloc_func
#define GO(A) \
static uintptr_t my_realloc_func_fct_##A = 0; \
Expand All @@ -79,6 +89,16 @@ static void* find_realloc_func_Fct(void* fct)
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 realloc_func callback\n");
return NULL;
}
static void* reverse_realloc_func_Fct(void* fct)
{
if(!fct) return fct;
if(CheckBridged(my_lib->w.bridge, fct))
return (void*)CheckBridged(my_lib->w.bridge, fct);
#define GO(A) if(my_realloc_func_##A == fct) return (void*)my_realloc_func_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(my_lib->w.bridge, pFpL, fct, 0, NULL);
}
// free_func
#define GO(A) \
static uintptr_t my_free_func_fct_##A = 0; \
Expand All @@ -102,12 +122,29 @@ static void* find_free_func_Fct(void* fct)
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 free_func callback\n");
return NULL;
}
static void* reverse_free_func_Fct(void* fct)
{
if(!fct) return fct;
if(CheckBridged(my_lib->w.bridge, fct))
return (void*)CheckBridged(my_lib->w.bridge, fct);
#define GO(A) if(my_free_func_##A == fct) return (void*)my_free_func_fct_##A;
SUPER()
#undef GO
return (void*)AddBridge(my_lib->w.bridge, vFp, fct, 0, NULL);
}

#undef SUPER

EXPORT void my___gmp_get_memory_functions(x86emu_t* emu, void* f_alloc, void* f_realloc, void* f_free)
EXPORT void my___gmp_get_memory_functions(x86emu_t* emu, void** f_alloc, void** f_realloc, void** f_free)
{
my->__gmp_get_memory_functions(f_alloc, f_realloc, f_free);
*f_alloc = reverse_alloc_func_Fct(*f_alloc);
*f_realloc = reverse_realloc_func_Fct(*f_realloc);
*f_free = reverse_free_func_Fct(*f_free);
}
EXPORT void my___gmp_set_memory_functions(x86emu_t* emu, void* f_alloc, void* f_realloc, void* f_free)
{
my->__gmp_get_memory_functions(find_alloc_func_Fct(f_alloc), find_realloc_func_Fct(f_realloc), find_free_func_Fct(f_free));
my->__gmp_set_memory_functions(find_alloc_func_Fct(f_alloc), find_realloc_func_Fct(f_realloc), find_free_func_Fct(f_free));
}

#define CUSTOM_INIT \
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped/wrappedgmp_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ GO(__gmpn_zero, vFpL)
//DATAB(__gmp_rands_initialized,
//DATA(__gmp_reallocate_func,
//GO(__gmp_scanf,
//GO(__gmp_set_memory_functions,
GOM(__gmp_set_memory_functions, vFEppp)
//GO(__gmp_snprintf,
//DATA(__gmp_snprintf_funs,
//GO(__gmp_sprintf,
Expand Down

0 comments on commit 58b0338

Please sign in to comment.