mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:12:43 +00:00 
			
		
		
		
	Kernel/HID: Take a spinlock when calling KeyboardClient::on_key_pressed
The KeyboardClient class member could be updated due to TTY switch, so we must ensure we always use a valid pointer.
This commit is contained in:
		
							parent
							
								
									b8493bf70f
								
							
						
					
					
						commit
						cd08c4a5aa
					
				
					 3 changed files with 14 additions and 3 deletions
				
			
		|  | @ -75,6 +75,12 @@ static constexpr Keyboard::CharacterMapData DEFAULT_CHARACTER_MAP = | |||
| }; | ||||
| // clang-format on
 | ||||
| 
 | ||||
| void HIDManagement::set_client(KeyboardClient* client) | ||||
| { | ||||
|     SpinlockLocker locker(m_client_lock); | ||||
|     m_client = client; | ||||
| } | ||||
| 
 | ||||
| size_t HIDManagement::generate_minor_device_number_for_mouse() | ||||
| { | ||||
|     // FIXME: Lock this to prevent race conditions with hot-plugging devices!
 | ||||
|  |  | |||
|  | @ -50,7 +50,7 @@ public: | |||
| 
 | ||||
|     u32 get_char_from_character_map(KeyEvent) const; | ||||
| 
 | ||||
|     void set_client(KeyboardClient* client) { m_client = client; } | ||||
|     void set_client(KeyboardClient* client); | ||||
|     void set_maps(NonnullOwnPtr<KString> character_map_name, Keyboard::CharacterMapData const& character_map); | ||||
| 
 | ||||
| private: | ||||
|  | @ -63,6 +63,7 @@ private: | |||
|     KeyboardClient* m_client { nullptr }; | ||||
|     RefPtr<I8042Controller> m_i8042_controller; | ||||
|     NonnullRefPtrVector<HIDDevice> m_hid_devices; | ||||
|     Spinlock m_client_lock; | ||||
| }; | ||||
| 
 | ||||
| class KeyboardClient { | ||||
|  |  | |||
|  | @ -254,8 +254,12 @@ void KeyboardDevice::key_state_changed(u8 scan_code, bool pressed) | |||
| 
 | ||||
|     if (pressed) | ||||
|         event.flags |= Is_Press; | ||||
|     if (HIDManagement::the().m_client) | ||||
|         HIDManagement::the().m_client->on_key_pressed(event); | ||||
| 
 | ||||
|     { | ||||
|         SpinlockLocker locker(HIDManagement::the().m_client_lock); | ||||
|         if (HIDManagement::the().m_client) | ||||
|             HIDManagement::the().m_client->on_key_pressed(event); | ||||
|     } | ||||
| 
 | ||||
|     { | ||||
|         SpinlockLocker lock(m_queue_lock); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A