// Write protected wrapper class that aligns its contents to a page boundary, // and sets the memory protection to be non-writable, except when being modified // explicitly. template <typename T> class WriteProtected { public:
static_assert(sizeof(T) < max_android_page_size(), "WriteProtected only supports contents up to max_android_page_size()");
void initialize() { // Not strictly necessary, but this will hopefully segfault if we initialize // multiple times by accident.
memset(contents_addr(), 0, sizeof(contents));
set_protection(PROT_READ);
}
WriteProtectedContents<T>* contents_addr() { auto addr = &contents; // Hide the fact that we're returning the address of contents from the compiler. // Otherwise it may generate code assuming alignment of 64KB even though the // variable is only guaranteed to have 4KB alignment.
__asm__ __volatile__("" : "+r"(addr)); return addr;
}
void set_protection(int prot) { auto addr = contents_addr(); #if __has_feature(hwaddress_sanitizer) // The mprotect system call does not currently untag pointers, so do it // ourselves.
addr = untag_address(addr); #endif if (mprotect(reinterpret_cast<void*>(addr), max_android_page_size(), prot) == -1) {
async_safe_fatal("WriteProtected mprotect %x failed: %m", prot);
}
}
};
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.