Commit 9874dbf1 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

fuchsia: allocate vmo/vmar instead of mmap/mprotect to create guarded memory

Fuchsia doesn't (currently? uncertain) support mprotect(...NONE...).
Work around this by using native apis to create a memory block and a
virtual memory mapping, and then leaving a guard page unmapped at the
end of the mapping.

Bug: 706592
Change-Id: I5329cf9206e5aa8056edf0cfb50b8745b9d1c83e
Reviewed-on: https://chromium-review.googlesource.com/545155
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481742}
parent 36088764
......@@ -16,6 +16,11 @@
#define MAP_ANONYMOUS MAP_ANON
#endif
#if defined(OS_FUCHSIA)
#include <magenta/process.h>
#include <magenta/syscalls.h>
#endif // OS_FUCHSIA
namespace base {
namespace trace_event {
namespace internal {
......@@ -32,25 +37,53 @@ void* AllocateGuardedVirtualMemory(size_t size) {
// Add space for a guard page at the end.
size_t map_size = size + GetGuardSize();
#if defined(OS_FUCHSIA)
// Fuchsia does not currently support PROT_NONE, see MG-546 upstream. Instead,
// create a virtual mapping with the size of the guard page unmapped after the
// block.
mx_handle_t vmo;
CHECK(mx_vmo_create(map_size, 0, &vmo) == MX_OK);
mx_handle_t vmar;
uintptr_t addr_uint;
CHECK(mx_vmar_allocate(mx_vmar_root_self(), 0, map_size,
MX_VM_FLAG_CAN_MAP_READ | MX_VM_FLAG_CAN_MAP_WRITE |
MX_VM_FLAG_CAN_MAP_SPECIFIC,
&vmar, &addr_uint) == MX_OK);
CHECK(mx_vmar_map(
vmar, 0, vmo, 0, size,
MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE | MX_VM_FLAG_SPECIFIC,
&addr_uint) == MX_OK);
CHECK(mx_handle_close(vmar) == MX_OK);
CHECK(mx_handle_close(vmo) == MX_OK);
void* addr = reinterpret_cast<void*>(addr_uint);
#else
void* addr = mmap(nullptr, map_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
PCHECK(addr != MAP_FAILED);
// Mark the last page of the allocated address space as inaccessible
// (PROT_NONE). The read/write accessible space is still at least |min_size|
// (PROT_NONE). The read/write accessible space is still at least |size|
// bytes.
void* guard_addr =
reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) + size);
int result = mprotect(guard_addr, GetGuardSize(), PROT_NONE);
PCHECK(result == 0);
#endif // defined(OS_FUCHSIA)
return addr;
}
void FreeGuardedVirtualMemory(void* address, size_t allocated_size) {
size_t size = bits::Align(allocated_size, GetPageSize()) + GetGuardSize();
#if defined(OS_FUCHSIA)
mx_status_t status = mx_vmar_unmap(
mx_vmar_root_self(), reinterpret_cast<uintptr_t>(address), size);
if (status != MX_OK) {
DLOG(ERROR) << "mx_vmar_unmap failed, status=" << status;
}
#else
munmap(address, size);
#endif
}
} // namespace internal
......
......@@ -4,14 +4,6 @@
-ActivityTrackerTest.CreateWithFileTest
-ActivityTrackerTest.ProcessDeathTest
-ActivityTrackerTest.ThreadDeathTest
-AllocationRegisterTest.ChangeContextAfterInsertion
-AllocationRegisterTest.DoubleFreeIsAllowed
-AllocationRegisterTest.DoubleInsertOverwrites
-AllocationRegisterTest.InsertRemove
-AllocationRegisterTest.InsertRemoveCollisions
-AllocationRegisterTest.InsertRemoveRandomOrder
-AllocationRegisterTest.OverflowAllocationTest
-AllocationRegisterTest.OverflowBacktraceTest
-CrashLoggingTest.ChunkValue
-CrashLoggingTest.InitSize
-CrashLoggingTest.ScopedCrashKey
......@@ -28,9 +20,6 @@
-DiscardableSharedMemoryTest.MappedSize
-DiscardableSharedMemoryTest.Purge
-DiscardableSharedMemoryTest.ZeroSize
-EventWriterTest.HeapDumpAggregation
-EventWriterTest.HeapDumpNoBacktraceNoType
-EventWriterTest.SerializeHeapProfileEventData
-FeatureListTest.StoreAndRetrieveAssociatedFeaturesFromSharedMemory
-FeatureListTest.StoreAndRetrieveFeaturesFromSharedMemory
-FieldTrialListTest.AddTrialsToAllocator
......@@ -77,8 +66,6 @@
-FileUtilTest.ExecutableExistsInPath
-FileUtilTest.FileToFILE
-FileUtilTest.NormalizeFilePathSymlinks
-HeapDumpWriterTest.BacktraceIndex
-HeapDumpWriterTest.TypeId
-LoggingTest.CheckCausesDistinctBreakpoints
-MemoryMappedFileTest.ExtendableFile
-MemoryMappedFileTest.MapLargePartialRegionInTheMiddle
......@@ -198,7 +185,6 @@
-TaskSchedulerWorkerPoolImplPostTaskBeforeStartTest.PostTasksBeforeStart
-TaskSchedulerWorkerPoolStandbyPolicyTest.InitLazy
-TaskSchedulerWorkerPoolStandbyPolicyTest.InitOne
-TraceEventTestFixture.TestTraceFlush
-TrackedObjectsTest.ReuseRetiredThreadData
-TrackedTimeTest.TrackedTimerDuration
-VerifyPathControlledByUserTest.BadPaths
......
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