From 0f4242de4031fba2e3f596c273a271cc782063f0 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Thu, 10 Sep 2009 01:40:46 +0000 Subject: [PATCH] Implement a vm_block_address_range() function which creates an area with no mapped pages and a non-read and non-write protection to block a certain address range from being used by anything. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33030 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/vm.h | 1 + src/system/kernel/vm/vm.cpp | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/headers/private/kernel/vm.h b/headers/private/kernel/vm.h index d56c56db25..d5ae0cd0a9 100644 --- a/headers/private/kernel/vm.h +++ b/headers/private/kernel/vm.h @@ -60,6 +60,7 @@ area_id create_area_etc(team_id team, const char *name, void **address, area_id transfer_area(area_id id, void** _address, uint32 addressSpec, team_id target, bool kernel); +status_t vm_block_address_range(const char* name, void* address, addr_t size); status_t vm_unreserve_address_range(team_id team, void *address, addr_t size); status_t vm_reserve_address_range(team_id team, void **_address, uint32 addressSpec, addr_t size, uint32 flags); diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index f95b491572..001a104dfa 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -1672,6 +1672,46 @@ err1: } +status_t +vm_block_address_range(const char* name, void* address, addr_t size) +{ + if (!arch_vm_supports_protection(0)) + return B_NOT_SUPPORTED; + + AddressSpaceWriteLocker locker; + status_t status = locker.SetTo(vm_kernel_address_space_id()); + if (status != B_OK) + return status; + + vm_address_space* addressSpace = locker.AddressSpace(); + + // create an anonymous cache + vm_cache* cache; + status = VMCacheFactory::CreateAnonymousCache(cache, false, 0, 0, false); + if (status != B_OK) + return status; + + cache->temporary = 1; + cache->virtual_end = size; + cache->scan_skip = 1; + cache->Lock(); + + vm_area* area; + void *areaAddress = address; + status = map_backing_store(addressSpace, cache, &areaAddress, 0, size, + B_EXACT_ADDRESS, B_ALREADY_WIRED, 0, REGION_NO_PRIVATE_MAP, &area, name, + false, true); + if (status != B_OK) { + cache->ReleaseRefAndUnlock(); + return status; + } + + cache->Unlock(); + area->cache_type = CACHE_TYPE_RAM; + return area->id; +} + + status_t vm_unreserve_address_range(team_id team, void* address, addr_t size) {