Skip to content

Commit 9e7c0b1

Browse files
authored
[OpenMP] Implement __kmp_is_address_mapped on DragonFlyBSD. (#82895)
implement internal __kmp_is_address_mapped.
1 parent f920b74 commit 9e7c0b1

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ function(libomp_get_libflags libflags)
144144
libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
145145
libomp_append(libflags_local "-lm")
146146
libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
147+
if (${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly")
148+
libomp_append(libflags_local "-lkvm")
149+
endif()
147150
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|Solaris")
148151
libomp_append(libflags_local -lm)
149152
endif()

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
#include <sys/sysctl.h>
6060
#include <sys/user.h>
6161
#include <pthread_np.h>
62+
#if KMP_OS_DRAGONFLY
63+
#include <kvm.h>
64+
#endif
6265
#elif KMP_OS_NETBSD || KMP_OS_OPENBSD
6366
#include <sys/types.h>
6467
#include <sys/sysctl.h>
@@ -1042,9 +1045,7 @@ extern "C" void __kmp_reap_monitor(kmp_info_t *th) {
10421045
#else
10431046
// Empty symbol to export (see exports_so.txt) when
10441047
// monitor thread feature is disabled
1045-
extern "C" void __kmp_reap_monitor(kmp_info_t *th) {
1046-
(void)th;
1047-
}
1048+
extern "C" void __kmp_reap_monitor(kmp_info_t *th) { (void)th; }
10481049
#endif // KMP_USE_MONITOR
10491050

10501051
void __kmp_reap_worker(kmp_info_t *th) {
@@ -2133,7 +2134,47 @@ int __kmp_is_address_mapped(void *addr) {
21332134
lw += cursz;
21342135
}
21352136
kmpc_free(buf);
2137+
#elif KMP_OS_DRAGONFLY
2138+
char err[_POSIX2_LINE_MAX];
2139+
kinfo_proc *proc;
2140+
vmspace sp;
2141+
vm_map *cur;
2142+
vm_map_entry entry, *c;
2143+
struct proc p;
2144+
kvm_t *fd;
2145+
uintptr_t uaddr;
2146+
int num;
2147+
2148+
fd = kvm_openfiles(nullptr, nullptr, nullptr, O_RDONLY, err);
2149+
if (!fd) {
2150+
return 0;
2151+
}
2152+
2153+
proc = kvm_getprocs(fd, KERN_PROC_PID, getpid(), &num);
2154+
2155+
if (kvm_read(fd, static_cast<uintptr_t>(proc->kp_paddr), &p, sizeof(p)) !=
2156+
sizeof(p) ||
2157+
kvm_read(fd, reinterpret_cast<uintptr_t>(p.p_vmspace), &sp, sizeof(sp)) !=
2158+
sizeof(sp)) {
2159+
kvm_close(fd);
2160+
return 0;
2161+
}
2162+
2163+
(void)rc;
2164+
cur = &sp.vm_map;
2165+
uaddr = reinterpret_cast<uintptr_t>(addr);
2166+
for (c = kvm_vm_map_entry_first(fd, cur, &entry); c;
2167+
c = kvm_vm_map_entry_next(fd, c, &entry)) {
2168+
if ((uaddr >= entry.ba.start) && (uaddr <= entry.ba.end)) {
2169+
if ((entry.protection & VM_PROT_READ) != 0 &&
2170+
(entry.protection & VM_PROT_WRITE) != 0) {
2171+
found = 1;
2172+
break;
2173+
}
2174+
}
2175+
}
21362176

2177+
kvm_close(fd);
21372178
#elif KMP_OS_DARWIN
21382179

21392180
/* On OS X*, /proc pseudo filesystem is not available. Try to read memory
@@ -2212,9 +2253,9 @@ int __kmp_is_address_mapped(void *addr) {
22122253
}
22132254
#elif KMP_OS_WASI
22142255
found = (int)addr < (__builtin_wasm_memory_size(0) * PAGESIZE);
2215-
#elif KMP_OS_DRAGONFLY || KMP_OS_SOLARIS || KMP_OS_AIX
2256+
#elif KMP_OS_SOLARIS || KMP_OS_AIX
22162257

2217-
// FIXME(DragonFly, Solaris, AIX): Implement this
2258+
// FIXME(Solaris, AIX): Implement this
22182259
found = 1;
22192260

22202261
#else

0 commit comments

Comments
 (0)