kernel/vm: Use ObjectDelter and slight cleanup to the mlock() routines.
This commit is contained in:
+10
-14
@@ -6969,8 +6969,8 @@ struct LockedPages : DoublyLinkedListLinkImpl<LockedPages> {
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
_user_mlock(const void* address, size_t size) {
|
_user_mlock(const void* address, size_t size)
|
||||||
// Maybe there's nothing to do, in which case, do nothing
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
@@ -6988,6 +6988,7 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
LockedPages* newRange = new(std::nothrow) LockedPages();
|
LockedPages* newRange = new(std::nothrow) LockedPages();
|
||||||
if (newRange == NULL)
|
if (newRange == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
ObjectDeleter<LockedPages> newRangeDeleter(newRange);
|
||||||
|
|
||||||
// Get and lock the team
|
// Get and lock the team
|
||||||
Team* team = thread_get_current_thread()->team;
|
Team* team = thread_get_current_thread()->team;
|
||||||
@@ -7008,11 +7009,11 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
newRange->start = (addr_t)address;
|
newRange->start = (addr_t)address;
|
||||||
newRange->end = endAddress;
|
newRange->end = endAddress;
|
||||||
error = newRange->LockMemory();
|
error = newRange->LockMemory();
|
||||||
if (error != B_OK) {
|
if (error != B_OK)
|
||||||
delete newRange;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
|
||||||
lockedPages->InsertBefore(currentRange, newRange);
|
lockedPages->InsertBefore(currentRange, newRange);
|
||||||
|
newRangeDeleter.Detach();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7022,7 +7023,6 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
if (currentRange->end >= endAddress) {
|
if (currentRange->end >= endAddress) {
|
||||||
// An existing range is already fully covering the pages we need to
|
// An existing range is already fully covering the pages we need to
|
||||||
// lock. Nothing to do then.
|
// lock. Nothing to do then.
|
||||||
delete newRange;
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} else {
|
} else {
|
||||||
// An existing range covers the start of the area we want to lock.
|
// An existing range covers the start of the area we want to lock.
|
||||||
@@ -7038,10 +7038,8 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
newRange->start = (addr_t)address;
|
newRange->start = (addr_t)address;
|
||||||
newRange->end = endAddress;
|
newRange->end = endAddress;
|
||||||
error = newRange->LockMemory();
|
error = newRange->LockMemory();
|
||||||
if (error != B_OK) {
|
if (error != B_OK)
|
||||||
delete newRange;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
|
||||||
|
|
||||||
// Unlock all ranges fully overlapping with the area we need to lock
|
// Unlock all ranges fully overlapping with the area we need to lock
|
||||||
while (currentRange != NULL && currentRange->end < endAddress) {
|
while (currentRange != NULL && currentRange->end < endAddress) {
|
||||||
@@ -7053,7 +7051,6 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
panic("Failed to unlock a memory range: %s", strerror(error));
|
panic("Failed to unlock a memory range: %s", strerror(error));
|
||||||
newRange->UnlockMemory();
|
newRange->UnlockMemory();
|
||||||
delete newRange;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
LockedPages* temp = currentRange;
|
LockedPages* temp = currentRange;
|
||||||
@@ -7070,7 +7067,6 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
// at the end) already cover the area we're after, there's nothing
|
// at the end) already cover the area we're after, there's nothing
|
||||||
// more to do. So we destroy our new extra allocation
|
// more to do. So we destroy our new extra allocation
|
||||||
error = newRange->UnlockMemory();
|
error = newRange->UnlockMemory();
|
||||||
delete newRange;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7080,7 +7076,6 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
panic("Failed to move a memory range: %s", strerror(error));
|
panic("Failed to move a memory range: %s", strerror(error));
|
||||||
newRange->UnlockMemory();
|
newRange->UnlockMemory();
|
||||||
delete newRange;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7088,13 +7083,14 @@ _user_mlock(const void* address, size_t size) {
|
|||||||
|
|
||||||
// Finally, store the new range in the locked list
|
// Finally, store the new range in the locked list
|
||||||
lockedPages->InsertBefore(currentRange, newRange);
|
lockedPages->InsertBefore(currentRange, newRange);
|
||||||
|
newRangeDeleter.Detach();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
_user_munlock(const void* address, size_t size) {
|
_user_munlock(const void* address, size_t size)
|
||||||
// Maybe there's nothing to do, in which case, do nothing
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user