From 010a1e70beecbe022e7b586c2d2a962adb8cf4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 19 Aug 2003 14:47:31 +0000 Subject: [PATCH] Made the delete_area() function BeOS compatible; it now allows any area to delete. Added a comment how the security should be improved by adding another restriction. Also mentioned that it's probably a bad idea that vm_delete_region() will not wait until the region has been freed, but just "mark" it as to be freed. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4319 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/vm/vm.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/kernel/core/vm/vm.c b/src/kernel/core/vm/vm.c index 0826b8e067..469a2c4aa7 100755 --- a/src/kernel/core/vm/vm.c +++ b/src/kernel/core/vm/vm.c @@ -900,22 +900,35 @@ region_id vm_clone_region(aspace_id aid, char *name, void **address, int addr_ty return new_region->id; } -static int __vm_delete_region(vm_address_space *aspace, vm_region *region) + +static int +__vm_delete_region(vm_address_space *aspace, vm_region *region) { - if(region->aspace == aspace) + // ToDo: allowing a NULL aspace parameter reduces security + // but is needed for BeOS compatibility - we should consider + // introducing team privileges for those things, though. + // Also, I am really not sure if it's a good idea not to + // wait until the area has really been freed - code following + // might rely on the address space to available again, and + // there is no other way to wait for the completion of the + // deletion. + if (aspace == NULL || region->aspace == aspace) vm_put_region(region); + return B_NO_ERROR; } -static int _vm_delete_region(vm_address_space *aspace, region_id rid) + +static int +_vm_delete_region(vm_address_space *aspace, region_id rid) { // vm_region *temp, *last = NULL; vm_region *region; - dprintf("vm_delete_region: aspace id 0x%lx, region id 0x%lx\n", aspace->id, rid); + dprintf("vm_delete_region: aspace id 0x%lx, region id 0x%lx\n", aspace ? aspace->id : -1, rid); region = vm_get_region_by_id(rid); - if(region == NULL) + if (region == NULL) return ERR_VM_INVALID_REGION; __vm_delete_region(aspace, region); @@ -924,7 +937,9 @@ static int _vm_delete_region(vm_address_space *aspace, region_id rid) return 0; } -int vm_delete_region(aspace_id aid, region_id rid) + +int +vm_delete_region(aspace_id aid, region_id rid) { vm_address_space *aspace; int err; @@ -938,7 +953,9 @@ int vm_delete_region(aspace_id aid, region_id rid) return err; } -static void _vm_put_region(vm_region *region, bool aspace_locked) + +static void +_vm_put_region(vm_region *region, bool aspace_locked) { vm_region *temp, *last = NULL; vm_address_space *aspace; @@ -2344,8 +2361,7 @@ create_area(const char *name, void **address, uint32 addressSpec, size_t size, u status_t delete_area(area_id area) { - // ToDo: works only correctly for kernel areas! - return vm_delete_region(vm_get_kernel_aspace_id(), area); + return vm_delete_region(NULL, area); } @@ -2387,6 +2403,6 @@ status_t _user_delete_area(area_id area) { // ToDo: works only correctly if the area belongs to the caller! - return vm_delete_region(vm_get_current_user_aspace_id(), area); + return _vm_delete_region(NULL, area); }