Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPTCH-3534: Use already loaded version of JSCoreGTK if available #77

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions execute_jscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <string.h>

#include <dlfcn.h>
#ifndef __APPLE__
# include <link.h>
#endif

#include <JavaScriptCore/JavaScript.h>

Expand Down Expand Up @@ -376,13 +379,32 @@
g_proxy_execute_jscore.module = dlopen(
"/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore", RTLD_LAZY | RTLD_LOCAL);
#else
g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-4.1.so.0", RTLD_LAZY | RTLD_LOCAL);
if (!g_proxy_execute_jscore.module)
g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-4.0.so.18", RTLD_LAZY | RTLD_LOCAL);
if (!g_proxy_execute_jscore.module)
g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-3.0.so.0", RTLD_LAZY | RTLD_LOCAL);
if (!g_proxy_execute_jscore.module)
g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-1.0.so.0", RTLD_LAZY | RTLD_LOCAL);
const char *library_names[] = {"libjavascriptcoregtk-4.1.so.0", "libjavascriptcoregtk-4.0.so.18",
"libjavascriptcoregtk-3.0.so.0", "libjavascriptcoregtk-1.0.so.0"};
const size_t library_names_size = sizeof(library_names) / sizeof(library_names[0]);

// Use existing JavaScriptCoreGTK if already loaded
struct link_map *map = NULL;
void *current_process = dlopen(0, RTLD_LAZY);
if (!current_process)
return false;

Check warning on line 390 in execute_jscore.c

View check run for this annotation

Codecov / codecov/patch

execute_jscore.c#L390

Added line #L390 was not covered by tests
if (dlinfo(current_process, RTLD_DI_LINKMAP, &map) == 0) {
while (map && !g_proxy_execute_jscore.module) {
for (size_t i = 0; i < library_names_size; i++) {
if (strstr(map->l_name, library_names[i])) {
g_proxy_execute_jscore.module = dlopen(map->l_name, RTLD_NOLOAD | RTLD_LAZY | RTLD_LOCAL);
break;

Check warning on line 396 in execute_jscore.c

View check run for this annotation

Codecov / codecov/patch

execute_jscore.c#L395-L396

Added lines #L395 - L396 were not covered by tests
}
}
map = map->l_next;
}
}
dlclose(current_process);

// Load the first available version of the JavaScriptCoreGTK
for (size_t i = 0; !g_proxy_execute_jscore.module && i < library_names_size; i++) {
g_proxy_execute_jscore.module = dlopen(library_names[i], RTLD_LAZY | RTLD_LOCAL);
}
#endif

if (!g_proxy_execute_jscore.module)
Expand Down
Loading