summaryrefslogtreecommitdiff
path: root/Kernel/StdLib.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-05 18:00:15 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-05 18:14:51 +0100
commit9eef39d68a99c5e29099ae4eb4a56934b35eecde (patch)
tree992cd16e74009907740a54df812f1f791a92b385 /Kernel/StdLib.h
parent04b734501a6be77501b21f787607963f253ebc32 (diff)
downloadserenity-9eef39d68a99c5e29099ae4eb4a56934b35eecde.zip
Kernel: Start implementing x86 SMAP support
Supervisor Mode Access Prevention (SMAP) is an x86 CPU feature that prevents the kernel from accessing userspace memory. With SMAP enabled, trying to read/write a userspace memory address while in the kernel will now generate a page fault. Since it's sometimes necessary to read/write userspace memory, there are two new instructions that quickly switch the protection on/off: STAC (disables protection) and CLAC (enables protection.) These are exposed in kernel code via the stac() and clac() helpers. There's also a SmapDisabler RAII object that can be used to ensure that you don't forget to re-enable protection before returning to userspace code. THis patch also adds copy_to_user(), copy_from_user() and memset_user() which are the "correct" way of doing things. These functions allow us to briefly disable protection for a specific purpose, and then turn it back on immediately after it's done. Going forward all kernel code should be moved to using these and all uses of SmapDisabler are to be considered FIXME's. Note that we're not realizing the full potential of this feature since I've used SmapDisabler quite liberally in this initial bring-up patch.
Diffstat (limited to 'Kernel/StdLib.h')
-rw-r--r--Kernel/StdLib.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h
index 35b10a6e30..67e0fb8f4a 100644
--- a/Kernel/StdLib.h
+++ b/Kernel/StdLib.h
@@ -6,6 +6,10 @@ extern "C" {
static_assert(sizeof(size_t) == 4);
+void* copy_to_user(void*, const void*, size_t);
+void* copy_from_user(void*, const void*, size_t);
+void* memset_user(void*, int, size_t);
+
void* memcpy(void*, const void*, size_t);
char* strcpy(char*, const char*);
char* strncpy(char*, const char*, size_t);