@@ -2481,3 +2481,61 @@ jint os::set_minimum_stack_sizes() {
2481
2481
}
2482
2482
return JNI_OK;
2483
2483
}
2484
+
2485
+ // Builds a platform dependent Agent_OnLoad_<lib_name> function name
2486
+ // which is used to find statically linked in agents.
2487
+ // Parameters:
2488
+ // sym_name: Symbol in library we are looking for
2489
+ // lib_name: Name of library to look in, null for shared libs.
2490
+ // is_absolute_path == true if lib_name is absolute path to agent
2491
+ // such as "C:/a/b/L.dll" or "/a/b/libL.so"
2492
+ // == false if only the base name of the library is passed in
2493
+ // such as "L"
2494
+ char * os::build_agent_function_name (const char *sym_name, const char *lib_name,
2495
+ bool is_absolute_path) {
2496
+ char *agent_entry_name;
2497
+ size_t len = 0 ;
2498
+ size_t name_len = 0 ;
2499
+ size_t prefix_len = strlen (JNI_LIB_PREFIX);
2500
+ size_t suffix_len = strlen (JNI_LIB_SUFFIX);
2501
+ size_t underscore_len = 0 ; // optional underscore if lib_name is set
2502
+ const char *start;
2503
+
2504
+ if (lib_name != nullptr ) {
2505
+ if (is_absolute_path) {
2506
+ // Need to strip path, prefix and suffix
2507
+ if ((start = strrchr (lib_name, *os::file_separator ())) != nullptr ) {
2508
+ lib_name = ++start;
2509
+ }
2510
+ #ifdef WINDOWS
2511
+ else { // Need to check for drive prefix e.g. C:L.dll
2512
+ if ((start = strchr (lib_name, ' :' )) != nullptr ) {
2513
+ lib_name = ++start;
2514
+ }
2515
+ }
2516
+ #endif
2517
+ name_len = strlen (lib_name);
2518
+ if (name_len <= (prefix_len + suffix_len)) {
2519
+ return nullptr ;
2520
+ }
2521
+ lib_name += prefix_len;
2522
+ name_len = strlen (lib_name) - suffix_len;
2523
+ } else {
2524
+ name_len = strlen (lib_name);
2525
+ }
2526
+ underscore_len = 1 ;
2527
+ }
2528
+ // Total buffer length to allocate - includes null terminator.
2529
+ len = strlen (sym_name) + underscore_len + name_len + 1 ;
2530
+ agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL (char , len, mtThread);
2531
+ if (agent_entry_name == nullptr ) {
2532
+ return nullptr ;
2533
+ }
2534
+
2535
+ strcpy (agent_entry_name, sym_name);
2536
+ if (lib_name != nullptr ) {
2537
+ strcat (agent_entry_name, " _" );
2538
+ strncat (agent_entry_name, lib_name, name_len);
2539
+ }
2540
+ return agent_entry_name;
2541
+ }
0 commit comments