src/jdk.hotspot.agent/solaris/native/libsaproc/saproc_audit.cpp
author mdoerr
Tue, 20 Feb 2018 16:10:21 +0100
changeset 49027 8dc742d9bbab
parent 47216 71c04702a3d5
permissions -rw-r--r--
8195112: x86 (32 bit): implementation for Thread-local handshakes Reviewed-by: goetz, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     4
 *
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     8
 *
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    13
 * accompanied this code).
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    14
 *
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3592
diff changeset
    21
 * questions.
3592
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    22
 *
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    23
 */
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    24
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    25
#include <link.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    26
#include <stdio.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    27
#include <stdlib.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    28
#include <string.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    29
#include <sys/types.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    30
#include <sys/stat.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    31
#include <fcntl.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    32
#include <limits.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    33
#include <varargs.h>
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    34
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    35
// This class sets up an interposer on open calls from libproc.so to
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    36
// support a pathmap facility in the SA.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    37
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    38
static uintptr_t* libproc_cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    39
static uintptr_t* libc_cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    40
static uintptr_t* libsaproc_cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    41
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    42
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    43
uint_t
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    44
la_version(uint_t version)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    45
{
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    46
  return (LAV_CURRENT);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    47
}
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    48
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    49
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    50
uint_t
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    51
la_objopen(Link_map * lmp, Lmid_t lmid, uintptr_t * cookie)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    52
{
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    53
  if (strstr(lmp->l_name, "/libproc.so") != NULL) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    54
    libproc_cookie = cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    55
    return LA_FLG_BINDFROM;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    56
  }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    57
  if (strstr(lmp->l_name, "/libc.so") != NULL) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    58
    libc_cookie = cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    59
    return LA_FLG_BINDTO;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    60
  }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    61
  if (strstr(lmp->l_name, "/libsaproc.so") != NULL) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    62
    libsaproc_cookie = cookie;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    63
    return LA_FLG_BINDTO | LA_FLG_BINDFROM;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    64
  }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    65
  return 0;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    66
}
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    67
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    68
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    69
#if     defined(_LP64)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    70
uintptr_t
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    71
la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook,
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    72
             uintptr_t *defcook, uint_t *sb_flags, const char *sym_name)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    73
#else
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    74
uintptr_t
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    75
la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook,
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    76
             uintptr_t *defcook, uint_t *sb_flags)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    77
#endif
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    78
{
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    79
#if     !defined(_LP64)
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    80
  const char      *sym_name = (const char *)symp->st_name;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    81
#endif
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    82
  if (strcmp(sym_name, "open") == 0 && refcook == libproc_cookie) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    83
    // redirect all open calls from libproc.so through libsaproc_open which will
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    84
    // try the alternate library locations first.
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    85
    void* handle = dlmopen(LM_ID_BASE, "libsaproc.so", RTLD_NOLOAD);
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    86
    if (handle == NULL) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    87
      fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc.so during linking\n");
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    88
    } else {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    89
      uintptr_t libsaproc_open = (uintptr_t)dlsym(handle, "libsaproc_open");
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    90
      if (libsaproc_open == 0) {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    91
        fprintf(stderr, "libsaproc_audit.so: didn't find libsaproc_open during linking\n");
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    92
      } else {
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    93
        return libsaproc_open;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    94
      }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    95
    }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    96
  }
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    97
  return symp->st_value;
857575a0a200 6861984: solaris version of libsaproc.so should support SA_ALTROOT directly
never
parents:
diff changeset
    98
}