2756 // the VM performs its own checks. Naturally, the user code would be making
2757 // a serious error if it tried to handle an exception (such as a null check
2758 // or breakpoint) that the VM was generating for its own correct operation.
2759 //
2760 // This routine may recognize any of the following kinds of signals:
2761 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
2762 // It should be consulted by handlers for any of those signals.
2763 //
2764 // The caller of this routine must pass in the three arguments supplied
2765 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
2766 // field of the structure passed to sigaction(). This routine assumes that
2767 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
2768 //
2769 // Note that the VM will print warnings if it detects conflicting signal
2770 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
2771 //
2772 extern "C" JNIEXPORT int JVM_handle_bsd_signal(int signo, siginfo_t* siginfo,
2773 void* ucontext,
2774 int abort_if_unrecognized);
2775
2776 void signalHandler(int sig, siginfo_t* info, void* uc) {
2777 assert(info != NULL && uc != NULL, "it must be old kernel");
2778 int orig_errno = errno; // Preserve errno value over signal handler.
2779 JVM_handle_bsd_signal(sig, info, uc, true);
2780 errno = orig_errno;
2781 }
2782
2783
2784 // This boolean allows users to forward their own non-matching signals
2785 // to JVM_handle_bsd_signal, harmlessly.
2786 bool os::Bsd::signal_handlers_are_installed = false;
2787
2788 // For signal-chaining
2789 struct sigaction sigact[NSIG];
2790 uint32_t sigs = 0;
2791 #if (32 < NSIG-1)
2792 #error "Not all signals can be encoded in sigs. Adapt its type!"
2793 #endif
2794 bool os::Bsd::libjsig_is_loaded = false;
2795 typedef struct sigaction *(*get_signal_t)(int);
2796 get_signal_t os::Bsd::get_signal_action = NULL;
3284 // To install functions for atexit system call
3285 extern "C" {
3286 static void perfMemory_exit_helper() {
3287 perfMemory_exit();
3288 }
3289 }
3290
3291 // this is called _after_ the global arguments have been parsed
3292 jint os::init_2(void) {
3293
3294 os::Posix::init_2();
3295
3296 // initialize suspend/resume support - must do this before signal_sets_init()
3297 if (SR_initialize() != 0) {
3298 perror("SR_initialize failed");
3299 return JNI_ERR;
3300 }
3301
3302 Bsd::signal_sets_init();
3303 Bsd::install_signal_handlers();
3304
3305 // Check and sets minimum stack sizes against command line options
3306 if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
3307 return JNI_ERR;
3308 }
3309
3310 if (MaxFDLimit) {
3311 // set the number of file descriptors to max. print out error
3312 // if getrlimit/setrlimit fails but continue regardless.
3313 struct rlimit nbr_files;
3314 int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3315 if (status != 0) {
3316 log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3317 } else {
3318 nbr_files.rlim_cur = nbr_files.rlim_max;
3319
3320 #ifdef __APPLE__
3321 // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3322 // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3323 // be used instead
|
2756 // the VM performs its own checks. Naturally, the user code would be making
2757 // a serious error if it tried to handle an exception (such as a null check
2758 // or breakpoint) that the VM was generating for its own correct operation.
2759 //
2760 // This routine may recognize any of the following kinds of signals:
2761 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
2762 // It should be consulted by handlers for any of those signals.
2763 //
2764 // The caller of this routine must pass in the three arguments supplied
2765 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
2766 // field of the structure passed to sigaction(). This routine assumes that
2767 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
2768 //
2769 // Note that the VM will print warnings if it detects conflicting signal
2770 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
2771 //
2772 extern "C" JNIEXPORT int JVM_handle_bsd_signal(int signo, siginfo_t* siginfo,
2773 void* ucontext,
2774 int abort_if_unrecognized);
2775
2776 static void signalHandler(int sig, siginfo_t* info, void* uc) {
2777 assert(info != NULL && uc != NULL, "it must be old kernel");
2778 int orig_errno = errno; // Preserve errno value over signal handler.
2779 JVM_handle_bsd_signal(sig, info, uc, true);
2780 errno = orig_errno;
2781 }
2782
2783
2784 // This boolean allows users to forward their own non-matching signals
2785 // to JVM_handle_bsd_signal, harmlessly.
2786 bool os::Bsd::signal_handlers_are_installed = false;
2787
2788 // For signal-chaining
2789 struct sigaction sigact[NSIG];
2790 uint32_t sigs = 0;
2791 #if (32 < NSIG-1)
2792 #error "Not all signals can be encoded in sigs. Adapt its type!"
2793 #endif
2794 bool os::Bsd::libjsig_is_loaded = false;
2795 typedef struct sigaction *(*get_signal_t)(int);
2796 get_signal_t os::Bsd::get_signal_action = NULL;
3284 // To install functions for atexit system call
3285 extern "C" {
3286 static void perfMemory_exit_helper() {
3287 perfMemory_exit();
3288 }
3289 }
3290
3291 // this is called _after_ the global arguments have been parsed
3292 jint os::init_2(void) {
3293
3294 os::Posix::init_2();
3295
3296 // initialize suspend/resume support - must do this before signal_sets_init()
3297 if (SR_initialize() != 0) {
3298 perror("SR_initialize failed");
3299 return JNI_ERR;
3300 }
3301
3302 Bsd::signal_sets_init();
3303 Bsd::install_signal_handlers();
3304 // Initialize data for jdk.internal.misc.Signal
3305 if (!ReduceSignalUsage) {
3306 signal_init_pd();
3307 }
3308
3309 // Check and sets minimum stack sizes against command line options
3310 if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
3311 return JNI_ERR;
3312 }
3313
3314 if (MaxFDLimit) {
3315 // set the number of file descriptors to max. print out error
3316 // if getrlimit/setrlimit fails but continue regardless.
3317 struct rlimit nbr_files;
3318 int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3319 if (status != 0) {
3320 log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3321 } else {
3322 nbr_files.rlim_cur = nbr_files.rlim_max;
3323
3324 #ifdef __APPLE__
3325 // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3326 // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3327 // be used instead
|