1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

UE+LibX86: Support bigger reads and writes

This commit is contained in:
Hendiadyoin1 2021-04-10 23:29:32 +02:00 committed by Andreas Kling
parent a99812633b
commit f1957bb86b
11 changed files with 316 additions and 4 deletions

View file

@ -4,13 +4,19 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Format.h>
#include <AK/Platform.h>
#pragma once
#include <AK/Format.h>
#include <AK/Platform.h>
#include <LibX86/Types.h>
#include <string.h>
namespace UserspaceEmulator {
constexpr u64 _inititalized_64 = 0x01010101'01010101LLU;
constexpr u128 _initialized_128 = u128(_inititalized_64, _inititalized_64);
constexpr u256 _initialized_256 = u256(_initialized_128, _initialized_128);
template<typename T>
class ValueAndShadowReference;
@ -32,6 +38,12 @@ public:
bool is_uninitialized() const
{
if constexpr (sizeof(T) == 32)
return (m_shadow & _initialized_256) != _initialized_256;
if constexpr (sizeof(T) == 16)
return (m_shadow & _initialized_128) != _initialized_128;
if constexpr (sizeof(T) == 8)
return (m_shadow & _inititalized_64) != _inititalized_64;
if constexpr (sizeof(T) == 4)
return (m_shadow & 0x01010101) != 0x01010101;
if constexpr (sizeof(T) == 2)
@ -42,6 +54,12 @@ public:
void set_initialized()
{
if constexpr (sizeof(T) == 32)
m_shadow = _initialized_256;
if constexpr (sizeof(T) == 16)
m_shadow = _initialized_128;
if constexpr (sizeof(T) == 8)
m_shadow = _inititalized_64;
if constexpr (sizeof(T) == 4)
m_shadow = 0x01010101;
if constexpr (sizeof(T) == 2)
@ -68,6 +86,12 @@ public:
bool is_uninitialized() const
{
if constexpr (sizeof(T) == 32)
return (m_shadow & _initialized_256) != _initialized_256;
if constexpr (sizeof(T) == 16)
return (m_shadow & _initialized_128) != _initialized_128;
if constexpr (sizeof(T) == 8)
return (m_shadow & _inititalized_64) != _inititalized_64;
if constexpr (sizeof(T) == 4)
return (m_shadow & 0x01010101) != 0x01010101;
if constexpr (sizeof(T) == 2)
@ -92,8 +116,12 @@ private:
template<typename T>
ALWAYS_INLINE ValueWithShadow<T> shadow_wrap_as_initialized(T value)
{
if constexpr (sizeof(T) == 32)
return { value, _initialized_256 };
if constexpr (sizeof(T) == 16)
return { value, _initialized_128 };
if constexpr (sizeof(T) == 8)
return { value, 0x01010101'01010101LLU };
return { value, _inititalized_64 };
if constexpr (sizeof(T) == 4)
return { value, 0x01010101 };
if constexpr (sizeof(T) == 2)
@ -149,3 +177,7 @@ struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<T> {
return Formatter<T>::format(builder, value.value());
}
};
#undef INITIALIZED_64
#undef INITIALIZED_128
#undef INITIALIZED_256