Repository navigation
[Library Forwarding/Question] Any plan to forward openssl? #5526
Replies: 2 comments 4 replies
|
Usually we only create library forwards for things that take significant CPU time in a wide variety of applications like GL and Vulkan. Each one adds maintenance burden. Is there some application spending significant time in this library to matter? |
|
Here is my implement details. For variadic parameter functions, e.g.
template<typename>
struct fex_gen_type {};
template<auto, int, typename = void>
struct fex_gen_param {};
template<>
struct fex_gen_type<BIO> : fexgen::opaque_type {};
template<>
struct fex_gen_config<fex_internal_BIO_printf> : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint {};
extern "C" {
int BIO_printf(BIO* bio, const char* format, ...) {
va_list ap;
va_start(ap, format);
int result = fexfn_pack_fex_internal_BIO_printf(bio, format, &ap);
va_end(ap);
return result;
}
int BIO_vprintf(BIO* bio, const char* format, va_list sysv_vaargs) {
return fexfn_pack_fex_internal_BIO_printf(bio, format, &sysv_vaargs);
}
}
static int FEXFN_IMPL(fex_internal_BIO_printf)(BIO* bio, const char* format, void* sysv_vaargs) {
auto x64_vaargs = reinterpret_cast<x64_va_list_s*>(sysv_vaargs);
va_list host_ap;
host_ap.__gr_offs = x64_vaargs->gp_offset - (6 * 8);
host_ap.__vr_offs = x64_vaargs->fp_offset - ((6 * 8) + (8 * 16));
host_ap.__stack = x64_vaargs->overflow_arg_area;
host_ap.__gr_top = reinterpret_cast<char*>(x64_vaargs->reg_save_area) + (6 * 8);
host_ap.__vr_top = reinterpret_cast<char*>(x64_vaargs->reg_save_area) + ((6 * 8) + (8 * 16));
if (LDR_PTR(BIO_vprintf) == nullptr) {
(void*&)LDR_PTR(BIO_vprintf) = dlsym_default(fexldr_ptr_libcrypto3_so, "BIO_vprintf");
}
return LDR_PTR(BIO_vprintf)(bio, format, host_ap);
}For functions with multi function pointers(Single-direction setup, later only used internally; the guest side will need to read function pointers through other external interfaces going forward). Inspired by libwayland-client, pass thoes pointers as
extern "C" {
int CRYPTO_get_ex_new_index(int a_0, long a_1, void* a_2, CRYPTO_EX_new* new_func, CRYPTO_EX_dup* dup_func, CRYPTO_EX_free* free_func) {
uint64_t host_callbacks[3];
host_callbacks[0] = CryptoAllocateHostTrampolineForGuestFunc(new_func);
host_callbacks[1] = CryptoAllocateHostTrampolineForGuestFunc(dup_func);
host_callbacks[2] = CryptoAllocateHostTrampolineForGuestFunc(free_func);
return fexfn_pack_fex_internal_CRYPTO_get_ex_new_index(a_0, a_1, a_2, (void (**)())host_callbacks);
}
}
static int FEXFN_IMPL(fex_internal_CRYPTO_get_ex_new_index)(int a_0, long a_1, void* a_2, guest_layout<void (**)(void)> a_3) {
// Replace guest-provided callback table with host-callable function pointers
auto callbacks = a_3.force_get_host_pointer();
auto new_func = (CRYPTO_EX_new*)callbacks[0];
auto dup_func = (CRYPTO_EX_dup*)callbacks[1];
auto free_func = (CRYPTO_EX_free*)callbacks[2];
FinalizeHostTrampolineForGuestFunction(new_func);
FinalizeHostTrampolineForGuestFunction(dup_func);
FinalizeHostTrampolineForGuestFunction(free_func);
if (LDR_PTR(CRYPTO_get_ex_new_index) == nullptr) {
(void*&)LDR_PTR(CRYPTO_get_ex_new_index) = dlsym_default(fexldr_ptr_libcrypto3_so, "CRYPTO_get_ex_new_index");
}
return LDR_PTR(CRYPTO_get_ex_new_index)(a_0, a_1, a_2, new_func, dup_func, free_func);
}But, for function pointers that need to be read later, e.g. @Sonicadvance1 Do you know any method base in current code base to handle the lasted case? I can do the rest tedious work by myself. |
Uh oh!
There was an error while loading. Please reload this page.
Is there any plan to support library forwarding for openssl(libcrypto.so and libssl.so)?
All reactions