Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 85e2459

Browse files
committed
[OpenMP] FreeBSD address check if mapped more native
/proc unless Linux layer compatibility is activated for CentOS is activated is not present thus relying on a more native for checking the address. Reviewers: Hahnfeld, kongyl, jdoerfert, jlpeyton, AndreyChurbanov, emaster, dim Reviewed By: Hahnfeld Differential Revision: https://reviews.llvm.org/D67326 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@373152 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent dbb024c commit 85e2459

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

runtime/src/z_Linux_util.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
#include <mach/mach.h>
5151
#include <sys/sysctl.h>
5252
#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD
53+
#include <sys/types.h>
54+
#include <sys/sysctl.h>
55+
#include <sys/user.h>
5356
#include <pthread_np.h>
5457
#elif KMP_OS_NETBSD
5558
#include <sys/types.h>
@@ -1979,7 +1982,7 @@ int __kmp_is_address_mapped(void *addr) {
19791982
int found = 0;
19801983
int rc;
19811984

1982-
#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_HURD
1985+
#if KMP_OS_LINUX || KMP_OS_HURD
19831986

19841987
/* On GNUish OSes, read the /proc/<pid>/maps pseudo-file to get all the address
19851988
ranges mapped into the address space. */
@@ -2017,6 +2020,44 @@ int __kmp_is_address_mapped(void *addr) {
20172020
// Free resources.
20182021
fclose(file);
20192022
KMP_INTERNAL_FREE(name);
2023+
#elif KMP_OS_FREEBSD
2024+
char *buf;
2025+
size_t lstsz;
2026+
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid()};
2027+
rc = sysctl(mib, 4, NULL, &lstsz, NULL, 0);
2028+
if (rc < 0)
2029+
return 0;
2030+
// We pass from number of vm entry's semantic
2031+
// to size of whole entry map list.
2032+
lstsz = lstsz * 4 / 3;
2033+
buf = reinterpret_cast<char *>(kmpc_malloc(lstsz));
2034+
rc = sysctl(mib, 4, buf, &lstsz, NULL, 0);
2035+
if (rc < 0) {
2036+
kmpc_free(buf);
2037+
return 0;
2038+
}
2039+
2040+
char *lw = buf;
2041+
char *up = buf + lstsz;
2042+
2043+
while (lw < up) {
2044+
struct kinfo_vmentry *cur = reinterpret_cast<struct kinfo_vmentry *>(lw);
2045+
size_t cursz = cur->kve_structsize;
2046+
if (cursz == 0)
2047+
break;
2048+
void *start = reinterpret_cast<void *>(cur->kve_start);
2049+
void *end = reinterpret_cast<void *>(cur->kve_end);
2050+
// Readable/Writable addresses within current map entry
2051+
if ((addr >= start) && (addr < end)) {
2052+
if ((cur->kve_protection & KVME_PROT_READ) != 0 &&
2053+
(cur->kve_protection & KVME_PROT_WRITE) != 0) {
2054+
found = 1;
2055+
break;
2056+
}
2057+
}
2058+
lw += cursz;
2059+
}
2060+
kmpc_free(buf);
20202061

20212062
#elif KMP_OS_DARWIN
20222063

0 commit comments

Comments
 (0)