annotate agent/src/os/solaris/proc/saproc_audit.cpp @ 892:a94af87c3357

6861984: solaris version of libsaproc.so should support SA_ALTROOT directly Reviewed-by: kvn, twisti
author never
date Fri, 24 Jul 2009 12:40:40 -0700
parents
children
rev   line source
never@892 1 /*
never@892 2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
never@892 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@892 4 *
never@892 5 * This code is free software; you can redistribute it and/or modify it
never@892 6 * under the terms of the GNU General Public License version 2 only, as
never@892 7 * published by the Free Software Foundation.
never@892 8 *
never@892 9 * This code is distributed in the hope that it will be useful, but WITHOUT
never@892 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@892 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@892 12 * version 2 for more details (a copy is included in the LICENSE file that
never@892 13 * accompanied this code).
never@892 14 *
never@892 15 * You should have received a copy of the GNU General Public License version
never@892 16 * 2 along with this work; if not, write to the Free Software Foundation,
never@892 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@892 18 *
never@892 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
never@892 20 * CA 95054 USA or visit www.sun.com if you need additional information or
never@892 21 * have any questions.
never@892 22 *
never@892 23 */
never@892 24
never@892 25 #include <link.h>
never@892 26 #include <stdio.h>
never@892 27 #include <stdlib.h>
never@892 28 #include <string.h>
never@892 29 #include <sys/types.h>
never@892 30 #include <sys/stat.h>
never@892 31 #include <fcntl.h>
never@892 32 #include <limits.h>
never@892 33 #include <varargs.h>
never@892 34
never@892 35 // This class sets up an interposer on open calls from libproc.so to
never@892 36 // support a pathmap facility in the SA.
never@892 37
never@892 38 static uintptr_t* libproc_cookie;
never@892 39 static uintptr_t* libc_cookie;
never@892 40 static uintptr_t* libsaproc_cookie;
never@892 41
never@892 42
never@892 43 uint_t
never@892 44 la_version(uint_t version)
never@892 45 {
never@892 46 return (LAV_CURRENT);
never@892 47 }
never@892 48
never@892 49
never@892 50 uint_t
never@892 51 la_objopen(Link_map * lmp, Lmid_t lmid, uintptr_t * cookie)
never@892 52 {
never@892 53 if (strstr(lmp->l_name, "/libproc.so") != NULL) {
never@892 54 libproc_cookie = cookie;
never@892 55 return LA_FLG_BINDFROM;
never@892 56 }
never@892 57 if (strstr(lmp->l_name, "/libc.so") != NULL) {
never@892 58 libc_cookie = cookie;
never@892 59 return LA_FLG_BINDTO;
never@892 60 }
never@892 61 if (strstr(lmp->l_name, "/libsaproc.so") != NULL) {
never@892 62 libsaproc_cookie = cookie;
never@892 63 return LA_FLG_BINDTO | LA_FLG_BINDFROM;
never@892 64 }
never@892 65 return 0;
never@892 66 }
never@892 67
never@892 68
never@892 69 #if defined(_LP64)
never@892 70 uintptr_t
never@892 71 la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook,
never@892 72 uintptr_t *defcook, uint_t *sb_flags, const char *sym_name)
never@892 73 #else
never@892 74 uintptr_t
never@892 75 la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook,
never@892 76 uintptr_t *defcook, uint_t *sb_flags)
never@892 77 #endif
never@892 78 {
never@892 79 #if !defined(_LP64)
never@892 80 const char *sym_name = (const char *)symp->st_name;
never@892 81 #endif
never@892 82 if (strcmp(sym_name, "open") == 0 && refcook == libproc_cookie) {
never@892 83 // redirect all open calls from libproc.so through libsaproc_open which will
never@892 84 // try the alternate library locations first.
never@892 85 void* handle = dlmopen(LM_ID_BASE, "libsaproc.so", RTLD_NOLOAD);
never@892 86 if (handle == NULL) {
never@892 87 fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc.so during linking\n");
never@892 88 } else {
never@892 89 uintptr_t libsaproc_open = (uintptr_t)dlsym(handle, "libsaproc_open");
never@892 90 if (libsaproc_open == 0) {
never@892 91 fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc_open during linking\n");
never@892 92 } else {
never@892 93 return libsaproc_open;
never@892 94 }
never@892 95 }
never@892 96 }
never@892 97 return symp->st_value;
never@892 98 }