Commit 7d291c72 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[heap] Add a read-only permission

Add a new permission kRead to PageAllocator::Permission and
OS::MemoryPermission and implement it in platform-*.

Not used yet, because it needs corresponding changes in chromium.

Bug: v8:7464
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I9f84251eff593536cbcc1cde04641d696c79d65c
Reviewed-on: https://chromium-review.googlesource.com/1006756Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52636}
parent 04d883cc
...@@ -206,6 +206,7 @@ class PageAllocator { ...@@ -206,6 +206,7 @@ class PageAllocator {
*/ */
enum Permission { enum Permission {
kNoAccess, kNoAccess,
kRead,
kReadWrite, kReadWrite,
// TODO(hpayer): Remove this flag. Memory should never be rwx. // TODO(hpayer): Remove this flag. Memory should never be rwx.
kReadWriteExecute, kReadWriteExecute,
......
...@@ -34,6 +34,8 @@ DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) { ...@@ -34,6 +34,8 @@ DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) { switch (access) {
case OS::MemoryPermission::kNoAccess: case OS::MemoryPermission::kNoAccess:
return PAGE_NOACCESS; return PAGE_NOACCESS;
case OS::MemoryPermission::kRead:
return PAGE_READONLY;
case OS::MemoryPermission::kReadWrite: case OS::MemoryPermission::kReadWrite:
return PAGE_READWRITE; return PAGE_READWRITE;
case OS::MemoryPermission::kReadWriteExecute: case OS::MemoryPermission::kReadWriteExecute:
......
...@@ -19,6 +19,8 @@ uint32_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) { ...@@ -19,6 +19,8 @@ uint32_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) { switch (access) {
case OS::MemoryPermission::kNoAccess: case OS::MemoryPermission::kNoAccess:
return 0; // no permissions return 0; // no permissions
case OS::MemoryPermission::kRead:
return ZX_VM_FLAG_PERM_READ;
case OS::MemoryPermission::kReadWrite: case OS::MemoryPermission::kReadWrite:
return ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE; return ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE;
case OS::MemoryPermission::kReadWriteExecute: case OS::MemoryPermission::kReadWriteExecute:
......
...@@ -112,6 +112,8 @@ int GetProtectionFromMemoryPermission(OS::MemoryPermission access) { ...@@ -112,6 +112,8 @@ int GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) { switch (access) {
case OS::MemoryPermission::kNoAccess: case OS::MemoryPermission::kNoAccess:
return PROT_NONE; return PROT_NONE;
case OS::MemoryPermission::kRead:
return PROT_READ;
case OS::MemoryPermission::kReadWrite: case OS::MemoryPermission::kReadWrite:
return PROT_READ | PROT_WRITE; return PROT_READ | PROT_WRITE;
case OS::MemoryPermission::kReadWriteExecute: case OS::MemoryPermission::kReadWriteExecute:
......
...@@ -758,6 +758,8 @@ DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) { ...@@ -758,6 +758,8 @@ DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) { switch (access) {
case OS::MemoryPermission::kNoAccess: case OS::MemoryPermission::kNoAccess:
return PAGE_NOACCESS; return PAGE_NOACCESS;
case OS::MemoryPermission::kRead:
return PAGE_READONLY;
case OS::MemoryPermission::kReadWrite: case OS::MemoryPermission::kReadWrite:
return PAGE_READWRITE; return PAGE_READWRITE;
case OS::MemoryPermission::kReadWriteExecute: case OS::MemoryPermission::kReadWriteExecute:
......
...@@ -159,6 +159,7 @@ class V8_BASE_EXPORT OS { ...@@ -159,6 +159,7 @@ class V8_BASE_EXPORT OS {
// v8::PageAllocator. // v8::PageAllocator.
enum class MemoryPermission { enum class MemoryPermission {
kNoAccess, kNoAccess,
kRead,
kReadWrite, kReadWrite,
// TODO(hpayer): Remove this flag. Memory should never be rwx. // TODO(hpayer): Remove this flag. Memory should never be rwx.
kReadWriteExecute, kReadWriteExecute,
......
...@@ -110,6 +110,7 @@ sigjmp_buf MemoryAllocationPermissionsTest::continuation_; ...@@ -110,6 +110,7 @@ sigjmp_buf MemoryAllocationPermissionsTest::continuation_;
TEST_F(MemoryAllocationPermissionsTest, DoTest) { TEST_F(MemoryAllocationPermissionsTest, DoTest) {
TestPermissions(PageAllocator::Permission::kNoAccess, false, false); TestPermissions(PageAllocator::Permission::kNoAccess, false, false);
TestPermissions(PageAllocator::Permission::kRead, true, false);
TestPermissions(PageAllocator::Permission::kReadWrite, true, true); TestPermissions(PageAllocator::Permission::kReadWrite, true, true);
TestPermissions(PageAllocator::Permission::kReadWriteExecute, true, true); TestPermissions(PageAllocator::Permission::kReadWriteExecute, true, true);
TestPermissions(PageAllocator::Permission::kReadExecute, true, false); TestPermissions(PageAllocator::Permission::kReadExecute, true, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment