Bug 248360

Summary: calling timer_delete from OpenJDK twice causing a SIGSEGEV
Product: Ports & Packages Reporter: Arne Plöse <aploese>
Component: Individual Port(s)Assignee: Greg Lewis <glewis>
Status: Open ---    
Severity: Affects Some People CC: aploese, glewis
Priority: --- Keywords: crash, needs-qa
Version: LatestFlags: koobs: maintainer-feedback? (glewis)
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Calling timer_delete twice from a native methd of java causing a SIGSEGEV none

Description Arne Plöse 2020-07-30 06:09:02 UTC
Created attachment 216874 [details]
Calling timer_delete twice from a native methd of java causing a SIGSEGEV

Creating a timer and deleting that timer a second time does not set the errno to EINVAL but crashes the whole VM (this happens in OpenBSD too... but not on linux).
calling timer_delete twice without returning to java after the first call will succeed without a SIGSEGEV. 
I don't know if this is an OpenJDK or a LibC bug or just a feature...


simply run run.sh

here files to reproduce the error

file run.sh
>>>>
#!/bin/sh

#linux export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
#freebsd
export JAVA_HOME=/usr/local/openjdk14/

gcc -fPIC TimerCreateDelete.c -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -I $JAVA_HOME/include/freebsd -pthread -lrt  || exit 1

./a.out

javac TimerCreateDelete.java || exit 1

gcc -c -fPIC TimerCreateDelete.c -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -I $JAVA_HOME/include/freebsd || exit 1

gcc -shared -o libTimerCreateDelete.so TimerCreateDelete.o -pthread -lrt || exit 1

java TimerCreateDelete `pwd`
<<<<

file TimerCreateDelete.c
>>>>
#include <jni.h>
#include <time.h>
#include <errno.h>

#ifdef __cplusplus
extern "C" {
#endif
    
static timer_t myTimer;

/*
 * Class:     TimerCreateDelete
 * Method:    timer_create
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_TimerCreateDelete_timer_1create
  (JNIEnv *env, jclass clazz) {
    if (timer_create(CLOCK_MONOTONIC, NULL, &myTimer)) {
        return errno;
    } else {
        return 0;
    }
}

/*
 * Class:     TimerCreateDelete
 * Method:    timer_delete
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_TimerCreateDelete_timer_1delete
  (JNIEnv *env, jclass clazz) {
    if (timer_delete(myTimer)) {
        return errno;
    } else {
        return 0;
    }
}


int main(void) {
    puts("Run from native main"); 
    int result;    
    result = Java_TimerCreateDelete_timer_1create(NULL, NULL);
    printf("time_create: %d\n", result);    
    result = Java_TimerCreateDelete_timer_1delete(NULL, NULL);
    printf("time_delete: %d\n", result);    
    result = Java_TimerCreateDelete_timer_1delete(NULL, NULL);
    printf("time_delete: %d\n", result);    
    puts("Timer destroyed"); 
    return 0;
}


#ifdef __cplusplus
}
#endif
<<<<

file TimerCreateDelete.java
>>>>

/**
 *
 * @author aploese
 */
public class TimerCreateDelete {

    private static native int timer_create();

    private static native int timer_delete();

    public static void main(String[] args) {
        System.load(args[0] + "/libTimerCreateDelete.so");
        int errno;
        System.out.println("Will call timer_create");
        errno = timer_create();
        System.out.println("timer_create errno: " + errno);

        System.out.println("Will call timer_delete first time");
        errno = timer_delete();
        System.out.println("timer_delete errno: " + errno);

        System.out.println("Will call timer_delete second time");
        errno = timer_delete();
        System.out.println("timer_delete errno: " + errno);
    }
}
<<<<
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2020-07-30 07:52:18 UTC
Thank you for yoru report Arne,

What exact port origin (category/portname) or package name is this an issue for?
Comment 2 Arne Plöse 2020-07-30 08:24:12 UTC
(In reply to Kubilay Kocak from comment #1)

I just installed the FuryBSD-12.1-XFCE.iso, and did a pkg update, pkg install openjdk14 ...

Sorry, I'm completely new to FreeBSD, so if you need more informations please let me know and maybe how to obtain them.