mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Kernel: Implement support for current thread pseudo-handle
This boots a few (mostly Nintendo 1st party) games further.
This commit is contained in:
		
							parent
							
								
									cdfa7157eb
								
							
						
					
					
						commit
						adee775f44
					
				
					 3 changed files with 16 additions and 2 deletions
				
			
		|  | @ -14,6 +14,10 @@ typedef s32 Result; | ||||||
| 
 | 
 | ||||||
| namespace Kernel { | namespace Kernel { | ||||||
| 
 | 
 | ||||||
|  | // From kernel.h. Declarations duplicated here to avoid a circular header dependency.
 | ||||||
|  | class Thread; | ||||||
|  | Thread* GetCurrentThread(); | ||||||
|  | 
 | ||||||
| enum KernelHandle { | enum KernelHandle { | ||||||
|     CurrentThread   = 0xFFFF8000, |     CurrentThread   = 0xFFFF8000, | ||||||
|     CurrentProcess  = 0xFFFF8001, |     CurrentProcess  = 0xFFFF8001, | ||||||
|  | @ -81,6 +85,10 @@ public: | ||||||
| 
 | 
 | ||||||
|     template <class T> |     template <class T> | ||||||
|     T* Get(Handle handle) { |     T* Get(Handle handle) { | ||||||
|  |         if (handle == CurrentThread) { | ||||||
|  |             return reinterpret_cast<T*>(GetCurrentThread()); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) { |         if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) { | ||||||
|             if (handle != 0) { |             if (handle != 0) { | ||||||
|                 LOG_ERROR(Kernel, "Bad object handle %08x", handle); |                 LOG_ERROR(Kernel, "Bad object handle %08x", handle); | ||||||
|  | @ -99,6 +107,10 @@ public: | ||||||
|     // ONLY use this when you know the handle is valid.
 |     // ONLY use this when you know the handle is valid.
 | ||||||
|     template <class T> |     template <class T> | ||||||
|     T *GetFast(Handle handle) { |     T *GetFast(Handle handle) { | ||||||
|  |         if (handle == CurrentThread) { | ||||||
|  |             return reinterpret_cast<T*>(GetCurrentThread()); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         const Handle realHandle = handle - HANDLE_OFFSET; |         const Handle realHandle = handle - HANDLE_OFFSET; | ||||||
|         _dbg_assert_(Kernel, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]); |         _dbg_assert_(Kernel, realHandle >= 0 && realHandle < MAX_COUNT && occupied[realHandle]); | ||||||
|         return static_cast<T*>(pool[realHandle]); |         return static_cast<T*>(pool[realHandle]); | ||||||
|  |  | ||||||
|  | @ -83,8 +83,7 @@ static Thread* current_thread; | ||||||
| static const u32 INITIAL_THREAD_ID = 1; ///< The first available thread id at startup
 | static const u32 INITIAL_THREAD_ID = 1; ///< The first available thread id at startup
 | ||||||
| static u32 next_thread_id; ///< The next available thread id
 | static u32 next_thread_id; ///< The next available thread id
 | ||||||
| 
 | 
 | ||||||
| /// Gets the current thread
 | Thread* GetCurrentThread() { | ||||||
| inline Thread* GetCurrentThread() { |  | ||||||
|     return current_thread; |     return current_thread; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -78,6 +78,9 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address); | ||||||
| /// Arbitrate all threads currently waiting...
 | /// Arbitrate all threads currently waiting...
 | ||||||
| void ArbitrateAllThreads(u32 arbiter, u32 address); | void ArbitrateAllThreads(u32 arbiter, u32 address); | ||||||
| 
 | 
 | ||||||
|  | /// Gets the current thread
 | ||||||
|  | Thread* GetCurrentThread(); | ||||||
|  | 
 | ||||||
| /// Gets the current thread handle
 | /// Gets the current thread handle
 | ||||||
| Handle GetCurrentThreadHandle(); | Handle GetCurrentThreadHandle(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue