Skip to content

Commit b3bebe4

Browse files
committed
svm: adopt "JDK-8347719: [REDO] Portable implementation of FORBID_C_FUNCTION and ALLOW_C_FUNCTION"
1 parent 006b59b commit b3bebe4

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/share/runtime/os.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@
8686
#include "utilities/fastrand.hpp"
8787
#include "utilities/globalDefinitions.hpp"
8888
#include "utilities/macros.hpp"
89+
#endif // !NATIVE_IMAGE
8990
#include "utilities/permitForbiddenFunctions.hpp"
91+
#ifndef NATIVE_IMAGE
9092
#include "utilities/powerOfTwo.hpp"
9193

9294
#ifdef LINUX

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/share/utilities/globalDefinitions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
#include "utilities/compilerWarnings.hpp"
3030
#include "utilities/debug.hpp"
31+
#ifndef NATIVE_IMAGE
3132
#include "utilities/forbiddenFunctions.hpp"
33+
#endif // !NATIVE_IMAGE
3234
#include "utilities/macros.hpp"
3335

3436
#ifndef NATIVE_IMAGE
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)