From 8e0e372a388434a0553810e2b958e59a26a6bd96 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Queru <jbq@google.com>
Date: Thu, 14 Oct 2010 14:29:00 -0700
Subject: [PATCH] Set PROT_EXEC on the whole pixelflinger code cache.

The pointer difference between word pointers is a number
of words, and it needs to be multiplied by the size of a word
to get a proper byte size.

Without this, we tend to see crashes when the code crosses
a page boundary.

Bug: 3026204
Bug: 3097482
Change-Id: I37776d26d5afcdb1da71680de02fbb95e6548371
---
 libpixelflinger/codeflinger/CodeCache.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libpixelflinger/codeflinger/CodeCache.cpp b/libpixelflinger/codeflinger/CodeCache.cpp
index 5877ff4a56..125c3ce05c 100644
--- a/libpixelflinger/codeflinger/CodeCache.cpp
+++ b/libpixelflinger/codeflinger/CodeCache.cpp
@@ -94,7 +94,7 @@ void Assembly::ensureMbaseExecutable()
     long pagemask = ~(pagesize - 1);  // assumes pagesize is a power of 2
 
     uint32_t* pageStart = (uint32_t*) (((uintptr_t) mBase) & pagemask);
-    size_t adjustedLength = mBase - pageStart + mSize;
+    size_t adjustedLength = (mBase - pageStart) * sizeof(uint32_t) + mSize;
 
     if (mBase && mprotect(pageStart, adjustedLength, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
         mspace_free(getMspace(), mBase);
-- 
GitLab