Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/solaris/proc/saproc_audit.cpp
38840 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include <link.h>25#include <stdio.h>26#include <stdlib.h>27#include <string.h>28#include <sys/types.h>29#include <sys/stat.h>30#include <fcntl.h>31#include <limits.h>32#include <varargs.h>3334// This class sets up an interposer on open calls from libproc.so to35// support a pathmap facility in the SA.3637static uintptr_t* libproc_cookie;38static uintptr_t* libc_cookie;39static uintptr_t* libsaproc_cookie;404142uint_t43la_version(uint_t version)44{45return (LAV_CURRENT);46}474849uint_t50la_objopen(Link_map * lmp, Lmid_t lmid, uintptr_t * cookie)51{52if (strstr(lmp->l_name, "/libproc.so") != NULL) {53libproc_cookie = cookie;54return LA_FLG_BINDFROM;55}56if (strstr(lmp->l_name, "/libc.so") != NULL) {57libc_cookie = cookie;58return LA_FLG_BINDTO;59}60if (strstr(lmp->l_name, "/libsaproc.so") != NULL) {61libsaproc_cookie = cookie;62return LA_FLG_BINDTO | LA_FLG_BINDFROM;63}64return 0;65}666768#if defined(_LP64)69uintptr_t70la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook,71uintptr_t *defcook, uint_t *sb_flags, const char *sym_name)72#else73uintptr_t74la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook,75uintptr_t *defcook, uint_t *sb_flags)76#endif77{78#if !defined(_LP64)79const char *sym_name = (const char *)symp->st_name;80#endif81if (strcmp(sym_name, "open") == 0 && refcook == libproc_cookie) {82// redirect all open calls from libproc.so through libsaproc_open which will83// try the alternate library locations first.84void* handle = dlmopen(LM_ID_BASE, "libsaproc.so", RTLD_NOLOAD);85if (handle == NULL) {86fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc.so during linking\n");87} else {88uintptr_t libsaproc_open = (uintptr_t)dlsym(handle, "libsaproc_open");89if (libsaproc_open == 0) {90fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc_open during linking\n");91} else {92return libsaproc_open;93}94}95}96return symp->st_value;97}9899100