summaryrefslogtreecommitdiff
path: root/Kernel/ProcessSpecificExposed.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-23 17:58:05 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-24 14:57:51 +0200
commitcf16b2c8e64709d570c5f54a981017d217e95ed0 (patch)
tree16c9efdaaa579ae51682a51a58949ce02c3d2092 /Kernel/ProcessSpecificExposed.cpp
parentd6ef18f587d4a7e4f58487c84e0b9eb260f3ec5a (diff)
downloadserenity-cf16b2c8e64709d570c5f54a981017d217e95ed0.zip
Kernel: Wrap process address spaces in SpinlockProtected
This forces anyone who wants to look into and/or manipulate an address space to lock it. And this replaces the previous, more flimsy, manual spinlock use. Note that pointers *into* the address space are not safe to use after you unlock the space. We've got many issues like this, and we'll have to track those down as wlel.
Diffstat (limited to 'Kernel/ProcessSpecificExposed.cpp')
-rw-r--r--Kernel/ProcessSpecificExposed.cpp78
1 files changed, 40 insertions, 38 deletions
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp
index 1bda213e5c..2e4cea6c29 100644
--- a/Kernel/ProcessSpecificExposed.cpp
+++ b/Kernel/ProcessSpecificExposed.cpp
@@ -267,45 +267,47 @@ ErrorOr<void> Process::procfs_get_fds_stats(KBufferBuilder& builder) const
ErrorOr<void> Process::procfs_get_virtual_memory_stats(KBufferBuilder& builder) const
{
auto array = TRY(JsonArraySerializer<>::try_create(builder));
- TRY(address_space().region_tree().with([&](auto& region_tree) -> ErrorOr<void> {
- for (auto const& region : region_tree.regions()) {
- auto current_process_credentials = Process::current().credentials();
- if (!region.is_user() && !current_process_credentials->is_superuser())
- continue;
- auto region_object = TRY(array.add_object());
- TRY(region_object.add("readable"sv, region.is_readable()));
- TRY(region_object.add("writable"sv, region.is_writable()));
- TRY(region_object.add("executable"sv, region.is_executable()));
- TRY(region_object.add("stack"sv, region.is_stack()));
- TRY(region_object.add("shared"sv, region.is_shared()));
- TRY(region_object.add("syscall"sv, region.is_syscall_region()));
- TRY(region_object.add("purgeable"sv, region.vmobject().is_anonymous()));
- if (region.vmobject().is_anonymous()) {
- TRY(region_object.add("volatile"sv, static_cast<Memory::AnonymousVMObject const&>(region.vmobject()).is_volatile()));
- }
- TRY(region_object.add("cacheable"sv, region.is_cacheable()));
- TRY(region_object.add("address"sv, region.vaddr().get()));
- TRY(region_object.add("size"sv, region.size()));
- TRY(region_object.add("amount_resident"sv, region.amount_resident()));
- TRY(region_object.add("amount_dirty"sv, region.amount_dirty()));
- TRY(region_object.add("cow_pages"sv, region.cow_pages()));
- TRY(region_object.add("name"sv, region.name()));
- TRY(region_object.add("vmobject"sv, region.vmobject().class_name()));
-
- StringBuilder pagemap_builder;
- for (size_t i = 0; i < region.page_count(); ++i) {
- auto page = region.physical_page(i);
- if (!page)
- pagemap_builder.append('N');
- else if (page->is_shared_zero_page() || page->is_lazy_committed_page())
- pagemap_builder.append('Z');
- else
- pagemap_builder.append('P');
+ TRY(address_space().with([&](auto& space) {
+ return space->region_tree().with([&](auto& region_tree) -> ErrorOr<void> {
+ for (auto const& region : region_tree.regions()) {
+ auto current_process_credentials = Process::current().credentials();
+ if (!region.is_user() && !current_process_credentials->is_superuser())
+ continue;
+ auto region_object = TRY(array.add_object());
+ TRY(region_object.add("readable"sv, region.is_readable()));
+ TRY(region_object.add("writable"sv, region.is_writable()));
+ TRY(region_object.add("executable"sv, region.is_executable()));
+ TRY(region_object.add("stack"sv, region.is_stack()));
+ TRY(region_object.add("shared"sv, region.is_shared()));
+ TRY(region_object.add("syscall"sv, region.is_syscall_region()));
+ TRY(region_object.add("purgeable"sv, region.vmobject().is_anonymous()));
+ if (region.vmobject().is_anonymous()) {
+ TRY(region_object.add("volatile"sv, static_cast<Memory::AnonymousVMObject const&>(region.vmobject()).is_volatile()));
+ }
+ TRY(region_object.add("cacheable"sv, region.is_cacheable()));
+ TRY(region_object.add("address"sv, region.vaddr().get()));
+ TRY(region_object.add("size"sv, region.size()));
+ TRY(region_object.add("amount_resident"sv, region.amount_resident()));
+ TRY(region_object.add("amount_dirty"sv, region.amount_dirty()));
+ TRY(region_object.add("cow_pages"sv, region.cow_pages()));
+ TRY(region_object.add("name"sv, region.name()));
+ TRY(region_object.add("vmobject"sv, region.vmobject().class_name()));
+
+ StringBuilder pagemap_builder;
+ for (size_t i = 0; i < region.page_count(); ++i) {
+ auto page = region.physical_page(i);
+ if (!page)
+ pagemap_builder.append('N');
+ else if (page->is_shared_zero_page() || page->is_lazy_committed_page())
+ pagemap_builder.append('Z');
+ else
+ pagemap_builder.append('P');
+ }
+ TRY(region_object.add("pagemap"sv, pagemap_builder.string_view()));
+ TRY(region_object.finish());
}
- TRY(region_object.add("pagemap"sv, pagemap_builder.string_view()));
- TRY(region_object.finish());
- }
- return {};
+ return {};
+ });
}));
TRY(array.finish());
return {};