1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:07:35 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -10,7 +10,7 @@
#include <sys/arch/regs.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
#endif
namespace ELF::Core {
@ -39,9 +39,9 @@ struct [[gnu::packed]] ProcessInfo {
// Keys:
// - "pid" (int)
// - "termination_signal" (u8)
// - "executable_path" (DeprecatedString)
// - "arguments" (Vector<DeprecatedString>)
// - "environment" (Vector<DeprecatedString>)
// - "executable_path" (ByteString)
// - "arguments" (Vector<ByteString>)
// - "environment" (Vector<ByteString>)
char json_data[]; // Null terminated
};
@ -59,7 +59,7 @@ struct [[gnu::packed]] MemoryRegionInfo {
char region_name[]; // Null terminated
#ifndef KERNEL
DeprecatedString object_name() const
ByteString object_name() const
{
StringView memory_region_name { region_name, strlen(region_name) };
if (memory_region_name.contains("Loader.so"sv))
@ -67,7 +67,7 @@ struct [[gnu::packed]] MemoryRegionInfo {
auto maybe_colon_index = memory_region_name.find(':');
if (!maybe_colon_index.has_value())
return {};
return memory_region_name.substring_view(0, *maybe_colon_index).to_deprecated_string();
return memory_region_name.substring_view(0, *maybe_colon_index).to_byte_string();
}
#endif
};

View file

@ -36,12 +36,12 @@
namespace ELF {
static HashMap<DeprecatedString, NonnullRefPtr<ELF::DynamicLoader>> s_loaders;
static DeprecatedString s_main_program_path;
static HashMap<ByteString, NonnullRefPtr<ELF::DynamicLoader>> s_loaders;
static ByteString s_main_program_path;
// Dependencies have to always be added after the object that depends on them in `s_global_objects`.
// This is needed for calling the destructors in the correct order.
static OrderedHashMap<DeprecatedString, NonnullRefPtr<ELF::DynamicObject>> s_global_objects;
static OrderedHashMap<ByteString, NonnullRefPtr<ELF::DynamicObject>> s_global_objects;
using EntryPointFunction = int (*)(int, char**, char**);
using LibCExitFunction = void (*)(int);
@ -57,13 +57,13 @@ static size_t s_allocated_tls_block_size = 0;
static char** s_envp = nullptr;
static LibCExitFunction s_libc_exit = nullptr;
static __pthread_mutex_t s_loader_lock = __PTHREAD_MUTEX_INITIALIZER;
static DeprecatedString s_cwd;
static ByteString s_cwd;
static bool s_allowed_to_check_environment_variables { false };
static bool s_do_breakpoint_trap_before_entry { false };
static StringView s_ld_library_path;
static StringView s_main_program_pledge_promises;
static DeprecatedString s_loader_pledge_promises;
static ByteString s_loader_pledge_promises;
static Result<void, DlErrorMessage> __dlclose(void* handle);
static Result<void*, DlErrorMessage> __dlopen(char const* filename, int flags);
@ -90,7 +90,7 @@ Optional<DynamicObject::SymbolLookupResult> DynamicLinker::lookup_global_symbol(
return weak_result;
}
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(DeprecatedString const& filepath, int fd)
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(ByteString const& filepath, int fd)
{
VERIFY(filepath.starts_with('/'));
@ -110,7 +110,7 @@ static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(Deprecat
return loader;
}
Optional<DeprecatedString> DynamicLinker::resolve_library(DeprecatedString const& name, DynamicObject const& parent_object)
Optional<ByteString> DynamicLinker::resolve_library(ByteString const& name, DynamicObject const& parent_object)
{
// Absolute and relative (to the current working directory) paths are already considered resolved.
// However, ensure that the returned path is absolute and canonical, so pass it through LexicalPath.
@ -135,7 +135,7 @@ Optional<DeprecatedString> DynamicLinker::resolve_library(DeprecatedString const
for (auto const& search_path : search_paths) {
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(parent_object.filepath()), ReplaceMode::FirstOnly));
DeprecatedString library_name = library_path.append(name).string();
ByteString library_name = library_path.append(name).string();
if (access(library_name.characters(), F_OK) == 0) {
if (!library_name.starts_with('/')) {
@ -152,24 +152,24 @@ Optional<DeprecatedString> DynamicLinker::resolve_library(DeprecatedString const
return {};
}
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(DeprecatedString const& path)
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(ByteString const& path)
{
VERIFY(path.starts_with('/'));
int fd = open(path.characters(), O_RDONLY);
if (fd < 0)
return DlErrorMessage { DeprecatedString::formatted("Could not open shared library '{}': {}", path, strerror(errno)) };
return DlErrorMessage { ByteString::formatted("Could not open shared library '{}': {}", path, strerror(errno)) };
return map_library(path, fd);
}
static Vector<DeprecatedString> get_dependencies(DeprecatedString const& path)
static Vector<ByteString> get_dependencies(ByteString const& path)
{
VERIFY(path.starts_with('/'));
auto name = LexicalPath::basename(path);
auto lib = s_loaders.get(path).value();
Vector<DeprecatedString> dependencies;
Vector<ByteString> dependencies;
lib->for_each_needed_library([&dependencies, &name](auto needed_name) {
if (name == needed_name)
@ -179,7 +179,7 @@ static Vector<DeprecatedString> get_dependencies(DeprecatedString const& path)
return dependencies;
}
static Result<void, DlErrorMessage> map_dependencies(DeprecatedString const& path)
static Result<void, DlErrorMessage> map_dependencies(ByteString const& path)
{
VERIFY(path.starts_with('/'));
@ -193,7 +193,7 @@ static Result<void, DlErrorMessage> map_dependencies(DeprecatedString const& pat
auto dependency_path = DynamicLinker::resolve_library(needed_name, parent_object);
if (!dependency_path.has_value())
return DlErrorMessage { DeprecatedString::formatted("Could not find required shared library: {}", needed_name) };
return DlErrorMessage { ByteString::formatted("Could not find required shared library: {}", needed_name) };
if (!s_loaders.contains(dependency_path.value()) && !s_global_objects.contains(dependency_path.value())) {
auto loader = TRY(map_library(dependency_path.value()));
@ -321,7 +321,7 @@ static void initialize_libc(DynamicObject& libc)
}
template<typename Callback>
static void for_each_unfinished_dependency_of(DeprecatedString const& path, HashTable<DeprecatedString>& seen_names, Callback callback)
static void for_each_unfinished_dependency_of(ByteString const& path, HashTable<ByteString>& seen_names, Callback callback)
{
VERIFY(path.starts_with('/'));
@ -356,11 +356,11 @@ static void for_each_unfinished_dependency_of(DeprecatedString const& path, Hash
callback(*s_loaders.get(path).value());
}
static Vector<NonnullRefPtr<DynamicLoader>> collect_loaders_for_library(DeprecatedString const& path)
static Vector<NonnullRefPtr<DynamicLoader>> collect_loaders_for_library(ByteString const& path)
{
VERIFY(path.starts_with('/'));
HashTable<DeprecatedString> seen_names;
HashTable<ByteString> seen_names;
Vector<NonnullRefPtr<DynamicLoader>> loaders;
for_each_unfinished_dependency_of(path, seen_names, [&](auto& loader) {
loaders.append(loader);
@ -375,7 +375,7 @@ static void drop_loader_promise(StringView promise_to_drop)
s_loader_pledge_promises = s_loader_pledge_promises.replace(promise_to_drop, ""sv, ReplaceMode::All);
auto extended_promises = DeprecatedString::formatted("{} {}", s_main_program_pledge_promises, s_loader_pledge_promises);
auto extended_promises = ByteString::formatted("{} {}", s_main_program_pledge_promises, s_loader_pledge_promises);
Syscall::SC_pledge_params params {
{ extended_promises.characters(), extended_promises.length() },
{ nullptr, 0 },
@ -387,7 +387,7 @@ static void drop_loader_promise(StringView promise_to_drop)
}
}
static Result<void, DlErrorMessage> link_main_library(DeprecatedString const& path, int flags)
static Result<void, DlErrorMessage> link_main_library(ByteString const& path, int flags)
{
VERIFY(path.starts_with('/'));
@ -400,7 +400,7 @@ static Result<void, DlErrorMessage> link_main_library(DeprecatedString const& pa
for (auto& loader : loaders) {
bool success = loader->link(flags);
if (!success) {
return DlErrorMessage { DeprecatedString::formatted("Failed to link library {}", loader->filepath()) };
return DlErrorMessage { ByteString::formatted("Failed to link library {}", loader->filepath()) };
}
}
@ -503,7 +503,7 @@ static Result<void*, DlErrorMessage> __dlopen(char const* filename, int flags)
auto library_path = (filename ? DynamicLinker::resolve_library(filename, parent_object) : s_main_program_path);
if (!library_path.has_value())
return DlErrorMessage { DeprecatedString::formatted("Could not find required shared library: {}", filename) };
return DlErrorMessage { ByteString::formatted("Could not find required shared library: {}", filename) };
auto existing_elf_object = s_global_objects.get(library_path.value());
if (existing_elf_object.has_value()) {
@ -552,7 +552,7 @@ static Result<void*, DlErrorMessage> __dlsym(void* handle, char const* symbol_na
}
if (!symbol.has_value())
return DlErrorMessage { DeprecatedString::formatted("Symbol {} not found", symbol_name_view) };
return DlErrorMessage { ByteString::formatted("Symbol {} not found", symbol_name_view) };
if (symbol.value().type == STT_GNU_IFUNC)
return (void*)reinterpret_cast<DynamicObject::IfuncResolver>(symbol.value().address.as_ptr())();
@ -656,7 +656,7 @@ static void read_environment_variables()
}
}
void ELF::DynamicLinker::linker_main(DeprecatedString&& main_program_path, int main_program_fd, bool is_secure, int argc, char** argv, char** envp)
void ELF::DynamicLinker::linker_main(ByteString&& main_program_path, int main_program_fd, bool is_secure, int argc, char** argv, char** envp)
{
VERIFY(main_program_path.starts_with('/'));

View file

@ -15,9 +15,9 @@ namespace ELF {
class DynamicLinker {
public:
static Optional<DynamicObject::SymbolLookupResult> lookup_global_symbol(StringView symbol);
[[noreturn]] static void linker_main(DeprecatedString&& main_program_path, int fd, bool is_secure, int argc, char** argv, char** envp);
[[noreturn]] static void linker_main(ByteString&& main_program_path, int fd, bool is_secure, int argc, char** argv, char** envp);
static Optional<DeprecatedString> resolve_library(DeprecatedString const& name, DynamicObject const& parent_object);
static Optional<ByteString> resolve_library(ByteString const& name, DynamicObject const& parent_object);
private:
DynamicLinker() = delete;

View file

@ -44,7 +44,7 @@ void* __tlsdesc_static(void*);
namespace ELF {
Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(int fd, DeprecatedString filepath)
Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(int fd, ByteString filepath)
{
VERIFY(filepath.starts_with('/'));
@ -56,9 +56,9 @@ Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(i
VERIFY(stat.st_size >= 0);
auto size = static_cast<size_t>(stat.st_size);
if (size < sizeof(Elf_Ehdr))
return DlErrorMessage { DeprecatedString::formatted("File {} has invalid ELF header", filepath) };
return DlErrorMessage { ByteString::formatted("File {} has invalid ELF header", filepath) };
DeprecatedString file_mmap_name = DeprecatedString::formatted("ELF_DYN: {}", filepath);
ByteString file_mmap_name = ByteString::formatted("ELF_DYN: {}", filepath);
auto* data = mmap_with_name(nullptr, size, PROT_READ, MAP_SHARED, fd, 0, file_mmap_name.characters());
if (data == MAP_FAILED) {
return DlErrorMessage { "DynamicLoader::try_create mmap" };
@ -70,7 +70,7 @@ Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(i
return loader;
}
DynamicLoader::DynamicLoader(int fd, DeprecatedString filepath, void* data, size_t size)
DynamicLoader::DynamicLoader(int fd, ByteString filepath, void* data, size_t size)
: m_filepath(move(filepath))
, m_file_size(size)
, m_image_fd(fd)
@ -293,19 +293,19 @@ Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> DynamicLoader::load_stage_3
// If we don't have textrels, .text has already been made executable by this point in load_stage_2.
for (auto& text_segment : m_text_segments) {
if (mprotect(text_segment.address().as_ptr(), text_segment.size(), PROT_READ | PROT_EXEC) < 0) {
return DlErrorMessage { DeprecatedString::formatted("mprotect .text: PROT_READ | PROT_EXEC: {}", strerror(errno)) };
return DlErrorMessage { ByteString::formatted("mprotect .text: PROT_READ | PROT_EXEC: {}", strerror(errno)) };
}
}
}
if (m_relro_segment_size) {
if (mprotect(m_relro_segment_address.as_ptr(), m_relro_segment_size, PROT_READ) < 0) {
return DlErrorMessage { DeprecatedString::formatted("mprotect .relro: PROT_READ: {}", strerror(errno)) };
return DlErrorMessage { ByteString::formatted("mprotect .relro: PROT_READ: {}", strerror(errno)) };
}
#ifdef AK_OS_SERENITY
if (set_mmap_name(m_relro_segment_address.as_ptr(), m_relro_segment_size, DeprecatedString::formatted("{}: .relro", m_filepath).characters()) < 0) {
return DlErrorMessage { DeprecatedString::formatted("set_mmap_name .relro: {}", strerror(errno)) };
if (set_mmap_name(m_relro_segment_address.as_ptr(), m_relro_segment_size, ByteString::formatted("{}: .relro", m_filepath).characters()) < 0) {
return DlErrorMessage { ByteString::formatted("set_mmap_name .relro: {}", strerror(errno)) };
}
#endif
}
@ -388,7 +388,7 @@ void DynamicLoader::load_program_headers()
}
// Now that we can't accidentally block our requested space, re-map our ELF image.
DeprecatedString file_mmap_name = DeprecatedString::formatted("ELF_DYN: {}", m_filepath);
ByteString file_mmap_name = ByteString::formatted("ELF_DYN: {}", m_filepath);
auto* data = mmap_with_name(nullptr, m_file_size, PROT_READ, MAP_SHARED, m_image_fd, 0, file_mmap_name.characters());
if (data == MAP_FAILED) {
perror("mmap new mapping");
@ -444,9 +444,9 @@ void DynamicLoader::load_program_headers()
// Pre-allocate any malloc memory needed before unmapping the reservation.
// We don't want any future malloc to accidentally mmap a reserved address!
DeprecatedString text_segment_name = DeprecatedString::formatted("{}: .text", m_filepath);
DeprecatedString rodata_segment_name = DeprecatedString::formatted("{}: .rodata", m_filepath);
DeprecatedString data_segment_name = DeprecatedString::formatted("{}: .data", m_filepath);
ByteString text_segment_name = ByteString::formatted("{}: .text", m_filepath);
ByteString rodata_segment_name = ByteString::formatted("{}: .rodata", m_filepath);
ByteString data_segment_name = ByteString::formatted("{}: .data", m_filepath);
m_text_segments.ensure_capacity(map_regions.size());

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/Assertions.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <LibELF/DynamicObject.h>
@ -49,10 +49,10 @@ extern "C" FlatPtr _fixup_plt_entry(DynamicObject* object, u32 relocation_offset
class DynamicLoader : public RefCounted<DynamicLoader> {
public:
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> try_create(int fd, DeprecatedString filepath);
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> try_create(int fd, ByteString filepath);
~DynamicLoader();
DeprecatedString const& filepath() const { return m_filepath; }
ByteString const& filepath() const { return m_filepath; }
bool is_valid() const { return m_valid; }
@ -94,7 +94,7 @@ public:
bool is_fully_initialized() const { return m_fully_initialized; }
private:
DynamicLoader(int fd, DeprecatedString filepath, void* file_data, size_t file_size);
DynamicLoader(int fd, ByteString filepath, void* file_data, size_t file_size);
class ProgramHeaderRegion {
public:
@ -153,7 +153,7 @@ private:
void do_relr_relocations();
void find_tls_size_and_alignment();
DeprecatedString m_filepath;
ByteString m_filepath;
size_t m_file_size { 0 };
int m_image_fd { -1 };
void* m_file_data { nullptr };

View file

@ -5,8 +5,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/StringBuilder.h>
#include <LibELF/DynamicLoader.h>
#include <LibELF/DynamicObject.h>
@ -16,7 +16,7 @@
namespace ELF {
DynamicObject::DynamicObject(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address)
DynamicObject::DynamicObject(ByteString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address)
: m_filepath(filepath)
, m_base_address(base_address)
, m_dynamic_address(dynamic_section_address)
@ -58,7 +58,7 @@ void DynamicObject::dump() const
size_t num_dynamic_sections = 0;
for_each_dynamic_entry([&](DynamicObject::DynamicEntry const& entry) {
DeprecatedString name_field = DeprecatedString::formatted("({})", name_for_dtag(entry.tag()));
ByteString name_field = ByteString::formatted("({})", name_for_dtag(entry.tag()));
builder.appendff("{:#08x} {:17} {:#08x}\n", entry.tag(), name_field, entry.val());
num_dynamic_sections++;
});
@ -508,7 +508,7 @@ auto DynamicObject::lookup_symbol(HashSymbol const& symbol) const -> Optional<Sy
return SymbolLookupResult { symbol_result.value(), symbol_result.size(), symbol_result.address(), symbol_result.bind(), symbol_result.type(), this };
}
NonnullRefPtr<DynamicObject> DynamicObject::create(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address)
NonnullRefPtr<DynamicObject> DynamicObject::create(ByteString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address)
{
return adopt_ref(*new DynamicObject(filepath, base_address, dynamic_section_address));
}

View file

@ -9,8 +9,8 @@
#pragma once
#include <AK/Assertions.h>
#include <AK/ByteString.h>
#include <AK/Concepts.h>
#include <AK/DeprecatedString.h>
#include <AK/RefCounted.h>
#include <Kernel/Memory/VirtualAddress.h>
#include <LibELF/ELFABI.h>
@ -20,7 +20,7 @@ namespace ELF {
class DynamicObject : public RefCounted<DynamicObject> {
public:
static NonnullRefPtr<DynamicObject> create(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
static NonnullRefPtr<DynamicObject> create(ByteString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
static char const* name_for_dtag(Elf_Sword d_tag);
~DynamicObject();
@ -284,7 +284,7 @@ public:
VirtualAddress plt_got_base_address() const { return m_base_address.offset(m_procedure_linkage_table_offset.value()); }
VirtualAddress base_address() const { return m_base_address; }
DeprecatedString const& filepath() const { return m_filepath; }
ByteString const& filepath() const { return m_filepath; }
StringView rpath() const { return m_has_rpath ? symbol_string_table_string(m_rpath_index) : StringView {}; }
StringView runpath() const { return m_has_runpath ? symbol_string_table_string(m_runpath_index) : StringView {}; }
@ -332,13 +332,13 @@ public:
void* symbol_for_name(StringView name);
private:
explicit DynamicObject(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
explicit DynamicObject(ByteString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
StringView symbol_string_table_string(Elf_Word) const;
char const* raw_symbol_string_table_string(Elf_Word) const;
void parse();
DeprecatedString m_filepath;
ByteString m_filepath;
VirtualAddress m_base_address;
VirtualAddress m_dynamic_address;

View file

@ -438,7 +438,7 @@ NEVER_INLINE void Image::sort_symbols() const
});
}
DeprecatedString Image::symbolicate(FlatPtr address, u32* out_offset) const
ByteString Image::symbolicate(FlatPtr address, u32* out_offset) const
{
auto symbol_count = this->symbol_count();
if (!symbol_count) {
@ -462,7 +462,7 @@ DeprecatedString Image::symbolicate(FlatPtr address, u32* out_offset) const
*out_offset = address - symbol->address;
return demangled_name;
}
return DeprecatedString::formatted("{} +{:#x}", demangled_name, address - symbol->address);
return ByteString::formatted("{} +{:#x}", demangled_name, address - symbol->address);
}
#endif

View file

@ -13,7 +13,7 @@
#include <LibELF/ELFABI.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
#endif
namespace ELF {
@ -221,7 +221,7 @@ public:
bool has_symbols() const { return symbol_count(); }
#ifndef KERNEL
Optional<Symbol> find_demangled_function(StringView name) const;
DeprecatedString symbolicate(FlatPtr address, u32* offset = nullptr) const;
ByteString symbolicate(FlatPtr address, u32* offset = nullptr) const;
#endif
Optional<Image::Symbol> find_symbol(FlatPtr address, u32* offset = nullptr) const;
@ -246,7 +246,7 @@ private:
struct SortedSymbol {
FlatPtr address;
StringView name;
DeprecatedString demangled_name;
ByteString demangled_name;
Optional<Image::Symbol> symbol;
};