|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 2025, 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. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef SHARE_UTILITIES_PERMITFORBIDDENFUNCTIONS_HPP |
| 27 | +#define SHARE_UTILITIES_PERMITFORBIDDENFUNCTIONS_HPP |
| 28 | + |
| 29 | +#include "utilities/compilerWarnings.hpp" |
| 30 | +#include "utilities/globalDefinitions.hpp" |
| 31 | + |
| 32 | +#ifndef NATIVE_IMAGE |
| 33 | +#ifdef _WINDOWS |
| 34 | +#include "permitForbiddenFunctions_windows.hpp" |
| 35 | +#else |
| 36 | +#include "permitForbiddenFunctions_posix.hpp" |
| 37 | +#endif |
| 38 | +#endif // !NATIVE_IMAGE |
| 39 | + |
| 40 | +// Provide wrappers for some functions otherwise forbidden from use in HotSpot. |
| 41 | +// |
| 42 | +// There may be special circumstances where an otherwise forbidden function |
| 43 | +// really does need to be used. One example is in the implementation of a |
| 44 | +// corresponding os:: function. |
| 45 | +// |
| 46 | +// Wrapper functions are provided for such forbidden functions. These |
| 47 | +// wrappers are defined in a context where the forbidding warnings are |
| 48 | +// suppressed. They are defined in a special namespace, to highlight uses as |
| 49 | +// unusual and requiring increased scrutiny. |
| 50 | +// |
| 51 | +// Note that there are several seemingly plausible shorter alternatives to |
| 52 | +// these written-out wrapper functions. All that have been tried don't work |
| 53 | +// for one reason or another. |
| 54 | + |
| 55 | +namespace permit_forbidden_function { |
| 56 | +BEGIN_ALLOW_FORBIDDEN_FUNCTIONS |
| 57 | + |
| 58 | +#ifndef NATIVE_IMAGE |
| 59 | +[[noreturn]] inline void exit(int status) { ::exit(status); } |
| 60 | +[[noreturn]] inline void _exit(int status) { ::_exit(status); } |
| 61 | +#endif // !NATIVE_IMAGE |
| 62 | + |
| 63 | +ATTRIBUTE_PRINTF(3, 0) |
| 64 | +inline int vsnprintf(char* str, size_t size, const char* format, va_list ap) { |
| 65 | + return ::vsnprintf(str, size, format, ap); |
| 66 | +} |
| 67 | + |
| 68 | +#ifndef NATIVE_IMAGE |
| 69 | +inline void* malloc(size_t size) { return ::malloc(size); } |
| 70 | +inline void free(void* ptr) { return ::free(ptr); } |
| 71 | +inline void* calloc(size_t nmemb, size_t size) { return ::calloc(nmemb, size); } |
| 72 | +inline void* realloc(void* ptr, size_t size) { return ::realloc(ptr, size); } |
| 73 | + |
| 74 | +inline char* strdup(const char* s) { return ::strdup(s); } |
| 75 | +#endif // !NATIVE_IMAGE |
| 76 | + |
| 77 | +END_ALLOW_FORBIDDEN_FUNCTIONS |
| 78 | +} // namespace permit_forbidden_function |
| 79 | + |
| 80 | +#endif // SHARE_UTILITIES_PERMITFORBIDDENFUNCTIONS_HPP |
0 commit comments