Blame SOURCES/rh1750419-redhat_alt_java.patch

53c576
diff --git openjdk.orig/jdk/make/CompileLaunchers.gmk openjdk/jdk/make/CompileLaunchers.gmk
53c576
--- openjdk.orig/jdk/make/CompileLaunchers.gmk
53c576
+++ openjdk/jdk/make/CompileLaunchers.gmk
53c576
@@ -255,6 +255,33 @@
53c576
   endif
53c576
 endif
53c576
 
53c576
+# -Wno-error=cpp is present to allow commented warning in ifdef part of main.c
53c576
+$(eval $(call SetupLauncher,alt-java, \
53c576
+    -DEXPAND_CLASSPATH_WILDCARDS -DREDHAT_ALT_JAVA -Wno-error=cpp,,,user32.lib comctl32.lib, \
53c576
+    $(JDK_OUTPUTDIR)/objs/jli_static.lib, $(JAVA_RC_FLAGS), \
53c576
+    $(JDK_TOPDIR)/src/windows/resource/java.rc, $(JDK_OUTPUTDIR)/objs/java_objs,true))
53c576
+
53c576
+$(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX): $(BUILD_LAUNCHER_alt-java)
53c576
+	$(MKDIR) -p $(@D)
53c576
+	$(RM) $@
53c576
+	$(CP) $(JDK_OUTPUTDIR)/objs/java_objs$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX) $@
53c576
+
53c576
+$(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT): $(BUILD_LAUNCHER_alt-java)
53c576
+	$(MKDIR) -p $(@D)
53c576
+	$(RM) $@
53c576
+	$(CP) $(JDK_OUTPUTDIR)/objs/java_objs$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT) $@
53c576
+
53c576
+ifeq ($(OPENJDK_TARGET_OS), linux)
53c576
+  BUILD_LAUNCHERS += $(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(EXE_SUFFIX)
53c576
+  ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
53c576
+    ifneq ($(POST_STRIP_CMD), )
53c576
+      ifneq ($(STRIP_POLICY), no_strip)
53c576
+        BUILD_LAUNCHERS += $(JDK_OUTPUTDIR)/bin$(OUTPUT_SUBDIR)/alt-java$(DEBUGINFO_EXT)
53c576
+      endif
53c576
+    endif
53c576
+  endif
53c576
+endif
53c576
+
53c576
 ifeq ($(OPENJDK_TARGET_OS), windows)
53c576
   $(eval $(call SetupLauncher,javaw, \
53c576
       -DJAVAW -DEXPAND_CLASSPATH_WILDCARDS,,,user32.lib comctl32.lib, \
53c576
diff --git openjdk.orig/jdk/src/share/bin/alt_main.h openjdk/jdk/src/share/bin/alt_main.h
53c576
new file mode 100644
53c576
--- /dev/null
53c576
+++ openjdk/jdk/src/share/bin/alt_main.h
53c576
@@ -0,0 +1,73 @@
53c576
+/*
53c576
+ * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
53c576
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53c576
+ *
53c576
+ * This code is free software; you can redistribute it and/or modify it
53c576
+ * under the terms of the GNU General Public License version 2 only, as
53c576
+ * published by the Free Software Foundation.  Oracle designates this
53c576
+ * particular file as subject to the "Classpath" exception as provided
53c576
+ * by Oracle in the LICENSE file that accompanied this code.
53c576
+ *
53c576
+ * This code is distributed in the hope that it will be useful, but WITHOUT
53c576
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53c576
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
53c576
+ * version 2 for more details (a copy is included in the LICENSE file that
53c576
+ * accompanied this code).
53c576
+ *
53c576
+ * You should have received a copy of the GNU General Public License version
53c576
+ * 2 along with this work; if not, write to the Free Software Foundation,
53c576
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53c576
+ *
53c576
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53c576
+ * or visit www.oracle.com if you need additional information or have any
53c576
+ * questions.
53c576
+ */
53c576
+
53c576
+#ifdef REDHAT_ALT_JAVA
53c576
+
53c576
+#include <sys/prctl.h>
53c576
+
53c576
+
53c576
+/* Per task speculation control */
53c576
+#ifndef PR_GET_SPECULATION_CTRL
53c576
+# define PR_GET_SPECULATION_CTRL    52
53c576
+#endif
53c576
+#ifndef PR_SET_SPECULATION_CTRL
53c576
+# define PR_SET_SPECULATION_CTRL    53
53c576
+#endif
53c576
+/* Speculation control variants */
53c576
+#ifndef PR_SPEC_STORE_BYPASS
53c576
+# define PR_SPEC_STORE_BYPASS          0
53c576
+#endif
53c576
+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
53c576
+
53c576
+#ifndef PR_SPEC_NOT_AFFECTED
53c576
+# define PR_SPEC_NOT_AFFECTED          0
53c576
+#endif
53c576
+#ifndef PR_SPEC_PRCTL
53c576
+# define PR_SPEC_PRCTL                 (1UL << 0)
53c576
+#endif
53c576
+#ifndef PR_SPEC_ENABLE
53c576
+# define PR_SPEC_ENABLE                (1UL << 1)
53c576
+#endif
53c576
+#ifndef PR_SPEC_DISABLE
53c576
+# define PR_SPEC_DISABLE               (1UL << 2)
53c576
+#endif
53c576
+#ifndef PR_SPEC_FORCE_DISABLE
53c576
+# define PR_SPEC_FORCE_DISABLE         (1UL << 3)
53c576
+#endif
53c576
+#ifndef PR_SPEC_DISABLE_NOEXEC
53c576
+# define PR_SPEC_DISABLE_NOEXEC        (1UL << 4)
53c576
+#endif
53c576
+
53c576
+static void set_speculation() __attribute__((constructor));
53c576
+static void set_speculation() {
53c576
+  if ( prctl(PR_SET_SPECULATION_CTRL,
53c576
+             PR_SPEC_STORE_BYPASS,
53c576
+             PR_SPEC_DISABLE_NOEXEC, 0, 0) == 0 ) {
53c576
+    return;
53c576
+  }
53c576
+  prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
53c576
+}
53c576
+
53c576
+#endif // REDHAT_ALT_JAVA
53c576
diff --git openjdk.orig/jdk/src/share/bin/main.c openjdk/jdk/src/share/bin/main.c
53c576
--- openjdk.orig/jdk/src/share/bin/main.c
53c576
+++ openjdk/jdk/src/share/bin/main.c
53c576
@@ -32,6 +32,14 @@
53c576
 
53c576
 #include "defines.h"
53c576
 
53c576
+#ifdef REDHAT_ALT_JAVA
53c576
+#if defined(__linux__) && defined(__x86_64__)
53c576
+#include "alt_main.h"
53c576
+#else
53c576
+#warning alt-java requested but SSB mitigation not available on this platform.
53c576
+#endif
53c576
+#endif
53c576
+
53c576
 #ifdef _MSC_VER
53c576
 #if _MSC_VER > 1400 && _MSC_VER < 1600
53c576