Bug 248360 - calling timer_delete from OpenJDK twice causing a SIGSEGEV
Summary: calling timer_delete from OpenJDK twice causing a SIGSEGEV
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Greg Lewis
URL:
Keywords: crash, needs-qa
Depends on:
Blocks:
 
Reported: 2020-07-30 06:09 UTC by Arne Plöse
Modified: 2020-07-30 08:24 UTC (History)
2 users (show)

See Also:
koobs: maintainer-feedback? (glewis)


Attachments
Calling timer_delete twice from a native methd of java causing a SIGSEGEV (38.80 KB, text/plain)
2020-07-30 06:09 UTC, Arne Plöse
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.