[Openmp-commits] [openmp] 928db7e - [OpenMP][AIX] Implement __kmp_is_address_mapped() for AIX (#90516)
via Openmp-commits
openmp-commits at lists.llvm.org
Tue Apr 30 13:58:51 PDT 2024
Author: Xing Xue
Date: 2024-04-30T16:58:47-04:00
New Revision: 928db7e7edc5ffeaf92e85610068852ee94b26fb
URL: https://github.com/llvm/llvm-project/commit/928db7e7edc5ffeaf92e85610068852ee94b26fb
DIFF: https://github.com/llvm/llvm-project/commit/928db7e7edc5ffeaf92e85610068852ee94b26fb.diff
LOG: [OpenMP][AIX] Implement __kmp_is_address_mapped() for AIX (#90516)
This patch implements `__kmp_is_address_mapped()` for AIX by calling
`loadquery()` to get the load info of the process and then checking if
the address falls within the range of the data segment of one of the
loaded modules.
Added:
Modified:
openmp/runtime/src/z_Linux_util.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index 11ce083f4801d3..affb577a539367 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -29,7 +29,9 @@
#include <semaphore.h>
#endif // KMP_OS_LINUX
#include <sys/resource.h>
-#if !KMP_OS_AIX
+#if KMP_OS_AIX
+#include <sys/ldr.h>
+#else
#include <sys/syscall.h>
#endif
#include <sys/time.h>
@@ -2338,9 +2340,48 @@ int __kmp_is_address_mapped(void *addr) {
found = (int)addr < (__builtin_wasm_memory_size(0) * PAGESIZE);
#elif KMP_OS_AIX
- (void)rc;
- // FIXME(AIX): Implement this
- found = 1;
+ uint32_t loadQueryBufSize = 4096u; // Default loadquery buffer size.
+ char *loadQueryBuf;
+
+ for (;;) {
+ loadQueryBuf = (char *)KMP_INTERNAL_MALLOC(loadQueryBufSize);
+ if (loadQueryBuf == NULL) {
+ return 0;
+ }
+
+ rc = loadquery(L_GETXINFO | L_IGNOREUNLOAD, loadQueryBuf, loadQueryBufSize);
+ if (rc < 0) {
+ KMP_INTERNAL_FREE(loadQueryBuf);
+ if (errno != ENOMEM) {
+ return 0;
+ }
+ // errno == ENOMEM; double the size.
+ loadQueryBufSize <<= 1;
+ continue;
+ }
+ // Obtained the load info successfully.
+ break;
+ }
+
+ struct ld_xinfo *curLdInfo = (struct ld_xinfo *)loadQueryBuf;
+
+ // Loop through the load info to find if there is a match.
+ for (;;) {
+ uintptr_t curDataStart = (uintptr_t)curLdInfo->ldinfo_dataorg;
+ uintptr_t curDataEnd = curDataStart + curLdInfo->ldinfo_datasize;
+
+ // The data segment is readable and writable.
+ if (curDataStart <= (uintptr_t)addr && (uintptr_t)addr < curDataEnd) {
+ found = 1;
+ break;
+ }
+ if (curLdInfo->ldinfo_next == 0u) {
+ // Reached the end of load info.
+ break;
+ }
+ curLdInfo = (struct ld_xinfo *)((char *)curLdInfo + curLdInfo->ldinfo_next);
+ }
+ KMP_INTERNAL_FREE(loadQueryBuf);
#else
More information about the Openmp-commits
mailing list