diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2023-05-19 12:12:27 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-21 12:00:22 +0200 |
commit | 0da2d2102a026ab0a2f315045257c0c4886222c4 (patch) | |
tree | 890ca2a2668b54197a8f8108fdb49dfce4c9c0fc /Kernel/Arch/aarch64 | |
parent | ab279c850b4ce5b945c9e8444e95ab5f1c50cf3a (diff) | |
download | serenity-0da2d2102a026ab0a2f315045257c0c4886222c4.zip |
Kernel/aarch64: Flatten `safe_{memset,strnlen,memcpy}()`
We want to detect if an access fault comes from within these operations,
so they cannot be calling out to the non-safe variants.
Diffstat (limited to 'Kernel/Arch/aarch64')
-rw-r--r-- | Kernel/Arch/aarch64/SafeMem.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Kernel/Arch/aarch64/SafeMem.cpp b/Kernel/Arch/aarch64/SafeMem.cpp index 29e58668ee..c537dc95cd 100644 --- a/Kernel/Arch/aarch64/SafeMem.cpp +++ b/Kernel/Arch/aarch64/SafeMem.cpp @@ -9,23 +9,34 @@ namespace Kernel { -bool safe_memset(void* dest_ptr, int c, size_t n, void*&) +bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at) { // FIXME: Actually implement a safe memset. - memset(dest_ptr, c, n); + auto* dest = static_cast<u8*>(dest_ptr); + for (; n--;) + *dest++ = c; + fault_at = nullptr; return true; } -ssize_t safe_strnlen(char const* str, unsigned long max_n, void*&) +ssize_t safe_strnlen(char const* str, unsigned long max_n, void*& fault_at) { // FIXME: Actually implement a safe strnlen. - return strnlen(str, max_n); + size_t len = 0; + for (; len < max_n && *str; str++) + len++; + fault_at = nullptr; + return len; } -bool safe_memcpy(void* dest_ptr, void const* src_ptr, unsigned long n, void*&) +bool safe_memcpy(void* dest_ptr, void const* src_ptr, unsigned long n, void*& fault_at) { // FIXME: Actually implement a safe memcpy. - memcpy(dest_ptr, src_ptr, n); + auto* pd = static_cast<u8*>(dest_ptr); + auto const* ps = static_cast<u8 const*>(src_ptr); + for (; n--;) + *pd++ = *ps++; + fault_at = nullptr; return true; } |