1 /*
2 * Copyright (c) 2021, 2024, 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 oop to_file_URL(const char* path, Handle url_h, TRAPS);
84 static Handle get_protection_domain_from_classloader(Handle class_loader,
85 Handle url, TRAPS);
86 static Handle get_shared_protection_domain(Handle class_loader,
87 int shared_path_index,
88 Handle url,
89 TRAPS);
90 static Handle get_shared_protection_domain(Handle class_loader,
91 ModuleEntry* mod, TRAPS);
92 static void atomic_set_array_index(OopHandle array, int index, oop o);
93 static oop shared_protection_domain(int index);
94 static void allocate_shared_protection_domain_array(int size, TRAPS);
95 static oop shared_jar_url(int index);
96 static void allocate_shared_jar_url_array(int size, TRAPS);
97 static oop shared_jar_manifest(int index);
98 static void allocate_shared_jar_manifest_array(int size, TRAPS);
99 static Handle init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS);
100
101 static void allocate_shared_data_arrays(int size, TRAPS) {
102 allocate_shared_protection_domain_array(size, CHECK);
103 allocate_shared_jar_url_array(size, CHECK);
104 allocate_shared_jar_manifest_array(size, CHECK);
105 }
106 static void atomic_set_shared_protection_domain(int index, oop pd) {
107 atomic_set_array_index(_shared_protection_domains, index, pd);
108 }
109 static void atomic_set_shared_jar_url(int index, oop url) {
110 atomic_set_array_index(_shared_jar_urls, index, url);
111 }
112 static void atomic_set_shared_jar_manifest(int index, oop man) {
113 atomic_set_array_index(_shared_jar_manifests, index, man);
114 }
115 };
116
117 #endif // SHARE_CDS_CDSPROTECTIONDOMAIN_HPP