Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259045: Exception message from saproc.dll is garbled on Windows with…
… Japanese locale

Reviewed-by: erikj, cjplummer, iklam
  • Loading branch information
YaSuenag committed Jan 6, 2021
1 parent 28e1f4d commit 67c221148159d94142a3a6d9ddadce2dff8c858b
Showing with 12 additions and 45 deletions.
  1. +5 −4 make/modules/jdk.hotspot.agent/Lib.gmk
  2. +7 −41 src/jdk.hotspot.agent/share/native/libsaproc/sadis.c
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@ else ifeq ($(call isTargetOs, macosx), true)
-mstack-alignment=16 -fPIC
LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent
else ifeq ($(call isTargetOs, windows), true)
SA_CFLAGS := -D_WINDOWS -D_DEBUG -D_CONSOLE -D_MBCS -EHsc
SA_CFLAGS := -D_WINDOWS -D_DEBUG -D_CONSOLE -EHsc
ifeq ($(call isTargetCpu, x86_64), true)
SA_CXXFLAGS := -DWIN64
else
@@ -65,12 +65,13 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBSA, \
CFLAGS := $(CFLAGS_JDKLIB) $(SA_CFLAGS), \
CXXFLAGS := $(CXXFLAGS_JDKLIB) $(SA_CFLAGS) $(SA_CXXFLAGS), \
EXTRA_SRC := $(LIBSA_EXTRA_SRC), \
LDFLAGS := $(LDFLAGS_JDKLIB), \
LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := $(LIBCXX), \
LIBS_unix := -ljava, \
LIBS_linux := $(LIBDL), \
LIBS_macosx := -framework Foundation -framework JavaNativeFoundation \
-framework JavaRuntimeSupport -framework Security -framework CoreFoundation, \
LIBS_windows := dbgeng.lib, \
LIBS_windows := dbgeng.lib $(WIN_JAVA_LIB), \
))

TARGETS += $(BUILD_LIBSA)
@@ -70,42 +70,8 @@
#define JVM_MAXPATHLEN MAXPATHLEN
#endif

#include "jni_util.h"

#ifdef _WINDOWS
static int getLastErrorString(char *buf, size_t len)
{
long errval;

if ((errval = GetLastError()) != 0)
{
/* DOS error */
size_t n = (size_t)FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errval,
0,
buf,
(DWORD)len,
NULL);
if (n > 3) {
/* Drop final '.', CR, LF */
if (buf[n - 1] == '\n') n--;
if (buf[n - 1] == '\r') n--;
if (buf[n - 1] == '.') n--;
buf[n] = '\0';
}
return (int)n;
}

if (errno != 0)
{
/* C runtime error that has no corresponding DOS error code */
strerror_s(buf, len, errno);
return strlen(buf);
}
return 0;
}
#endif /* _WINDOWS */

/*
* Class: sun_jvm_hotspot_asm_Disassembler
@@ -157,13 +123,13 @@ JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIE
/* Couldn't find entry point. error_message should contain some
* platform dependent error message.
*/
jclass eclass = (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException");
if ((*env)->ExceptionOccurred(env)) {
/* Can't throw exception, probably OOM, so silently return 0 */
return (jlong) 0;
jstring s = JNU_NewStringPlatform(env, error_message);
if (s != NULL) {
jobject x = JNU_NewObjectByName(env, "sun/jvm/hotspot/debugger/DebuggerException", "(Ljava/lang/String;)V", s);
if (x != NULL) {
(*env)->Throw(env, x);
}
}

(*env)->ThrowNew(env, eclass, error_message);
}
return (jlong)func;
}

0 comments on commit 67c2211

Please sign in to comment.