1 /*
2 * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
69 // TODO - return a meaningful error code
70 *error = 0;
71 ImageFileReader* jfile = ImageFileReader::open(name);
72 return (JImageFile*) jfile;
73 }
74
75 /*
76 * JImageClose - Given the supplied open image file (see JImageOpen), release
77 * memory and resources used by the open file and close the file. If the image
78 * file is shared by other uses, release and close is deferred until the last use
79 * is also closed.
80 *
81 * Ex.
82 * (*JImageClose)(image);
83 */
84 extern "C" JNIEXPORT void
85 JIMAGE_Close(JImageFile* image) {
86 ImageFileReader::close((ImageFileReader*) image);
87 }
88
89 /*
90 * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
91 * of a package, return the name of module where the package resides. If the
92 * package does not exist in the image file, the function returns NULL.
93 * The resulting string does/should not have to be released. All strings are
94 * utf-8, zero byte terminated.
95 *
96 * Ex.
97 * const char* package = (*JImagePackageToModule)(image, "java/lang");
98 * tty->print_cr(package);
99 * -> java.base
100 */
101 extern "C" JNIEXPORT const char*
102 JIMAGE_PackageToModule(JImageFile* image, const char* package_name) {
103 return ((ImageFileReader*) image)->get_image_module_data()->package_to_module(package_name);
104 }
105
106 /*
107 * JImageFindResource - Given an open image file (see JImageOpen), a module
108 * name, a version string and the name of a class/resource, return location
109 * information describing the resource and its size. If no resource is found, the
110 * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
111 * The version number should be "9.0" and is not used in locating the resource.
112 * The resulting location does/should not have to be released.
113 * All strings are utf-8, zero byte terminated.
114 *
115 * Ex.
116 * jlong size;
117 * JImageLocationRef location = (*JImageFindResource)(image,
118 * "java.base", "9.0", "java/lang/String.class", &size);
119 */
120 extern "C" JNIEXPORT JImageLocationRef
121 JIMAGE_FindResource(JImageFile* image,
122 const char* module_name, const char* version, const char* name,
123 jlong* size) {
124 // Concatenate to get full path
125 char fullpath[IMAGE_MAX_PATH];
|
1 /*
2 * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
69 // TODO - return a meaningful error code
70 *error = 0;
71 ImageFileReader* jfile = ImageFileReader::open(name);
72 return (JImageFile*) jfile;
73 }
74
75 /*
76 * JImageClose - Given the supplied open image file (see JImageOpen), release
77 * memory and resources used by the open file and close the file. If the image
78 * file is shared by other uses, release and close is deferred until the last use
79 * is also closed.
80 *
81 * Ex.
82 * (*JImageClose)(image);
83 */
84 extern "C" JNIEXPORT void
85 JIMAGE_Close(JImageFile* image) {
86 ImageFileReader::close((ImageFileReader*) image);
87 }
88
89 /*
90 * JImageFindResource - Given an open image file (see JImageOpen), a module
91 * name, a version string and the name of a class/resource, return location
92 * information describing the resource and its size. If no resource is found, the
93 * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
94 * The version number should be "9.0" and is not used in locating the resource.
95 * The resulting location does/should not have to be released.
96 * All strings are utf-8, zero byte terminated.
97 *
98 * Ex.
99 * jlong size;
100 * JImageLocationRef location = (*JImageFindResource)(image,
101 * "java.base", "9.0", "java/lang/String.class", &size);
102 */
103 extern "C" JNIEXPORT JImageLocationRef
104 JIMAGE_FindResource(JImageFile* image,
105 const char* module_name, const char* version, const char* name,
106 jlong* size) {
107 // Concatenate to get full path
108 char fullpath[IMAGE_MAX_PATH];
|