mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:17:44 +00:00
AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it possible to pass a FlatPtr to something that has u32 and u64 overloads.
This commit is contained in:
parent
b98d8ad5b0
commit
b1058b33fb
36 changed files with 164 additions and 161 deletions
|
@ -32,15 +32,15 @@
|
|||
class PhysicalAddress {
|
||||
public:
|
||||
PhysicalAddress() {}
|
||||
explicit PhysicalAddress(uintptr_t address)
|
||||
explicit PhysicalAddress(FlatPtr address)
|
||||
: m_address(address)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicalAddress offset(uintptr_t o) const { return PhysicalAddress(m_address + o); }
|
||||
uintptr_t get() const { return m_address; }
|
||||
void set(uintptr_t address) { m_address = address; }
|
||||
void mask(uintptr_t m) { m_address &= m; }
|
||||
PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); }
|
||||
FlatPtr get() const { return m_address; }
|
||||
void set(FlatPtr address) { m_address = address; }
|
||||
void mask(FlatPtr m) { m_address &= m; }
|
||||
|
||||
bool is_null() const { return m_address == 0; }
|
||||
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
bool operator<=(const PhysicalAddress& other) const { return m_address <= other.m_address; }
|
||||
|
||||
private:
|
||||
uintptr_t m_address { 0 };
|
||||
FlatPtr m_address { 0 };
|
||||
};
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, PhysicalAddress value)
|
||||
|
|
|
@ -32,23 +32,23 @@
|
|||
class VirtualAddress {
|
||||
public:
|
||||
VirtualAddress() {}
|
||||
explicit VirtualAddress(uintptr_t address)
|
||||
explicit VirtualAddress(FlatPtr address)
|
||||
: m_address(address)
|
||||
{
|
||||
}
|
||||
|
||||
explicit VirtualAddress(const void* address)
|
||||
: m_address((uintptr_t)address)
|
||||
: m_address((FlatPtr)address)
|
||||
{
|
||||
}
|
||||
|
||||
bool is_null() const { return m_address == 0; }
|
||||
bool is_page_aligned() const { return (m_address & 0xfff) == 0; }
|
||||
|
||||
VirtualAddress offset(uintptr_t o) const { return VirtualAddress(m_address + o); }
|
||||
uintptr_t get() const { return m_address; }
|
||||
void set(uintptr_t address) { m_address = address; }
|
||||
void mask(uintptr_t m) { m_address &= m; }
|
||||
VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); }
|
||||
FlatPtr get() const { return m_address; }
|
||||
void set(FlatPtr address) { m_address = address; }
|
||||
void mask(FlatPtr m) { m_address &= m; }
|
||||
|
||||
bool operator<=(const VirtualAddress& other) const { return m_address <= other.m_address; }
|
||||
bool operator>=(const VirtualAddress& other) const { return m_address >= other.m_address; }
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); }
|
||||
|
||||
private:
|
||||
uintptr_t m_address { 0 };
|
||||
FlatPtr m_address { 0 };
|
||||
};
|
||||
|
||||
inline VirtualAddress operator-(const VirtualAddress& a, const VirtualAddress& b)
|
||||
|
|
|
@ -294,7 +294,7 @@ static void free_impl(void* ptr)
|
|||
|
||||
LOCKER(malloc_lock());
|
||||
|
||||
void* block_base = (void*)((uintptr_t)ptr & block_mask);
|
||||
void* block_base = (void*)((FlatPtr)ptr & block_mask);
|
||||
size_t magic = *(size_t*)block_base;
|
||||
|
||||
if (magic == MAGIC_BIGALLOC_HEADER) {
|
||||
|
@ -372,14 +372,14 @@ void* malloc(size_t size)
|
|||
{
|
||||
void* ptr = malloc_impl(size);
|
||||
if (s_profiling)
|
||||
perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast<uintptr_t>(ptr));
|
||||
perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast<FlatPtr>(ptr));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free(void* ptr)
|
||||
{
|
||||
if (s_profiling)
|
||||
perf_event(PERF_EVENT_FREE, reinterpret_cast<uintptr_t>(ptr), 0);
|
||||
perf_event(PERF_EVENT_FREE, reinterpret_cast<FlatPtr>(ptr), 0);
|
||||
free_impl(ptr);
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,7 @@ size_t malloc_size(void* ptr)
|
|||
if (!ptr)
|
||||
return 0;
|
||||
LOCKER(malloc_lock());
|
||||
void* page_base = (void*)((uintptr_t)ptr & block_mask);
|
||||
void* page_base = (void*)((FlatPtr)ptr & block_mask);
|
||||
auto* header = (const CommonHeader*)page_base;
|
||||
auto size = header->m_size;
|
||||
if (header->m_magic == MAGIC_BIGALLOC_HEADER)
|
||||
|
|
|
@ -79,7 +79,7 @@ int purge(int mode)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int perf_event(int type, uintptr_t arg1, uintptr_t arg2)
|
||||
int perf_event(int type, uintptr_t arg1, FlatPtr arg2)
|
||||
{
|
||||
int rc = syscall(SC_perf_event, type, arg1, arg2);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
|
|
|
@ -164,9 +164,9 @@ public:
|
|||
}
|
||||
|
||||
if (type == "SetInspectedObject") {
|
||||
auto address = request.get("address").to_number<uintptr_t>();
|
||||
auto address = request.get("address").to_number<FlatPtr>();
|
||||
for (auto& object : Object::all_objects()) {
|
||||
if ((uintptr_t)&object == address) {
|
||||
if ((FlatPtr)&object == address) {
|
||||
if (m_inspected_object)
|
||||
m_inspected_object->decrement_inspector_count({});
|
||||
m_inspected_object = object.make_weak_ptr();
|
||||
|
@ -178,9 +178,9 @@ public:
|
|||
}
|
||||
|
||||
if (type == "SetProperty") {
|
||||
auto address = request.get("address").to_number<uintptr_t>();
|
||||
auto address = request.get("address").to_number<FlatPtr>();
|
||||
for (auto& object : Object::all_objects()) {
|
||||
if ((uintptr_t)&object == address) {
|
||||
if ((FlatPtr)&object == address) {
|
||||
bool success = object.set_property(request.get("name").to_string(), request.get("value"));
|
||||
JsonObject response;
|
||||
response.set("type", "SetProperty");
|
||||
|
|
|
@ -168,9 +168,9 @@ void Object::deferred_invoke(Function<void(Object&)> invokee)
|
|||
void Object::save_to(JsonObject& json)
|
||||
{
|
||||
json.set("class_name", class_name());
|
||||
json.set("address", (uintptr_t)this);
|
||||
json.set("address", (FlatPtr)this);
|
||||
json.set("name", name());
|
||||
json.set("parent", (uintptr_t)parent());
|
||||
json.set("parent", (FlatPtr)parent());
|
||||
}
|
||||
|
||||
bool Object::set_property(const StringView& name, const JsonValue& value)
|
||||
|
|
|
@ -228,32 +228,32 @@ private:
|
|||
unsigned m_symbol_count { 0 };
|
||||
|
||||
// Begin Section information collected from DT_* entries
|
||||
uintptr_t m_init_offset { 0 };
|
||||
uintptr_t m_fini_offset { 0 };
|
||||
FlatPtr m_init_offset { 0 };
|
||||
FlatPtr m_fini_offset { 0 };
|
||||
|
||||
uintptr_t m_init_array_offset { 0 };
|
||||
FlatPtr m_init_array_offset { 0 };
|
||||
size_t m_init_array_size { 0 };
|
||||
uintptr_t m_fini_array_offset { 0 };
|
||||
FlatPtr m_fini_array_offset { 0 };
|
||||
size_t m_fini_array_size { 0 };
|
||||
|
||||
uintptr_t m_hash_table_offset { 0 };
|
||||
FlatPtr m_hash_table_offset { 0 };
|
||||
|
||||
uintptr_t m_string_table_offset { 0 };
|
||||
FlatPtr m_string_table_offset { 0 };
|
||||
size_t m_size_of_string_table { 0 };
|
||||
uintptr_t m_symbol_table_offset { 0 };
|
||||
FlatPtr m_symbol_table_offset { 0 };
|
||||
size_t m_size_of_symbol_table_entry { 0 };
|
||||
|
||||
Elf32_Sword m_procedure_linkage_table_relocation_type { -1 };
|
||||
uintptr_t m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations
|
||||
FlatPtr m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations
|
||||
size_t m_size_of_plt_relocation_entry_list { 0 };
|
||||
uintptr_t m_procedure_linkage_table_offset { 0 };
|
||||
FlatPtr m_procedure_linkage_table_offset { 0 };
|
||||
|
||||
// NOTE: We'll only ever either RELA or REL entries, not both (thank god)
|
||||
// NOTE: The x86 ABI will only ever genrerate REL entries.
|
||||
size_t m_number_of_relocations { 0 };
|
||||
size_t m_size_of_relocation_entry { 0 };
|
||||
size_t m_size_of_relocation_table { 0 };
|
||||
uintptr_t m_relocation_table_offset { 0 };
|
||||
FlatPtr m_relocation_table_offset { 0 };
|
||||
|
||||
// DT_FLAGS
|
||||
Elf32_Word m_dt_flags { 0 };
|
||||
|
|
|
@ -77,7 +77,7 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
bool forward = direction == Direction::Forward;
|
||||
for (forward ? ++i : --i; forward ? (i < document.spans().size()) : (i >= 0); forward ? ++i : --i) {
|
||||
auto& span = document.spans().at(i);
|
||||
auto span_token_type = (CppToken::Type)((uintptr_t)span.data);
|
||||
auto span_token_type = (CppToken::Type)((FlatPtr)span.data);
|
||||
if (span_token_type == not_type) {
|
||||
++nesting_level;
|
||||
} else if (span_token_type == type) {
|
||||
|
@ -116,7 +116,7 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
|
||||
for (size_t i = 0; i < document.spans().size(); ++i) {
|
||||
auto& span = const_cast<GUI::TextDocumentSpan&>(document.spans().at(i));
|
||||
auto token_type = (CppToken::Type)((uintptr_t)span.data);
|
||||
auto token_type = (CppToken::Type)((FlatPtr)span.data);
|
||||
|
||||
for (auto& pair : pairs) {
|
||||
if (token_type == pair.open && span.range.start() == m_editor->cursor()) {
|
||||
|
|
|
@ -138,7 +138,7 @@ void Layout::save_to(JsonObject& json)
|
|||
JsonObject entry_object;
|
||||
if (entry.type == Entry::Type::Widget) {
|
||||
entry_object.set("type", "Widget");
|
||||
entry_object.set("widget", (uintptr_t)entry.widget.ptr());
|
||||
entry_object.set("widget", (FlatPtr)entry.widget.ptr());
|
||||
} else if (entry.type == Entry::Type::Spacer) {
|
||||
entry_object.set("type", "Spacer");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue