mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:37:34 +00:00
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.
This commit is contained in:
parent
ab279c850b
commit
0da2d2102a
1 changed files with 17 additions and 6 deletions
|
@ -9,23 +9,34 @@
|
||||||
|
|
||||||
namespace Kernel {
|
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.
|
// 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;
|
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.
|
// 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.
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue