aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-04-05 01:42:14 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-05 01:42:14 +0000
commitb97459693eefb6c8e39e560cd1febef6177afd82 (patch)
treec9545b5f84292b7a8e552216ec5e54f250f3d2ec
parent1d141ce1c81a0a1fa71ae47f19d12aaca0e8f819 (diff)
parent8bd83d8c98519b0c97c6a978b953cf28919ff236 (diff)
downloadbionic-b97459693eefb6c8e39e560cd1febef6177afd82.tar.gz
Merge "Hide overaligned global address from the compiler." into main
-rw-r--r--libc/arch-x86/bionic/setjmp.S4
-rw-r--r--libc/private/WriteProtected.h19
2 files changed, 15 insertions, 8 deletions
diff --git a/libc/arch-x86/bionic/setjmp.S b/libc/arch-x86/bionic/setjmp.S
index d22683a57..b9e6bdf92 100644
--- a/libc/arch-x86/bionic/setjmp.S
+++ b/libc/arch-x86/bionic/setjmp.S
@@ -65,19 +65,16 @@
.endm
ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
- movl 4(%esp),%ecx
mov $1,%eax
jmp .L_sigsetjmp
END(setjmp)
ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
- movl 4(%esp),%ecx
movl $0,%eax
jmp .L_sigsetjmp
END(_setjmp)
ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
- movl 4(%esp),%ecx
movl 8(%esp),%eax
.L_sigsetjmp:
@@ -88,6 +85,7 @@ ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
PIC_EPILOGUE
// Record the setjmp cookie and whether or not we're saving the signal mask.
+ movl 4(%esp),%ecx
movl %eax,(_JB_SIGFLAG * 4)(%ecx)
// Do we need to save the signal mask?
diff --git a/libc/private/WriteProtected.h b/libc/private/WriteProtected.h
index fac07cb61..bbe35e529 100644
--- a/libc/private/WriteProtected.h
+++ b/libc/private/WriteProtected.h
@@ -51,30 +51,39 @@ class WriteProtected {
void initialize() {
// Not strictly necessary, but this will hopefully segfault if we initialize
// multiple times by accident.
- memset(&contents, 0, sizeof(contents));
+ memset(contents_addr(), 0, sizeof(contents));
set_protection(PROT_READ);
}
const T* operator->() {
- return &contents.value;
+ return &contents_addr()->value;
}
const T& operator*() {
- return contents.value;
+ return contents_addr()->value;
}
template <typename Mutator>
void mutate(Mutator mutator) {
set_protection(PROT_READ | PROT_WRITE);
- mutator(&contents.value);
+ mutator(&contents_addr()->value);
set_protection(PROT_READ);
}
private:
WriteProtectedContents<T> contents;
- void set_protection(int prot) {
+ 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.