From 36dc99a3237d35b1591fbdb1662ab083126ed5c5 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 12 Jun 2011 20:17:14 +0000 Subject: [PATCH] Add private get_memory_properties() syscall which allows one to retrieve the address protection bits as well as the wiring flags for an arbitrary address in a team's address space. Will be used in the debugger for the purposes of the memory inspector/editor, in order to determine whether it can in fact allow editing for the currently inspected address range. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42129 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/libroot/memory_private.h | 21 ++++++++++++++ headers/private/system/syscalls.h | 5 ++++ src/system/kernel/vm/vm.cpp | 35 ++++++++++++++++++++++++ src/system/libroot/os/Jamfile | 1 + src/system/libroot/os/memory.cpp | 17 ++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 headers/private/libroot/memory_private.h create mode 100644 src/system/libroot/os/memory.cpp diff --git a/headers/private/libroot/memory_private.h b/headers/private/libroot/memory_private.h new file mode 100644 index 0000000000..564278f6ec --- /dev/null +++ b/headers/private/libroot/memory_private.h @@ -0,0 +1,21 @@ +/* + * Copyright 2011, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#ifndef _LIBROOT_MEMORY_PRIVATE_H +#define _LIBROOT_MEMORY_PRIVATE_H + +#include + +#include + + +__BEGIN_DECLS + +status_t get_memory_properties(team_id teamID, const void* address, + uint32* _protected, uint32* _lock); + +__END_DECLS + + +#endif // _LIBROOT_MEMORY_PRIVATE_H diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index 09488ba3af..3ef1eba1d0 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -435,6 +435,11 @@ extern status_t _kern_sync_memory(void *address, size_t size, int flags); extern status_t _kern_memory_advice(void *address, size_t size, uint32 advice); +extern status_t _kern_get_memory_properties(team_id teamID, + const void *address, + uint32* _protected, + uint32* _lock); + /* kernel port functions */ extern port_id _kern_create_port(int32 queue_length, const char *name); extern status_t _kern_close_port(port_id id); diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index a8fc0a92aa..8717c33a7f 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -6303,6 +6303,41 @@ _user_memory_advice(void* address, size_t size, uint32 advice) } +status_t +_user_get_memory_properties(team_id teamID, const void* address, + uint32* _protected, uint32* _lock) +{ + if (!IS_USER_ADDRESS(_protected) || !IS_USER_ADDRESS(_lock)) + return B_BAD_ADDRESS; + + AddressSpaceReadLocker locker; + status_t error = locker.SetTo(teamID); + if (error != B_OK) + return error; + + VMArea* area = locker.AddressSpace()->LookupArea((addr_t)address); + if (area == NULL) + return B_NO_MEMORY; + + + uint32 protection = area->protection; + if (area->page_protections != NULL) + protection = get_area_page_protection(area, (addr_t)address); + + uint32 wiring = area->wiring; + + locker.Unlock(); + + error = user_memcpy(_protected, &protection, sizeof(protection)); + if (error != B_OK) + return error; + + error = user_memcpy(_lock, &wiring, sizeof(wiring)); + + return error; +} + + // #pragma mark -- compatibility diff --git a/src/system/libroot/os/Jamfile b/src/system/libroot/os/Jamfile index 6fbd278ac8..fcdb6e2cd5 100644 --- a/src/system/libroot/os/Jamfile +++ b/src/system/libroot/os/Jamfile @@ -20,6 +20,7 @@ MergeObject os_main.o : fs_query.cpp fs_volume.c image.cpp + memory.cpp parsedate.cpp port.c scheduler.c diff --git a/src/system/libroot/os/memory.cpp b/src/system/libroot/os/memory.cpp new file mode 100644 index 0000000000..935d212fd0 --- /dev/null +++ b/src/system/libroot/os/memory.cpp @@ -0,0 +1,17 @@ +/* + * Copyright 2011, Rene Gollent, rene@gollent.com. + * Distributed under the terms of the MIT License. + */ +#include + +#include + +#include + + +status_t +get_memory_properties(team_id teamID, const void* address, uint32* _protected, + uint32* _lock) +{ + return _kern_get_memory_properties(teamID, address, _protected, _lock); +}