forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kernel: Implement helper to find multiple Regions in a Range
- Loading branch information
1 parent
7874b89
commit 61f0aa6
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2021, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Leon Albrecht <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -158,6 +159,27 @@ Region* Space::find_region_containing(const Range& range) | |
return nullptr; | ||
} | ||
|
||
Vector<Region*> Space::find_regions_intersecting(const Range& range) | ||
{ | ||
Vector<Region*> regions = {}; | ||
size_t total_size_collected = 0; | ||
|
||
ScopedSpinLock lock(m_lock); | ||
|
||
// FIXME: Maybe take the cache from the single lookup? | ||
for (auto& region : m_regions) { | ||
if (region.range().base() < range.end() && region.range().end() > range.base()) { | ||
regions.append(®ion); | ||
|
||
total_size_collected += region.size() - region.range().intersect(range).size(); | ||
if (total_size_collected == range.size()) | ||
break; | ||
} | ||
} | ||
|
||
return regions; | ||
} | ||
|
||
Region& Space::add_region(NonnullOwnPtr<Region> region) | ||
{ | ||
auto* ptr = region.ptr(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2018-2021, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Leon Albrecht <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -27,6 +28,7 @@ | |
#pragma once | ||
|
||
#include <AK/NonnullOwnPtrVector.h> | ||
#include <AK/Vector.h> | ||
#include <AK/WeakPtr.h> | ||
#include <Kernel/UnixTypes.h> | ||
#include <Kernel/VM/AllocationStrategy.h> | ||
|
@@ -63,6 +65,8 @@ class Space { | |
Region* find_region_from_range(const Range&); | ||
Region* find_region_containing(const Range&); | ||
|
||
Vector<Region*> find_regions_intersecting(const Range&); | ||
|
||
bool enforces_syscall_regions() const { return m_enforces_syscall_regions; } | ||
void set_enforces_syscall_regions(bool b) { m_enforces_syscall_regions = b; } | ||
|
||
|