< 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 #define JVM_MAXPATHLEN MAXPATHLEN
  71 #endif
  72 
  73 
  74 #ifdef _WINDOWS
  75 static int getLastErrorString(char *buf, size_t len)
  76 {
  77     long errval;
  78 
  79     if ((errval = GetLastError()) != 0)
  80     {
  81       /* DOS error */
  82       size_t n = (size_t)FormatMessage(
  83             FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  84             NULL,
  85             errval,
  86             0,
  87             buf,
  88             (DWORD)len,
  89             NULL);
  90       if (n > 3) {
  91         /* Drop final '.', CR, LF */
  92         if (buf[n - 1] == '\n') n--;
  93         if (buf[n - 1] == '\r') n--;
  94         if (buf[n - 1] == '.') n--;


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


< prev index next >