< prev index next >

src/jdk.hotspot.agent/share/native/libsaproc/sadis.c

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  47 #endif
  48 
  49 #else
  50 
  51 #include <string.h>
  52 #include <dlfcn.h>
  53 
  54 #ifndef __APPLE__
  55 #include <link.h>
  56 #endif
  57 
  58 #endif
  59 
  60 #include <limits.h>
  61 #include <stdio.h>
  62 #include <stdarg.h>
  63 #include <stdlib.h>
  64 #include <errno.h>
  65 
  66 #ifdef _WINDOWS














  67 static int getLastErrorString(char *buf, size_t len)
  68 {
  69     long errval;
  70 
  71     if ((errval = GetLastError()) != 0)
  72     {
  73       /* DOS error */
  74       size_t n = (size_t)FormatMessage(
  75             FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  76             NULL,
  77             errval,
  78             0,
  79             buf,
  80             (DWORD)len,
  81             NULL);
  82       if (n > 3) {
  83         /* Drop final '.', CR, LF */
  84         if (buf[n - 1] == '\n') n--;
  85         if (buf[n - 1] == '\r') n--;
  86         if (buf[n - 1] == '.') n--;


  95       strerror_s(buf, len, errno);
  96       return strlen(buf);
  97     }
  98     return 0;
  99 }
 100 #endif /* _WINDOWS */
 101 
 102 /*
 103  * Class:     sun_jvm_hotspot_asm_Disassembler
 104  * Method:    load_library
 105  * Signature: (Ljava/lang/String;)L
 106  */
 107 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIEnv * env,
 108                                                                            jclass disclass,
 109                                                                            jstring jrepath_s,
 110                                                                            jstring libname_s) {
 111   uintptr_t func = 0;
 112   const char *error_message = NULL;
 113   const char *jrepath = NULL;
 114   const char *libname = NULL;
 115   char buffer[128];
 116 
 117 #ifdef _WINDOWS
 118   HINSTANCE hsdis_handle = (HINSTANCE) NULL;
 119 #else
 120   void* hsdis_handle = NULL;
 121 #endif
 122 
 123   jrepath = (*env)->GetStringUTFChars(env, jrepath_s, NULL); // like $JAVA_HOME/jre/lib/sparc/
 124   if (jrepath == NULL || (*env)->ExceptionOccurred(env)) {
 125     return 0;
 126   }
 127 
 128   libname = (*env)->GetStringUTFChars(env, libname_s, NULL);
 129   if (libname == NULL || (*env)->ExceptionOccurred(env)) {
 130     (*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath);
 131     return 0;
 132   }
 133 
 134   /* Load the hsdis library */
 135 #ifdef _WINDOWS


   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  47 #endif
  48 
  49 #else
  50 
  51 #include <string.h>
  52 #include <dlfcn.h>
  53 
  54 #ifndef __APPLE__
  55 #include <link.h>
  56 #endif
  57 
  58 #endif
  59 
  60 #include <limits.h>
  61 #include <stdio.h>
  62 #include <stdarg.h>
  63 #include <stdlib.h>
  64 #include <errno.h>
  65 
  66 #ifdef _WINDOWS
  67 #define JVM_MAXPATHLEN _MAX_PATH
  68 #else
  69 #include <sys/param.h>
  70 
  71 #if defined(AIX) || defined(SOLARIS)
  72 #define JVM_MAXPATHLEN MAXPATHLEN
  73 #else
  74 #define JVM_MAXPATHLEN MAXPATHLEN + 1
  75 #endif
  76 
  77 #endif
  78 
  79 
  80 #ifdef _WINDOWS
  81 static int getLastErrorString(char *buf, size_t len)
  82 {
  83     long errval;
  84 
  85     if ((errval = GetLastError()) != 0)
  86     {
  87       /* DOS error */
  88       size_t n = (size_t)FormatMessage(
  89             FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  90             NULL,
  91             errval,
  92             0,
  93             buf,
  94             (DWORD)len,
  95             NULL);
  96       if (n > 3) {
  97         /* Drop final '.', CR, LF */
  98         if (buf[n - 1] == '\n') n--;
  99         if (buf[n - 1] == '\r') n--;
 100         if (buf[n - 1] == '.') n--;


 109       strerror_s(buf, len, errno);
 110       return strlen(buf);
 111     }
 112     return 0;
 113 }
 114 #endif /* _WINDOWS */
 115 
 116 /*
 117  * Class:     sun_jvm_hotspot_asm_Disassembler
 118  * Method:    load_library
 119  * Signature: (Ljava/lang/String;)L
 120  */
 121 JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIEnv * env,
 122                                                                            jclass disclass,
 123                                                                            jstring jrepath_s,
 124                                                                            jstring libname_s) {
 125   uintptr_t func = 0;
 126   const char *error_message = NULL;
 127   const char *jrepath = NULL;
 128   const char *libname = NULL;
 129   char buffer[JVM_MAXPATHLEN];
 130 
 131 #ifdef _WINDOWS
 132   HINSTANCE hsdis_handle = (HINSTANCE) NULL;
 133 #else
 134   void* hsdis_handle = NULL;
 135 #endif
 136 
 137   jrepath = (*env)->GetStringUTFChars(env, jrepath_s, NULL); // like $JAVA_HOME/jre/lib/sparc/
 138   if (jrepath == NULL || (*env)->ExceptionOccurred(env)) {
 139     return 0;
 140   }
 141 
 142   libname = (*env)->GetStringUTFChars(env, libname_s, NULL);
 143   if (libname == NULL || (*env)->ExceptionOccurred(env)) {
 144     (*env)->ReleaseStringUTFChars(env, jrepath_s, jrepath);
 145     return 0;
 146   }
 147 
 148   /* Load the hsdis library */
 149 #ifdef _WINDOWS


< prev index next >