diff options
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingUtil.c')
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingUtil.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c index bf5a9670fe18..4fa792b72eac 100644 --- a/compiler-rt/lib/profile/InstrProfilingUtil.c +++ b/compiler-rt/lib/profile/InstrProfilingUtil.c @@ -12,12 +12,13 @@ #include <windows.h> #include "WindowsMMap.h" #else +#include <errno.h> +#include <fcntl.h> #include <sys/file.h> +#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> -#include <fcntl.h> -#include <errno.h> #endif #ifdef COMPILER_RT_HAS_UNAME @@ -32,6 +33,10 @@ #include <sys/prctl.h> #endif +#if defined(__Fuchsia__) +#include <zircon/syscalls.h> +#endif + #include "InstrProfiling.h" #include "InstrProfilingUtil.h" @@ -330,3 +335,21 @@ COMPILER_RT_VISIBILITY void lprofRestoreSigKill() { prctl(PR_SET_PDEATHSIG, SIGKILL); #endif } + +COMPILER_RT_VISIBILITY int lprofReleaseMemoryPagesToOS(uintptr_t Begin, + uintptr_t End) { + size_t PageSize = getpagesize(); + uintptr_t BeginAligned = lprofRoundUpTo((uintptr_t)Begin, PageSize); + uintptr_t EndAligned = lprofRoundDownTo((uintptr_t)End, PageSize); + if (BeginAligned < EndAligned) { +#if defined(__Fuchsia__) + return _zx_vmar_op_range(_zx_vmar_root_self(), ZX_VMAR_OP_DECOMMIT, + (zx_vaddr_t)BeginAligned, + EndAligned - BeginAligned, NULL, 0); +#else + return madvise((void *)BeginAligned, EndAligned - BeginAligned, + MADV_DONTNEED); +#endif + } + return 0; +} |