Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from ChengJin01/ffi_inline_libc_func_jdk20
Browse files Browse the repository at this point in the history
[FFI]Inline the missing libc functions for symbol lookup on AIX
  • Loading branch information
pshipton authored Mar 4, 2023
2 parents f989025 + 4bc22b2 commit 91eb72c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 7 deletions.
37 changes: 37 additions & 0 deletions closed/src/java.base/aix/native/libsyslookup/syslookup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* IBM designates this particular file as subject to the "Classpath" exception
* as provided by IBM in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
*
* ===========================================================================
*/

#include <fstab.h>
#include <setjmp.h>
#include <string.h>
#include <strings.h>

/* The function list inlines the libc functions which
* are missing in loading the default library.
*/
__attribute__((visibility("default"))) void* funcs[] = {
&bcopy, &endfsent, &getfsent, &getfsfile, &getfsspec, &longjmp,
&memcpy, &memmove, &setfsent, &setjmp, &siglongjmp, &strcat,
&strcpy, &strncat, &strncpy
};
43 changes: 36 additions & 7 deletions src/java.base/share/classes/jdk/internal/foreign/SystemLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,27 @@ private static SymbolLookup makeAixLookup() {
NativeLibrary lib = NativeLibraries.defaultLibrary;
return name -> {
Objects.requireNonNull(name);
try {
long addr = lib.lookup(name);
return (addr == 0) ?
Optional.empty() :
Optional.of(MemorySegment.ofAddress(addr, 0, SegmentScope.global()));
} catch (NoSuchMethodException e) {
return Optional.empty();
MemorySegment funcAddr = null;
AixFuncSymbols symbol = AixFuncSymbols.valueOfOrNull(name);
if (symbol == null) {
try {
/* Look up the libc functions in the default library. */
funcAddr = MemorySegment.ofAddress(lib.lookup(name));
} catch (NoSuchMethodException e) {
return Optional.empty();
}
} else {
/* Directly load the specified library with the libc functions
* missing in the default library.
*/
SymbolLookup funcsLibLookup =
libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
MemorySegment funcs = MemorySegment.ofAddress(funcsLibLookup.find("funcs").orElseThrow().address(),
ADDRESS.byteSize() * AixFuncSymbols.values().length, SegmentScope.global());
funcAddr = funcs.getAtIndex(ADDRESS, symbol.ordinal());
}

return Optional.of(MemorySegment.ofAddress(funcAddr.address(), 0L, SegmentScope.global()));
};
}

Expand Down Expand Up @@ -231,4 +244,20 @@ static WindowsFallbackSymbols valueOfOrNull(String name) {
}
}
}

/* Inlined libc function symbols missing in the default library. */
public enum AixFuncSymbols {
bcopy, endfsent, getfsent, getfsfile, getfsspec, longjmp,
memcpy, memmove, setfsent, setjmp, siglongjmp, strcat,
strcpy, strncat, strncpy
;

static AixFuncSymbols valueOfOrNull(String name) {
try {
return valueOf(name);
} catch (IllegalArgumentException e) {
return null;
}
}
}
}

0 comments on commit 91eb72c

Please sign in to comment.