summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-01-30 21:35:54 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-01 09:54:32 +0100
commita2c21a55e17189b61b416688cfe072c0856cba00 (patch)
treee47fc163ada6498043ef096037e53cfad4a8befe /Kernel/Syscalls
parentd47ed358015a83523e1895ec5df21f9226f8ad0c (diff)
downloadserenity-a2c21a55e17189b61b416688cfe072c0856cba00.zip
Kernel+LibKeyboard: Enable querying the current keymap
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/keymap.cpp (renamed from Kernel/Syscalls/setkeymap.cpp)33
1 files changed, 32 insertions, 1 deletions
diff --git a/Kernel/Syscalls/setkeymap.cpp b/Kernel/Syscalls/keymap.cpp
index d761e3351b..2cbab8bf46 100644
--- a/Kernel/Syscalls/setkeymap.cpp
+++ b/Kernel/Syscalls/keymap.cpp
@@ -29,6 +29,8 @@
namespace Kernel {
+constexpr size_t map_name_max_size = 50;
+
int Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_params*> user_params)
{
REQUIRE_PROMISE(setkeymap);
@@ -57,7 +59,6 @@ int Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_params*> user_p
if (map_name.is_error()) {
return map_name.error();
}
- constexpr size_t map_name_max_size = 50;
if (map_name.value().length() > map_name_max_size) {
return -ENAMETOOLONG;
}
@@ -66,4 +67,34 @@ int Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_params*> user_p
return 0;
}
+int Process::sys$getkeymap(Userspace<const Syscall::SC_getkeymap_params*> user_params)
+{
+ REQUIRE_PROMISE(stdio);
+
+ Syscall::SC_getkeymap_params params;
+ if (!copy_from_user(&params, user_params))
+ return -EFAULT;
+
+ String keymap_name = KeyboardDevice::the().keymap_name();
+ const Keyboard::CharacterMapData& character_maps = KeyboardDevice::the().character_maps();
+
+ if (!copy_to_user(params.map, character_maps.map, CHAR_MAP_SIZE * sizeof(u32)))
+ return -EFAULT;
+ if (!copy_to_user(params.shift_map, character_maps.shift_map, CHAR_MAP_SIZE * sizeof(u32)))
+ return -EFAULT;
+ if (!copy_to_user(params.alt_map, character_maps.alt_map, CHAR_MAP_SIZE * sizeof(u32)))
+ return -EFAULT;
+ if (!copy_to_user(params.altgr_map, character_maps.altgr_map, CHAR_MAP_SIZE * sizeof(u32)))
+ return -EFAULT;
+ if (!copy_to_user(params.shift_altgr_map, character_maps.shift_altgr_map, CHAR_MAP_SIZE * sizeof(u32)))
+ return -EFAULT;
+
+ if (params.map_name.size < keymap_name.length())
+ return -ENAMETOOLONG;
+ if (!copy_to_user(params.map_name.data, keymap_name.characters(), keymap_name.length()))
+ return -EFAULT;
+
+ return 0;
+}
+
}