Fri, 24 Jul 2009 12:40:40 -0700
6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
Reviewed-by: kvn, twisti
1.1 --- a/agent/make/saenv.sh Fri Jul 24 09:01:00 2009 -0700 1.2 +++ b/agent/make/saenv.sh Fri Jul 24 12:40:40 2009 -0700 1.3 @@ -48,6 +48,8 @@ 1.4 CPU=i386 1.5 fi 1.6 else 1.7 + LD_AUDIT_32=$STARTDIR/../src/os/solaris/proc/`uname -p`/libsaproc_audit.so 1.8 + export LD_AUDIT_32 1.9 SA_LIBPATH=$STARTDIR/../src/os/solaris/proc/`uname -p`:$STARTDIR/solaris/`uname -p` 1.10 OPTIONS="-Dsa.library.path=$SA_LIBPATH -Dsun.jvm.hotspot.debugger.useProcDebugger" 1.11 CPU=sparc
2.1 --- a/agent/make/saenv64.sh Fri Jul 24 09:01:00 2009 -0700 2.2 +++ b/agent/make/saenv64.sh Fri Jul 24 12:40:40 2009 -0700 2.3 @@ -43,6 +43,8 @@ 2.4 fi 2.5 fi 2.6 2.7 +LD_AUDIT_64=$STARTDIR/../src/os/solaris/proc/$CPU/libsaproc_audit.so 2.8 +export LD_AUDIT_64 2.9 SA_LIBPATH=$STARTDIR/../src/os/solaris/proc/$CPU:$STARTDIR/solaris/$CPU 2.10 2.11 OPTIONS="-Dsa.library.path=$SA_LIBPATH -Dsun.jvm.hotspot.debugger.useProcDebugger"
3.1 --- a/agent/src/os/solaris/proc/Makefile Fri Jul 24 09:01:00 2009 -0700 3.2 +++ b/agent/src/os/solaris/proc/Makefile Fri Jul 24 12:40:40 2009 -0700 3.3 @@ -56,24 +56,28 @@ 3.4 @javah -classpath $(CLASSES_DIR) -jni sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal 3.5 CC -G -KPIC -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris saproc.cpp \ 3.6 -M mapfile -o $@/libsaproc.so -ldemangle 3.7 + CC -o $@/libsaproc_audit.so -G -Kpic -z defs saproc_audit.cpp -lmapmalloc -ldl -lc 3.8 3.9 amd64:: javahomecheck 3.10 $(MKDIRS) $@ 3.11 @javah -classpath $(CLASSES_DIR) -jni sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal 3.12 CC -G -KPIC -xarch=amd64 -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris saproc.cpp \ 3.13 -M mapfile -o $@/libsaproc.so -ldemangle 3.14 + CC -xarch=amd64 -o $@/libsaproc_audit.so -G -Kpic -z defs saproc_audit.cpp -lmapmalloc -ldl -lc 3.15 3.16 sparc:: javahomecheck 3.17 $(MKDIRS) $@ 3.18 @javah -classpath $(CLASSES_DIR) -jni sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal 3.19 CC -G -KPIC -xarch=v8 -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris saproc.cpp \ 3.20 -M mapfile -o $@/libsaproc.so -ldemangle 3.21 + CC -xarch=v8 -o $@/libsaproc_audit.so -G -Kpic -z defs saproc_audit.cpp -lmapmalloc -ldl -lc 3.22 3.23 sparcv9:: javahomecheck 3.24 $(MKDIRS) $@ 3.25 @javah -classpath $(CLASSES_DIR) -jni sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal 3.26 CC -G -KPIC -xarch=v9 -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris saproc.cpp \ 3.27 -M mapfile -o $@/libsaproc.so -ldemangle 3.28 + CC -xarch=v9 -o $@/libsaproc_audit.so -G -Kpic -z defs saproc_audit.cpp -lmapmalloc -ldl -lc 3.29 3.30 clean:: 3.31 $(RM) -rf sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal.h
4.1 --- a/agent/src/os/solaris/proc/mapfile Fri Jul 24 09:01:00 2009 -0700 4.2 +++ b/agent/src/os/solaris/proc/mapfile Fri Jul 24 12:40:40 2009 -0700 4.3 @@ -45,6 +45,8 @@ 4.4 Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_resume0; 4.5 Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_suspend0; 4.6 Java_sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal_writeBytesToProcess0; 4.7 + # this is needed by saproc_audit.c to redirect opens in libproc.so 4.8 + libsaproc_open; 4.9 local: 4.10 *; 4.11 };
5.1 --- a/agent/src/os/solaris/proc/saproc.cpp Fri Jul 24 09:01:00 2009 -0700 5.2 +++ b/agent/src/os/solaris/proc/saproc.cpp Fri Jul 24 12:40:40 2009 -0700 5.3 @@ -214,49 +214,58 @@ 5.4 } 5.5 } 5.6 5.7 -static int find_file_hook(const char * name, int elf_checksum) { 5.8 - init_alt_root(); 5.9 +// This function is a complete substitute for the open system call 5.10 +// since it's also used to override open calls from libproc to 5.11 +// implement as a pathmap style facility for the SA. If libproc 5.12 +// starts using other interfaces then this might have to extended to 5.13 +// cover other calls. 5.14 +extern "C" int libsaproc_open(const char * name, int oflag, ...) { 5.15 + if (oflag == O_RDONLY) { 5.16 + init_alt_root(); 5.17 5.18 - if (_libsaproc_debug) { 5.19 - printf("libsaproc DEBUG: find_file_hook %s 0x%x\n", name, elf_checksum); 5.20 - } 5.21 - 5.22 - if (alt_root_len > 0) { 5.23 - int fd = -1; 5.24 - char alt_path[PATH_MAX+1]; 5.25 - 5.26 - strcpy(alt_path, alt_root); 5.27 - strcat(alt_path, name); 5.28 - fd = open(alt_path, O_RDONLY); 5.29 - if (fd >= 0) { 5.30 - if (_libsaproc_debug) { 5.31 - printf("libsaproc DEBUG: find_file_hook substituted %s\n", alt_path); 5.32 - } 5.33 - return fd; 5.34 + if (_libsaproc_debug) { 5.35 + printf("libsaproc DEBUG: libsaproc_open %s\n", name); 5.36 } 5.37 5.38 - if (strrchr(name, '/')) { 5.39 + if (alt_root_len > 0) { 5.40 + int fd = -1; 5.41 + char alt_path[PATH_MAX+1]; 5.42 + 5.43 strcpy(alt_path, alt_root); 5.44 - strcat(alt_path, strrchr(name, '/')); 5.45 + strcat(alt_path, name); 5.46 fd = open(alt_path, O_RDONLY); 5.47 if (fd >= 0) { 5.48 if (_libsaproc_debug) { 5.49 - printf("libsaproc DEBUG: find_file_hook substituted %s\n", alt_path); 5.50 + printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path); 5.51 } 5.52 return fd; 5.53 } 5.54 + 5.55 + if (strrchr(name, '/')) { 5.56 + strcpy(alt_path, alt_root); 5.57 + strcat(alt_path, strrchr(name, '/')); 5.58 + fd = open(alt_path, O_RDONLY); 5.59 + if (fd >= 0) { 5.60 + if (_libsaproc_debug) { 5.61 + printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path); 5.62 + } 5.63 + return fd; 5.64 + } 5.65 + } 5.66 } 5.67 } 5.68 - return -1; 5.69 + 5.70 + { 5.71 + mode_t mode; 5.72 + va_list ap; 5.73 + va_start(ap, oflag); 5.74 + mode = va_arg(ap, mode_t); 5.75 + va_end(ap); 5.76 + 5.77 + return open(name, oflag, mode); 5.78 + } 5.79 } 5.80 5.81 -static int pathmap_open(const char* name) { 5.82 - int fd = open(name, O_RDONLY); 5.83 - if (fd < 0) { 5.84 - fd = find_file_hook(name, 0); 5.85 - } 5.86 - return fd; 5.87 -} 5.88 5.89 static void * pathmap_dlopen(const char * name, int mode) { 5.90 init_alt_root(); 5.91 @@ -608,7 +617,7 @@ 5.92 print_debug("looking for %s\n", classes_jsa); 5.93 5.94 // open the classes[_g].jsa 5.95 - int fd = pathmap_open(classes_jsa); 5.96 + int fd = libsaproc_open(classes_jsa, O_RDONLY); 5.97 if (fd < 0) { 5.98 char errMsg[ERR_MSG_SIZE]; 5.99 sprintf(errMsg, "can't open shared archive file %s", classes_jsa); 5.100 @@ -1209,8 +1218,6 @@ 5.101 return res; 5.102 } 5.103 5.104 -typedef int (*find_file_hook_t)(const char *, int elf_checksum); 5.105 - 5.106 /* 5.107 * Class: sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal 5.108 * Method: initIDs 5.109 @@ -1230,16 +1237,6 @@ 5.110 if (libproc_handle == 0) 5.111 THROW_NEW_DEBUGGER_EXCEPTION("can't load libproc.so, if you are using Solaris 5.7 or below, copy libproc.so from 5.8!"); 5.112 5.113 - // If possible, set shared object find file hook. 5.114 - void (*set_hook)(find_file_hook_t) = (void(*)(find_file_hook_t))dlsym(libproc_handle, "Pset_find_file_hook"); 5.115 - if (set_hook) { 5.116 - // we found find file hook symbol, set up our hook function. 5.117 - set_hook(find_file_hook); 5.118 - } else if (getenv(SA_ALTROOT)) { 5.119 - printf("libsaproc WARNING: %s set, but can't set file hook. " \ 5.120 - "Did you use right version of libproc.so?\n", SA_ALTROOT); 5.121 - } 5.122 - 5.123 p_ps_prochandle_ID = env->GetFieldID(clazz, "p_ps_prochandle", "J"); 5.124 CHECK_EXCEPTION; 5.125
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/agent/src/os/solaris/proc/saproc_audit.cpp Fri Jul 24 12:40:40 2009 -0700 6.3 @@ -0,0 +1,98 @@ 6.4 +/* 6.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 6.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 6.24 + * have any questions. 6.25 + * 6.26 + */ 6.27 + 6.28 +#include <link.h> 6.29 +#include <stdio.h> 6.30 +#include <stdlib.h> 6.31 +#include <string.h> 6.32 +#include <sys/types.h> 6.33 +#include <sys/stat.h> 6.34 +#include <fcntl.h> 6.35 +#include <limits.h> 6.36 +#include <varargs.h> 6.37 + 6.38 +// This class sets up an interposer on open calls from libproc.so to 6.39 +// support a pathmap facility in the SA. 6.40 + 6.41 +static uintptr_t* libproc_cookie; 6.42 +static uintptr_t* libc_cookie; 6.43 +static uintptr_t* libsaproc_cookie; 6.44 + 6.45 + 6.46 +uint_t 6.47 +la_version(uint_t version) 6.48 +{ 6.49 + return (LAV_CURRENT); 6.50 +} 6.51 + 6.52 + 6.53 +uint_t 6.54 +la_objopen(Link_map * lmp, Lmid_t lmid, uintptr_t * cookie) 6.55 +{ 6.56 + if (strstr(lmp->l_name, "/libproc.so") != NULL) { 6.57 + libproc_cookie = cookie; 6.58 + return LA_FLG_BINDFROM; 6.59 + } 6.60 + if (strstr(lmp->l_name, "/libc.so") != NULL) { 6.61 + libc_cookie = cookie; 6.62 + return LA_FLG_BINDTO; 6.63 + } 6.64 + if (strstr(lmp->l_name, "/libsaproc.so") != NULL) { 6.65 + libsaproc_cookie = cookie; 6.66 + return LA_FLG_BINDTO | LA_FLG_BINDFROM; 6.67 + } 6.68 + return 0; 6.69 +} 6.70 + 6.71 + 6.72 +#if defined(_LP64) 6.73 +uintptr_t 6.74 +la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook, 6.75 + uintptr_t *defcook, uint_t *sb_flags, const char *sym_name) 6.76 +#else 6.77 +uintptr_t 6.78 +la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook, 6.79 + uintptr_t *defcook, uint_t *sb_flags) 6.80 +#endif 6.81 +{ 6.82 +#if !defined(_LP64) 6.83 + const char *sym_name = (const char *)symp->st_name; 6.84 +#endif 6.85 + if (strcmp(sym_name, "open") == 0 && refcook == libproc_cookie) { 6.86 + // redirect all open calls from libproc.so through libsaproc_open which will 6.87 + // try the alternate library locations first. 6.88 + void* handle = dlmopen(LM_ID_BASE, "libsaproc.so", RTLD_NOLOAD); 6.89 + if (handle == NULL) { 6.90 + fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc.so during linking\n"); 6.91 + } else { 6.92 + uintptr_t libsaproc_open = (uintptr_t)dlsym(handle, "libsaproc_open"); 6.93 + if (libsaproc_open == 0) { 6.94 + fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc_open during linking\n"); 6.95 + } else { 6.96 + return libsaproc_open; 6.97 + } 6.98 + } 6.99 + } 6.100 + return symp->st_value; 6.101 +}