summaryrefslogtreecommitdiff
path: root/Kernel/Arch/i386/CPU.h
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-09-10 19:49:31 -0600
committerAndreas Kling <kling@serenityos.org>2020-09-13 21:19:15 +0200
commit7d1b8417bdf5d2818d1c9d310786cdf59650b104 (patch)
treecb708ca30c6528286ad67fddd92624f6a1920e4b /Kernel/Arch/i386/CPU.h
parent1c86ab010824b3e7985c99ff0fc604b0cd42f68d (diff)
downloadserenity-7d1b8417bdf5d2818d1c9d310786cdf59650b104.zip
Kernel: Add safe_memcpy, safe_memset and safe_strnlen
These special functions can be used to safely copy/set memory or determine the length of a string, e.g. provided by user mode. In the event of a page fault, safe_memcpy/safe_memset will return false and safe_strnlen will return -1.
Diffstat (limited to 'Kernel/Arch/i386/CPU.h')
-rw-r--r--Kernel/Arch/i386/CPU.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h
index 44bbcfb4c5..0431c60ca1 100644
--- a/Kernel/Arch/i386/CPU.h
+++ b/Kernel/Arch/i386/CPU.h
@@ -279,6 +279,10 @@ void flush_idt();
void load_task_register(u16 selector);
void handle_crash(RegisterState&, const char* description, int signal, bool out_of_memory = false);
+[[nodiscard]] bool safe_memcpy(void* dest_ptr, const void* src_ptr, size_t n, void*& fault_at);
+[[nodiscard]] ssize_t safe_strnlen(const char* str, size_t max_n, void*& fault_at);
+[[nodiscard]] bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at);
+
#define LSW(x) ((u32)(x)&0xFFFF)
#define MSW(x) (((u32)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x)&0xFF)