Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
f0454b49
Unverified
Commit
f0454b49
authored
Dec 02, 2021
by
Pavel
Committed by
GitHub
Dec 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix segfault on exception log (#417)
parent
688c97fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
36 deletions
+30
-36
build.gradle.kts
samples/SkiaJvmSample/build.gradle.kts
+1
-0
interop.cc
skiko/src/jvmMain/cpp/common/interop.cc
+15
-0
interop.hh
skiko/src/jvmMain/cpp/common/interop.hh
+7
-0
exceptions_handler.cc
skiko/src/jvmMain/cpp/windows/exceptions_handler.cc
+7
-36
No files found.
samples/SkiaJvmSample/build.gradle.kts
View file @
f0454b49
...
...
@@ -56,6 +56,7 @@ val casualRun = tasks.named<JavaExec>("run") {
systemProperty
(
"skiko.win.exception.logger.enabled"
,
"true"
)
systemProperty
(
"skiko.win.exception.handler.enabled"
,
"true"
)
jvmArgs
?.
add
(
"-ea"
)
// jvmArgs?.add("-Xcheck:jni")
// Use systemProperty("skiko.library.path", "/tmp") to test loader.
System
.
getProperties
().
entries
.
associate
{
...
...
skiko/src/jvmMain/cpp/common/interop.cc
View file @
f0454b49
...
...
@@ -99,6 +99,19 @@ namespace java {
return
false
;
}
}
namespace
System
{
jclass
cls
;
jmethodID
getProperty
;
void
onLoad
(
JNIEnv
*
env
)
{
jclass
local
=
env
->
FindClass
(
"java/lang/System"
);
cls
=
static_cast
<
jclass
>
(
env
->
NewGlobalRef
(
local
));
getProperty
=
env
->
GetStaticMethodID
(
cls
,
"getProperty"
,
"(Ljava/lang/String;)Ljava/lang/String;"
);
}
void
onUnload
(
JNIEnv
*
env
)
{
env
->
DeleteGlobalRef
(
cls
);
}
}
}
namespace
util
{
...
...
@@ -127,6 +140,7 @@ namespace java {
lang
::
RuntimeException
::
onLoad
(
env
);
lang
::
String
::
onLoad
(
env
);
lang
::
Throwable
::
onLoad
(
env
);
lang
::
System
::
onLoad
(
env
);
util
::
Iterator
::
onLoad
(
env
);
}
...
...
@@ -136,6 +150,7 @@ namespace java {
lang
::
RuntimeException
::
onUnload
(
env
);
lang
::
Float
::
onUnload
(
env
);
lang
::
Boolean
::
onUnload
(
env
);
lang
::
System
::
onUnload
(
env
);
}
}
...
...
skiko/src/jvmMain/cpp/common/interop.hh
View file @
f0454b49
...
...
@@ -61,6 +61,13 @@ namespace java {
void
onLoad
(
JNIEnv
*
env
);
bool
exceptionThrown
(
JNIEnv
*
env
);
}
namespace
System
{
extern
jclass
cls
;
extern
jmethodID
getProperty
;
void
onLoad
(
JNIEnv
*
env
);
void
onUnload
(
JNIEnv
*
env
);
}
}
namespace
util
{
...
...
skiko/src/jvmMain/cpp/windows/exceptions_handler.cc
View file @
f0454b49
#if SK_BUILD_FOR_WIN
#include "exceptions_handler.h"
static
JavaVM
*
jvm
=
NULL
;
#include "../common/interop.hh"
bool
isHandleException
(
JNIEnv
*
env
)
{
static
jclass
systemClass
=
NULL
;
if
(
!
systemClass
)
{
systemClass
=
env
->
FindClass
(
"java/lang/System"
);
}
static
jmethodID
getPropertyMethod
=
NULL
;
if
(
!
getPropertyMethod
)
{
getPropertyMethod
=
env
->
GetStaticMethodID
(
systemClass
,
"getProperty"
,
"(Ljava/lang/String;)Ljava/lang/String;"
);
}
jstring
propertyName
=
env
->
NewStringUTF
(
"skiko.win.exception.handler.enabled"
);
jstring
propertyString
=
(
jstring
)
env
->
CallStaticObjectMethod
(
systemClass
,
getPropertyMethod
,
propertyName
);
jstring
propertyString
=
(
jstring
)
env
->
CallStaticObjectMethod
(
java
::
lang
::
System
::
cls
,
java
::
lang
::
System
::
getProperty
,
propertyName
);
if
(
propertyString
==
0
)
{
return
false
;
...
...
@@ -81,29 +68,13 @@ const char *getDescription(DWORD code)
void
logJavaException
(
JNIEnv
*
env
,
const
char
*
function
,
DWORD
sehCode
)
{
char
buffer
[
200
];
int
result
=
snprintf
(
buffer
,
200
,
"Native exception in [%s]:
\n
SEH description: %s
\n
"
,
function
,
getDescription
(
sehCode
));
if
(
jvm
==
NULL
)
{
env
->
GetJavaVM
(
&
jvm
);
}
if
(
isHandleException
(
env
))
{
static
jclass
logClass
=
NULL
;
if
(
!
logClass
)
{
logClass
=
env
->
FindClass
(
"org/jetbrains/skiko/RenderExceptionsHandler"
);
}
static
jmethodID
logMethod
=
NULL
;
if
(
!
logMethod
)
{
logMethod
=
env
->
GetStaticMethodID
(
logClass
,
"logAndThrow"
,
"(Ljava/lang/String;)V"
);
}
char
buffer
[
200
];
int
result
=
snprintf
(
buffer
,
sizeof
(
buffer
)
-
1
,
"Native exception in [%s]:
\n
SEH description: %s
\n
"
,
function
,
getDescription
(
sehCode
));
jclass
logClass
=
env
->
FindClass
(
"org/jetbrains/skiko/RenderExceptionsHandler"
);
jmethodID
logMethod
=
env
->
GetStaticMethodID
(
logClass
,
"logAndThrow"
,
"(Ljava/lang/String;)V"
);
env
->
CallStaticVoidMethod
(
logClass
,
logMethod
,
env
->
NewStringUTF
(
buffer
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment