1 /* 2 * Copyright (c) 2021, 2023, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CDS_CDSPROTECTIONDOMAIN_HPP 26 #define SHARE_CDS_CDSPROTECTIONDOMAIN_HPP 27 28 #include "classfile/moduleEntry.hpp" 29 #include "oops/oopHandle.inline.hpp" 30 #include "runtime/handles.inline.hpp" 31 #include "runtime/javaThread.hpp" 32 33 class InstanceKlass; 34 class Symbol; 35 class PackageEntry; 36 class ModuleEntry; 37 38 // CDS security 39 class CDSProtectionDomain : AllStatic { 40 // See init_security_info for more info. 41 static OopHandle _shared_protection_domains; 42 static OopHandle _shared_jar_urls; 43 static OopHandle _shared_jar_manifests; 44 45 public: 46 // Package handling: 47 // 48 // 1. For named modules in the runtime image 49 // BOOT classes: Reuses the existing JVM_GetSystemPackage(s) interfaces 50 // to get packages in named modules for shared classes. 51 // Package for non-shared classes in named module is also 52 // handled using JVM_GetSystemPackage(s). 53 // 54 // APP classes: VM calls ClassLoaders.AppClassLoader::definePackage(String, Module) 55 // to define package for shared app classes from named 56 // modules. 57 // 58 // PLATFORM classes: VM calls ClassLoaders.PlatformClassLoader::definePackage(String, Module) 59 // to define package for shared platform classes from named 60 // modules. 61 // 62 // 2. For unnamed modules 63 // BOOT classes: Reuses the existing JVM_GetSystemPackage(s) interfaces to 64 // get packages for shared boot classes in unnamed modules. 65 // 66 // APP classes: VM calls ClassLoaders.AppClassLoader::defineOrCheckPackage() 67 // with with the manifest and url from archived data. 68 // 69 // PLATFORM classes: No package is defined. 70 // 71 // The following two define_shared_package() functions are used to define 72 // package for shared APP and PLATFORM classes. 73 static Handle get_package_name(Symbol* class_name, TRAPS); 74 static PackageEntry* get_package_entry_from_class(InstanceKlass* ik, Handle class_loader); 75 static void define_shared_package(Symbol* class_name, 76 Handle class_loader, 77 Handle manifest, 78 Handle url, 79 TRAPS); 80 static Handle create_jar_manifest(const char* man, size_t size, TRAPS); 81 static Handle get_shared_jar_manifest(int shared_path_index, TRAPS); 82 static Handle get_shared_jar_url(int shared_path_index, TRAPS); 83 static Handle get_protection_domain_from_classloader(Handle class_loader, 84 Handle url, TRAPS); 85 static Handle get_shared_protection_domain(Handle class_loader, 86 int shared_path_index, 87 Handle url, 88 TRAPS); 89 static Handle get_shared_protection_domain(Handle class_loader, 90 ModuleEntry* mod, TRAPS); 91 static void atomic_set_array_index(OopHandle array, int index, oop o); 92 static oop shared_protection_domain(int index); 93 static void allocate_shared_protection_domain_array(int size, TRAPS); 94 static oop shared_jar_url(int index); 95 static void allocate_shared_jar_url_array(int size, TRAPS); 96 static oop shared_jar_manifest(int index); 97 static void allocate_shared_jar_manifest_array(int size, TRAPS); 98 static Handle init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS); 99 100 static void allocate_shared_data_arrays(int size, TRAPS) { 101 allocate_shared_protection_domain_array(size, CHECK); 102 allocate_shared_jar_url_array(size, CHECK); 103 allocate_shared_jar_manifest_array(size, CHECK); 104 } 105 static void atomic_set_shared_protection_domain(int index, oop pd) { 106 atomic_set_array_index(_shared_protection_domains, index, pd); 107 } 108 static void atomic_set_shared_jar_url(int index, oop url) { 109 atomic_set_array_index(_shared_jar_urls, index, url); 110 } 111 static void atomic_set_shared_jar_manifest(int index, oop man) { 112 atomic_set_array_index(_shared_jar_manifests, index, man); 113 } 114 }; 115 116 #endif // SHARE_CDS_CDSPROTECTIONDOMAIN_HPP