Skip to content

Commit db76f47

Browse files
author
Kim Barrett
committed
8347720: [BACKOUT] Portable implementation of FORBID_C_FUNCTION and ALLOW_C_FUNCTION
Reviewed-by: coleenp
1 parent e6902cf commit db76f47

32 files changed

+177
-528
lines changed

src/hotspot/os/aix/libodm_aix.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <string.h>
3131
#include "runtime/arguments.hpp"
3232
#include "runtime/os.hpp"
33-
#include "utilities/permitForbiddenFunctions.hpp"
3433

3534

3635
dynamicOdm::dynamicOdm() {
@@ -60,7 +59,7 @@ dynamicOdm::~dynamicOdm() {
6059
}
6160

6261

63-
void odmWrapper::clean_data() { if (_data) { permit_forbidden_function::free(_data); _data = nullptr; } }
62+
void odmWrapper::clean_data() { if (_data) { free(_data); _data = nullptr; } }
6463

6564

6665
int odmWrapper::class_offset(const char *field, bool is_aix_5)

src/hotspot/os/aix/loadlib_aix.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "logging/log.hpp"
3939
#include "utilities/debug.hpp"
4040
#include "utilities/ostream.hpp"
41-
#include "utilities/permitForbiddenFunctions.hpp"
4241

4342
// For loadquery()
4443
#include <sys/ldr.h>
@@ -56,7 +55,7 @@ class StringList {
5655
// Enlarge list. If oom, leave old list intact and return false.
5756
bool enlarge() {
5857
int cap2 = _cap + 64;
59-
char** l2 = (char**) permit_forbidden_function::realloc(_list, sizeof(char*) * cap2);
58+
char** l2 = (char**) ::realloc(_list, sizeof(char*) * cap2);
6059
if (!l2) {
6160
return false;
6261
}
@@ -74,7 +73,7 @@ class StringList {
7473
}
7574
}
7675
assert0(_cap > _num);
77-
char* s2 = permit_forbidden_function::strdup(s);
76+
char* s2 = ::strdup(s);
7877
if (!s2) {
7978
return nullptr;
8079
}
@@ -168,7 +167,7 @@ static void free_entry_list(loaded_module_t** start) {
168167
loaded_module_t* lm = *start;
169168
while (lm) {
170169
loaded_module_t* const lm2 = lm->next;
171-
permit_forbidden_function::free(lm);
170+
::free(lm);
172171
lm = lm2;
173172
}
174173
*start = nullptr;
@@ -191,7 +190,7 @@ static bool reload_table() {
191190
uint8_t* buffer = nullptr;
192191
size_t buflen = 1024;
193192
for (;;) {
194-
buffer = (uint8_t*) permit_forbidden_function::realloc(buffer, buflen);
193+
buffer = (uint8_t*) ::realloc(buffer, buflen);
195194
if (loadquery(L_GETINFO, buffer, buflen) == -1) {
196195
if (errno == ENOMEM) {
197196
buflen *= 2;
@@ -211,7 +210,7 @@ static bool reload_table() {
211210

212211
for (;;) {
213212

214-
loaded_module_t* lm = (loaded_module_t*) permit_forbidden_function::malloc(sizeof(loaded_module_t));
213+
loaded_module_t* lm = (loaded_module_t*) ::malloc(sizeof(loaded_module_t));
215214
if (!lm) {
216215
log_warning(os)("OOM.");
217216
goto cleanup;
@@ -227,7 +226,7 @@ static bool reload_table() {
227226
lm->path = g_stringlist.add(ldi->ldinfo_filename);
228227
if (!lm->path) {
229228
log_warning(os)("OOM.");
230-
permit_forbidden_function::free(lm);
229+
free(lm);
231230
goto cleanup;
232231
}
233232

@@ -249,7 +248,7 @@ static bool reload_table() {
249248
lm->member = g_stringlist.add(p_mbr_name);
250249
if (!lm->member) {
251250
log_warning(os)("OOM.");
252-
permit_forbidden_function::free(lm);
251+
free(lm);
253252
goto cleanup;
254253
}
255254
} else {
@@ -297,7 +296,7 @@ static bool reload_table() {
297296
free_entry_list(&new_list);
298297
}
299298

300-
permit_forbidden_function::free(buffer);
299+
::free(buffer);
301300

302301
return rc;
303302

src/hotspot/os/aix/os_aix.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
#include "utilities/defaultStream.hpp"
7575
#include "utilities/events.hpp"
7676
#include "utilities/growableArray.hpp"
77-
#include "utilities/permitForbiddenFunctions.hpp"
7877
#include "utilities/vmError.hpp"
7978
#if INCLUDE_JFR
8079
#include "jfr/support/jfrNativeLibraryLoadEvent.hpp"
@@ -365,9 +364,9 @@ static void query_multipage_support() {
365364
// or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
366365
// default should be 4K.
367366
{
368-
void* p = permit_forbidden_function::malloc(16*M);
367+
void* p = ::malloc(16*M);
369368
g_multipage_support.datapsize = os::Aix::query_pagesize(p);
370-
permit_forbidden_function::free(p);
369+
::free(p);
371370
}
372371

373372
// Query default shm page size (LDR_CNTRL SHMPSIZE).
@@ -1410,7 +1409,7 @@ static struct {
14101409
} vmem;
14111410

14121411
static void vmembk_add(char* addr, size_t size, size_t pagesize, int type) {
1413-
vmembk_t* p = (vmembk_t*) permit_forbidden_function::malloc(sizeof(vmembk_t));
1412+
vmembk_t* p = (vmembk_t*) ::malloc(sizeof(vmembk_t));
14141413
assert0(p);
14151414
if (p) {
14161415
MiscUtils::AutoCritSect lck(&vmem.cs);
@@ -1439,7 +1438,7 @@ static void vmembk_remove(vmembk_t* p0) {
14391438
for (vmembk_t** pp = &(vmem.first); *pp; pp = &((*pp)->next)) {
14401439
if (*pp == p0) {
14411440
*pp = p0->next;
1442-
permit_forbidden_function::free(p0);
1441+
::free(p0);
14431442
return;
14441443
}
14451444
}

src/hotspot/os/aix/porting_aix.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "runtime/os.hpp"
4040
#include "utilities/align.hpp"
4141
#include "utilities/debug.hpp"
42-
#include "utilities/permitForbiddenFunctions.hpp"
4342
#include <cxxabi.h>
4443
#include <sys/debug.h>
4544
#include <pthread.h>
@@ -251,7 +250,7 @@ bool AixSymbols::get_function_name (
251250
p_name[namelen-1] = '\0';
252251
}
253252
if (demangled_name != nullptr) {
254-
permit_forbidden_function::free(demangled_name);
253+
ALLOW_C_FUNCTION(::free, ::free(demangled_name));
255254
}
256255
}
257256
} else {
@@ -1082,7 +1081,7 @@ void* Aix_dlopen(const char* filename, int Flags, int *eno, const char** error_r
10821081
if (g_handletable_used == max_handletable) {
10831082
// No place in array anymore; increase array.
10841083
unsigned new_max = MAX2(max_handletable * 2, init_num_handles);
1085-
struct handletableentry* new_tab = (struct handletableentry*) permit_forbidden_function::realloc(p_handletable, new_max * sizeof(struct handletableentry));
1084+
struct handletableentry* new_tab = (struct handletableentry*)::realloc(p_handletable, new_max * sizeof(struct handletableentry));
10861085
assert(new_tab != nullptr, "no more memory for handletable");
10871086
if (new_tab == nullptr) {
10881087
*error_report = "dlopen: no more memory for handletable";

src/hotspot/os/bsd/decoder_machO.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,8 +28,6 @@
2828
#include "decoder_machO.hpp"
2929
#include "jvm.h"
3030
#include "memory/allocation.inline.hpp"
31-
#include "utilities/globalDefinitions.hpp"
32-
#include "utilities/permitForbiddenFunctions.hpp"
3331

3432
#include <cxxabi.h>
3533
#include <mach-o/loader.h>
@@ -45,9 +43,9 @@ bool MachODecoder::demangle(const char* symbol, char *buf, int buflen) {
4543
// may use different malloc/realloc mechanism that allocates 'buf'.
4644
if ((result = abi::__cxa_demangle(symbol, nullptr, nullptr, &status)) != nullptr) {
4745
jio_snprintf(buf, buflen, "%s", result);
48-
// call c library's free
49-
permit_forbidden_function::free(result);
50-
return true;
46+
// call c library's free
47+
::free(result);
48+
return true;
5149
}
5250
return false;
5351
}

src/hotspot/os/linux/decoder_linux.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
2727
#include "utilities/decoder_elf.hpp"
2828
#include "utilities/elfFile.hpp"
2929
#include "utilities/globalDefinitions.hpp"
30-
#include "utilities/permitForbiddenFunctions.hpp"
3130

3231
#include <cxxabi.h>
3332

@@ -47,9 +46,9 @@ bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {
4746
// may use different malloc/realloc mechanism that allocates 'buf'.
4847
if ((result = abi::__cxa_demangle(symbol, nullptr, nullptr, &status)) != nullptr) {
4948
jio_snprintf(buf, buflen, "%s", result);
50-
// call c library's free
51-
permit_forbidden_function::free(result);
52-
return true;
49+
// call c library's free
50+
ALLOW_C_FUNCTION(::free, ::free(result);)
51+
return true;
5352
}
5453
return false;
5554
}

src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
2929
#include "runtime/globals.hpp"
3030
#include "runtime/os.hpp"
3131
#include "utilities/globalDefinitions.hpp"
32-
#include "utilities/permitForbiddenFunctions.hpp"
3332

3433
#include <stdio.h>
3534
#include <unistd.h>
@@ -64,11 +63,11 @@ char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) cons
6463
strcmp(line_filesystem, filesystem) != 0 ||
6564
access(line_mountpoint, R_OK|W_OK|X_OK) != 0) {
6665
// Not a matching or accessible filesystem
67-
permit_forbidden_function::free(line_mountpoint);
66+
ALLOW_C_FUNCTION(::free, ::free(line_mountpoint);)
6867
line_mountpoint = nullptr;
6968
}
7069

71-
permit_forbidden_function::free(line_filesystem);
70+
ALLOW_C_FUNCTION(::free, ::free(line_filesystem);)
7271

7372
return line_mountpoint;
7473
}
@@ -92,14 +91,14 @@ void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpo
9291
}
9392

9493
// readline will return malloced memory. Need raw ::free, not os::free.
95-
permit_forbidden_function::free(line);
94+
ALLOW_C_FUNCTION(::free, ::free(line);)
9695
fclose(fd);
9796
}
9897

9998
void ZMountPoint::free_mountpoints(ZArray<char*>* mountpoints) const {
10099
ZArrayIterator<char*> iter(mountpoints);
101100
for (char* mountpoint; iter.next(&mountpoint);) {
102-
permit_forbidden_function::free(mountpoint); // *not* os::free
101+
ALLOW_C_FUNCTION(::free, ::free(mountpoint);) // *not* os::free
103102
}
104103
mountpoints->clear();
105104
}

src/hotspot/os/linux/mallocInfoDcmd.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
2727
#include "os_linux.hpp"
2828
#include "utilities/globalDefinitions.hpp"
2929
#include "utilities/ostream.hpp"
30-
#include "utilities/permitForbiddenFunctions.hpp"
3130

3231
#include <malloc.h>
3332

@@ -37,15 +36,15 @@ void MallocInfoDcmd::execute(DCmdSource source, TRAPS) {
3736
#ifdef __GLIBC__
3837
char* buf;
3938
size_t size;
40-
FILE* stream = ::open_memstream(&buf, &size);
39+
ALLOW_C_FUNCTION(::open_memstream, FILE* stream = ::open_memstream(&buf, &size);)
4140
if (stream == nullptr) {
4241
_output->print_cr("Error: Could not call malloc_info(3)");
4342
return;
4443
}
4544

4645
int err = os::Linux::malloc_info(stream);
4746
if (err == 0) {
48-
fflush(stream);
47+
ALLOW_C_FUNCTION(::fflush, fflush(stream);)
4948
_output->print_raw(buf);
5049
_output->cr();
5150
} else if (err == -1) {
@@ -55,8 +54,8 @@ void MallocInfoDcmd::execute(DCmdSource source, TRAPS) {
5554
} else {
5655
ShouldNotReachHere();
5756
}
58-
::fclose(stream);
59-
permit_forbidden_function::free(buf);
57+
ALLOW_C_FUNCTION(::fclose, ::fclose(stream);)
58+
ALLOW_C_FUNCTION(::free, ::free(buf);)
6059
#else
6160
_output->print_cr(malloc_info_unavailable);
6261
#endif // __GLIBC__

src/hotspot/os/posix/forbiddenFunctions_posix.hpp

-54
This file was deleted.

0 commit comments

Comments
 (0)