``` #include <jvmti.h> #include <stdio.h&...
# kotlin-native
i
Copy code
#include <jvmti.h>
#include <stdio.h>

JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
    return 0;
}
Copy code
// SIGSEGV
@CName("Agent_OnLoad")
fun Agent_OnLoad(
    vm: CValuesRef<JavaVMVar>?,
    options: CValuesRef<ByteVar>?,
    reserved: CValuesRef<*>?
:disappointed: jint {
    println("Agent: Hello, World!")
    return 0
}

// ok
@CName("Agent_OnLoad")
fun Agent_OnLoad(
    vm: NativePtr,
    options: NativePtr,
    reserved: NativePtr
:disappointed: jint {
    println("Agent: Hello, World!")
    return 0
}
n
Do note that Kotlin Native doesn't support JNI.
i
I've trying to implement JVM TI with Kotlin/Native, and I have some success, but types generated by cinterop feels wron
🆗 1
o
K/N does support JNI as any other C library.
CPointer<JavaVMVar>
and such is right type here.
🆗 1
i
But
cinterop
generated
CValuesRef<JavaVMVar>?
here. Headers from jdk11
I feel like generated types is wrong in other places, so they doesn't help, and I have to write bindings myself. https://github.com/IRus/jvm-ti-kotlin/blob/master/src/linuxMain/kotlin/JvmTi.kt#L25
Can you confirm that?
o
nope,
CPointer
is subclass of
CValuesRef
, and in this case it shall be used.
cinterop
is not related to the problem here, as it provides bindings to the C library from Kotlin, and in your case you produce C library from Kotlin source code.