4711 tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN));
4712 tty->print("expected:");
4713 os::Posix::print_sa_flags(tty, os::Linux::get_our_sigflags(sig));
4714 tty->cr();
4715 tty->print(" found:");
4716 os::Posix::print_sa_flags(tty, act.sa_flags);
4717 tty->cr();
4718 // No need to check this sig any longer
4719 sigaddset(&check_signal_done, sig);
4720 }
4721
4722 // Dump all the signal
4723 if (sigismember(&check_signal_done, sig)) {
4724 print_signal_handlers(tty, buf, O_BUFLEN);
4725 }
4726 }
4727
4728 extern void report_error(char* file_name, int line_no, char* title,
4729 char* format, ...);
4730
4731 // this is called _before_ the most of global arguments have been parsed
4732 void os::init(void) {
4733 char dummy; // used to get a guess on initial stack address
4734 // first_hrtime = gethrtime();
4735
4736 clock_tics_per_sec = sysconf(_SC_CLK_TCK);
4737
4738 init_random(1234567);
4739
4740 ThreadCritical::initialize();
4741
4742 Linux::set_page_size(sysconf(_SC_PAGESIZE));
4743 if (Linux::page_size() == -1) {
4744 fatal("os_linux.cpp: os::init: sysconf failed (%s)",
4745 os::strerror(errno));
4746 }
4747 init_page_sizes((size_t) Linux::page_size());
4748
4749 Linux::initialize_system_info();
4750
4762 if ((status = pthread_condattr_init(_condattr)) != 0) {
4763 fatal("pthread_condattr_init: %s", os::strerror(status));
4764 }
4765 // Only set the clock if CLOCK_MONOTONIC is available
4766 if (os::supports_monotonic_clock()) {
4767 if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
4768 if (status == EINVAL) {
4769 warning("Unable to use monotonic clock with relative timed-waits" \
4770 " - changes to the time-of-day clock may have adverse affects");
4771 } else {
4772 fatal("pthread_condattr_setclock: %s", os::strerror(status));
4773 }
4774 }
4775 }
4776 // else it defaults to CLOCK_REALTIME
4777
4778 // retrieve entry point for pthread_setname_np
4779 Linux::_pthread_setname_np =
4780 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4781
4782 }
4783
4784 // To install functions for atexit system call
4785 extern "C" {
4786 static void perfMemory_exit_helper() {
4787 perfMemory_exit();
4788 }
4789 }
4790
4791 // this is called _after_ the global arguments have been parsed
4792 jint os::init_2(void) {
4793 Linux::fast_thread_clock_init();
4794
4795 // Allocate a single page and mark it as readable for safepoint polling
4796 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4797 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
4798
4799 os::set_polling_page(polling_page);
4800 log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
4801
|
4711 tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN));
4712 tty->print("expected:");
4713 os::Posix::print_sa_flags(tty, os::Linux::get_our_sigflags(sig));
4714 tty->cr();
4715 tty->print(" found:");
4716 os::Posix::print_sa_flags(tty, act.sa_flags);
4717 tty->cr();
4718 // No need to check this sig any longer
4719 sigaddset(&check_signal_done, sig);
4720 }
4721
4722 // Dump all the signal
4723 if (sigismember(&check_signal_done, sig)) {
4724 print_signal_handlers(tty, buf, O_BUFLEN);
4725 }
4726 }
4727
4728 extern void report_error(char* file_name, int line_no, char* title,
4729 char* format, ...);
4730
4731 // Some linux distributions (notably: Alpine Linux) include the
4732 // grsecurity in the kernel by default. Of particular interest from a
4733 // JVM perspective is PaX (https://pax.grsecurity.net/), which adds
4734 // some security features related to page attributes. Specifically,
4735 // the MPROTECT PaX functionality
4736 // (https://pax.grsecurity.net/docs/mprotect.txt) prevents dynamic
4737 // code generation by disallowing a (previously) writable page to be
4738 // marked as executable. This is, of course, exactly what HotSpot does
4739 // for both JIT compiled method, as well as for stubs, adapters, etc.
4740 //
4741 // Instead of crashing "lazily" when trying to make a page executable,
4742 // this code probes for the presence of PaX and reports the failure
4743 // eagerly.
4744 static void check_pax(void) {
4745 // Zero doesn't generate code dynamically, so no need to perform the PaX check
4746 #ifndef ZERO
4747 size_t size = os::Linux::page_size();
4748
4749 void* p = ::mmap(NULL, size, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4750 if (p == MAP_FAILED) {
4751 vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "failed to allocate memory for PaX check.");
4752 }
4753
4754 int res = ::mprotect(p, size, PROT_WRITE|PROT_EXEC);
4755 if (res == -1) {
4756 vm_exit_during_initialization("Failed to mark memory page as executable",
4757 "Please check if grsecurity/PaX is enabled in your kernel.\n"
4758 "\n"
4759 "For example, you can do this by running (note: you may need root privileges):\n"
4760 "\n"
4761 " sysctl kernel.pax.softmode\n"
4762 "\n"
4763 "If PaX is included in the kernel you will see something like this:\n"
4764 "\n"
4765 " kernel.pax.softmode = 0\n"
4766 "\n"
4767 "In particular, if the value is 0 (zero), then PaX is enabled.\n"
4768 "\n"
4769 "PaX includes security functionality which interferes with the dynamic code\n"
4770 "generation the JVM relies on. Specifically, the MPROTECT functionality as\n"
4771 "described on https://pax.grsecurity.net/docs/mprotect.txt is not compatible\n"
4772 "with the JVM. If you want to allow the JVM to run you will have to disable PaX.\n"
4773 "You can do this on a per-executable basis using the paxctl tool, for example:\n"
4774 "\n"
4775 " paxctl -cm bin/java\n"
4776 "\n"
4777 "Please note that this modifies the executable binary in-place, so may want\n"
4778 "to make a backup of it first. Also note that you have to repeat this for other\n"
4779 "executables like javac, jar, jcmd, etc.\n"
4780 );
4781
4782 }
4783
4784 ::munmap(p, size);
4785 #endif
4786 }
4787
4788 // this is called _before_ the most of global arguments have been parsed
4789 void os::init(void) {
4790 char dummy; // used to get a guess on initial stack address
4791 // first_hrtime = gethrtime();
4792
4793 clock_tics_per_sec = sysconf(_SC_CLK_TCK);
4794
4795 init_random(1234567);
4796
4797 ThreadCritical::initialize();
4798
4799 Linux::set_page_size(sysconf(_SC_PAGESIZE));
4800 if (Linux::page_size() == -1) {
4801 fatal("os_linux.cpp: os::init: sysconf failed (%s)",
4802 os::strerror(errno));
4803 }
4804 init_page_sizes((size_t) Linux::page_size());
4805
4806 Linux::initialize_system_info();
4807
4819 if ((status = pthread_condattr_init(_condattr)) != 0) {
4820 fatal("pthread_condattr_init: %s", os::strerror(status));
4821 }
4822 // Only set the clock if CLOCK_MONOTONIC is available
4823 if (os::supports_monotonic_clock()) {
4824 if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
4825 if (status == EINVAL) {
4826 warning("Unable to use monotonic clock with relative timed-waits" \
4827 " - changes to the time-of-day clock may have adverse affects");
4828 } else {
4829 fatal("pthread_condattr_setclock: %s", os::strerror(status));
4830 }
4831 }
4832 }
4833 // else it defaults to CLOCK_REALTIME
4834
4835 // retrieve entry point for pthread_setname_np
4836 Linux::_pthread_setname_np =
4837 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4838
4839 check_pax();
4840 }
4841
4842 // To install functions for atexit system call
4843 extern "C" {
4844 static void perfMemory_exit_helper() {
4845 perfMemory_exit();
4846 }
4847 }
4848
4849 // this is called _after_ the global arguments have been parsed
4850 jint os::init_2(void) {
4851 Linux::fast_thread_clock_init();
4852
4853 // Allocate a single page and mark it as readable for safepoint polling
4854 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4855 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
4856
4857 os::set_polling_page(polling_page);
4858 log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
4859
|