mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:22:46 +00:00 
			
		
		
		
	Kernel: Add jail semantics to methods iterating over thread lists
We should consider whether the selected Thread is within the same jail or not. Therefore let's make it clear to callers with jail semantics if a called method checks if the desired Thread object is within the same jail. As for Thread::for_each_* methods, currently nothing in the kernel codebase needs iteration with consideration for jails, so the old Thread::for_each* were simply renamed to include "ignoring_jails" suffix in their names.
This commit is contained in:
		
							parent
							
								
									3a55a1b592
								
							
						
					
					
						commit
						cbaa3465a8
					
				
					 7 changed files with 36 additions and 17 deletions
				
			
		|  | @ -589,7 +589,7 @@ void Thread::finalize_dying_threads() | |||
|     Vector<Thread*, 32> dying_threads; | ||||
|     { | ||||
|         SpinlockLocker lock(g_scheduler_lock); | ||||
|         for_each_in_state(Thread::State::Dying, [&](Thread& thread) { | ||||
|         for_each_in_state_ignoring_jails(Thread::State::Dying, [&](Thread& thread) { | ||||
|             if (!thread.is_finalizable()) | ||||
|                 return; | ||||
|             auto result = dying_threads.try_append(&thread); | ||||
|  | @ -1398,7 +1398,25 @@ ErrorOr<void> Thread::make_thread_specific_region(Badge<Process>) | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| RefPtr<Thread> Thread::from_tid(ThreadID tid) | ||||
| RefPtr<Thread> Thread::from_tid_in_same_jail(ThreadID tid) | ||||
| { | ||||
|     return Thread::all_instances().with([&](auto& list) -> RefPtr<Thread> { | ||||
|         for (Thread& thread : list) { | ||||
|             if (thread.tid() == tid) { | ||||
|                 return Process::current().jail().with([&thread](auto const& my_jail) -> RefPtr<Thread> { | ||||
|                     return thread.process().jail().with([&thread, my_jail](auto const& other_thread_process_jail) -> RefPtr<Thread> { | ||||
|                         if (my_jail && my_jail.ptr() != other_thread_process_jail.ptr()) | ||||
|                             return nullptr; | ||||
|                         return thread; | ||||
|                     }); | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|         return nullptr; | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| RefPtr<Thread> Thread::from_tid_ignoring_jails(ThreadID tid) | ||||
| { | ||||
|     return Thread::all_instances().with([&](auto& list) -> RefPtr<Thread> { | ||||
|         for (Thread& thread : list) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A