Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/ch/NativeThread.c
32288 views
1
/*
2
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include <sys/types.h>
27
#include <string.h>
28
#include "jni.h"
29
#include "jni_util.h"
30
#include "jvm.h"
31
#include "jlong.h"
32
#include "sun_nio_ch_NativeThread.h"
33
#include "nio_util.h"
34
35
#ifdef __ANDROID__
36
# define __SIGRTMAX SIGRTMAX
37
#endif
38
39
#ifdef __linux__
40
#include <pthread.h>
41
#include <sys/signal.h>
42
/* Also defined in net/linux_close.c */
43
#define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
44
#elif __solaris__
45
#include <thread.h>
46
#include <signal.h>
47
#define INTERRUPT_SIGNAL (SIGRTMAX - 2)
48
#elif _ALLBSD_SOURCE
49
#include <pthread.h>
50
#include <signal.h>
51
/* Also defined in net/bsd_close.c */
52
#define INTERRUPT_SIGNAL SIGIO
53
#else
54
#error "missing platform-specific definition here"
55
#endif
56
57
static void
58
nullHandler(int sig)
59
{
60
}
61
62
JNIEXPORT void JNICALL
63
Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
64
{
65
/* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
66
* handler previously installed by java/net/linux_close.c, but that's okay
67
* since neither handler actually does anything. We install our own
68
* handler here simply out of paranoia; ultimately the two mechanisms
69
* should somehow be unified, perhaps within the VM.
70
*/
71
72
sigset_t ss;
73
struct sigaction sa, osa;
74
sa.sa_handler = nullHandler;
75
sa.sa_flags = 0;
76
sigemptyset(&sa.sa_mask);
77
if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
78
JNU_ThrowIOExceptionWithLastError(env, "sigaction");
79
}
80
81
JNIEXPORT jlong JNICALL
82
Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
83
{
84
#ifdef __solaris__
85
return (jlong)thr_self();
86
#else
87
return (jlong)pthread_self();
88
#endif
89
}
90
91
JNIEXPORT void JNICALL
92
Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
93
{
94
int ret;
95
#ifdef __solaris__
96
ret = thr_kill((thread_t)thread, INTERRUPT_SIGNAL);
97
#else
98
ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
99
#endif
100
if (ret != 0)
101
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
102
}
103
104