mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +00:00 
			
		
		
		
	Kernel: Use TRY() and adopt_nonnull_ref_or_enomem() in AnonymousVMObject
This commit is contained in:
		
							parent
							
								
									52cbbe1dc5
								
							
						
					
					
						commit
						21f7932ae2
					
				
					 1 changed files with 4 additions and 13 deletions
				
			
		|  | @ -42,14 +42,8 @@ KResultOr<NonnullRefPtr<VMObject>> AnonymousVMObject::try_clone() | ||||||
|     // one would keep the one it still has. This ensures that the original
 |     // one would keep the one it still has. This ensures that the original
 | ||||||
|     // one and this one, as well as the clone have sufficient resources
 |     // one and this one, as well as the clone have sufficient resources
 | ||||||
|     // to cow all pages as needed
 |     // to cow all pages as needed
 | ||||||
|     auto new_shared_committed_cow_pages = try_make_ref_counted<SharedCommittedCowPages>(move(committed_pages)); |     auto new_shared_committed_cow_pages = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedCommittedCowPages(move(committed_pages)))); | ||||||
|     if (!new_shared_committed_cow_pages) |     auto clone = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousVMObject(*this, *new_shared_committed_cow_pages))); | ||||||
|         return ENOMEM; |  | ||||||
| 
 |  | ||||||
|     auto maybe_clone = adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(*this, *new_shared_committed_cow_pages)); |  | ||||||
|     if (!maybe_clone) |  | ||||||
|         return ENOMEM; |  | ||||||
|     auto clone = maybe_clone.release_nonnull(); |  | ||||||
| 
 | 
 | ||||||
|     m_shared_committed_cow_pages = move(new_shared_committed_cow_pages); |     m_shared_committed_cow_pages = move(new_shared_committed_cow_pages); | ||||||
| 
 | 
 | ||||||
|  | @ -98,12 +92,9 @@ KResultOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_purgea | ||||||
|         committed_pages = TRY(MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))); |         committed_pages = TRY(MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto vmobject = adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, strategy, move(committed_pages))); |     auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousVMObject(size, strategy, move(committed_pages)))); | ||||||
|     if (!vmobject) |  | ||||||
|         return ENOMEM; |  | ||||||
| 
 |  | ||||||
|     vmobject->m_purgeable = true; |     vmobject->m_purgeable = true; | ||||||
|     return vmobject.release_nonnull(); |     return vmobject; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| KResultOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>> physical_pages) | KResultOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>> physical_pages) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling