Changeset View
Changeset View
Standalone View
Standalone View
compiler-rt/lib/scudo/standalone/linux.cpp
Show All 22 Lines | |||||
#include <string.h> | #include <string.h> | ||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/syscall.h> | #include <sys/syscall.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#if SCUDO_ANDROID | |||||
#include <sys/prctl.h> | #include <sys/prctl.h> | ||||
// Definitions of prctl arguments to set a vma name in Android kernels. | // Definitions of prctl arguments to set a vma name in kernels (Linux from 5.17). | ||||
#define ANDROID_PR_SET_VMA 0x53564d41 | #ifndef PR_SET_VMA | ||||
#define ANDROID_PR_SET_VMA_ANON_NAME 0 | #define PR_SET_VMA 0x53564d41 | ||||
#define PR_SET_VMA_ANON_NAME 0 | |||||
#endif | #endif | ||||
namespace scudo { | namespace scudo { | ||||
uptr getPageSize() { return static_cast<uptr>(sysconf(_SC_PAGESIZE)); } | uptr getPageSize() { return static_cast<uptr>(sysconf(_SC_PAGESIZE)); } | ||||
void NORETURN die() { abort(); } | void NORETURN die() { abort(); } | ||||
Show All 17 Lines | #endif | ||||
if (Addr) | if (Addr) | ||||
MmapFlags |= MAP_FIXED; | MmapFlags |= MAP_FIXED; | ||||
void *P = mmap(Addr, Size, MmapProt, MmapFlags, -1, 0); | void *P = mmap(Addr, Size, MmapProt, MmapFlags, -1, 0); | ||||
if (P == MAP_FAILED) { | if (P == MAP_FAILED) { | ||||
if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM) | if (!(Flags & MAP_ALLOWNOMEM) || errno != ENOMEM) | ||||
dieOnMapUnmapError(errno == ENOMEM ? Size : 0); | dieOnMapUnmapError(errno == ENOMEM ? Size : 0); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
#if SCUDO_ANDROID | |||||
if (Name) | if (Name) | ||||
prctl(ANDROID_PR_SET_VMA, ANDROID_PR_SET_VMA_ANON_NAME, P, Size, Name); | prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, P, Size, Name); | ||||
#endif | |||||
return P; | return P; | ||||
} | } | ||||
void unmap(void *Addr, uptr Size, UNUSED uptr Flags, | void unmap(void *Addr, uptr Size, UNUSED uptr Flags, | ||||
UNUSED MapPlatformData *Data) { | UNUSED MapPlatformData *Data) { | ||||
if (munmap(Addr, Size) != 0) | if (munmap(Addr, Size) != 0) | ||||
dieOnMapUnmapError(); | dieOnMapUnmapError(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |