3860N/A/*
3860N/A * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
3860N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3860N/A *
3860N/A * This code is free software; you can redistribute it and/or modify it
3860N/A * under the terms of the GNU General Public License version 2 only, as
3860N/A * published by the Free Software Foundation. Oracle designates this
3860N/A * particular file as subject to the "Classpath" exception as provided
3860N/A * by Oracle in the LICENSE file that accompanied this code.
3860N/A *
3860N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3860N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3860N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3860N/A * version 2 for more details (a copy is included in the LICENSE file that
3860N/A * accompanied this code).
3860N/A *
3860N/A * You should have received a copy of the GNU General Public License version
3860N/A * 2 along with this work; if not, write to the Free Software Foundation,
3860N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3860N/A *
3860N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3860N/A * or visit www.oracle.com if you need additional information or have any
3860N/A * questions.
3860N/A */
4103N/A
3860N/A#include <sys/types.h>
3860N/A#include <string.h>
3860N/A#include "jni.h"
3860N/A#include "jni_util.h"
3860N/A#include "jvm.h"
3860N/A#include "jlong.h"
3860N/A#include "sun_nio_ch_NativeThread.h"
3860N/A#include "nio_util.h"
3860N/A
3860N/A
4124N/A#ifdef __linux__
3860N/A#include <pthread.h>
3860N/A#include <sys/signal.h>
3860N/A
3860N/A/* Also defined in src/solaris/native/java/net/linux_close.c */
3860N/A#define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
3860N/A
3860N/Astatic void
3860N/AnullHandler(int sig)
3860N/A{
3860N/A}
4124N/A
4124N/A#endif
4103N/A
3860N/A
3860N/AJNIEXPORT void JNICALL
3860N/AJava_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
3860N/A{
3860N/A#ifdef __linux__
3860N/A
3860N/A /* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
3860N/A * handler previously installed by java/net/linux_close.c, but that's okay
3860N/A * since neither handler actually does anything. We install our own
3860N/A * handler here simply out of paranoia; ultimately the two mechanisms
3860N/A * should somehow be unified, perhaps within the VM.
3860N/A */
3860N/A
3860N/A sigset_t ss;
3860N/A struct sigaction sa, osa;
3860N/A sa.sa_handler = nullHandler;
3860N/A sa.sa_flags = 0;
3860N/A sigemptyset(&sa.sa_mask);
3860N/A if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
3860N/A JNU_ThrowIOExceptionWithLastError(env, "sigaction");
3914N/A
3860N/A#endif
3972N/A}
4124N/A
3914N/AJNIEXPORT jlong JNICALL
3972N/AJava_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
4124N/A{
3972N/A#ifdef __linux__
3972N/A return (long)pthread_self();
3860N/A#else
3860N/A return -1;
3860N/A#endif
3860N/A}
3860N/A
3860N/AJNIEXPORT void JNICALL
3860N/AJava_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
3860N/A{
3860N/A#ifdef __linux__
3860N/A if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL))
3860N/A JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
3972N/A#endif
3972N/A}
3860N/A