1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17: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

@ -42,7 +42,7 @@ Emulator& Emulator::the()
return *s_the;
}
Emulator::Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment)
Emulator::Emulator(ByteString const& executable_path, Vector<StringView> const& arguments, Vector<ByteString> const& environment)
: m_executable_path(executable_path)
, m_arguments(arguments)
, m_environment(environment)
@ -70,7 +70,7 @@ Emulator::Emulator(DeprecatedString const& executable_path, Vector<StringView> c
setup_signal_trampoline();
}
Vector<ELF::AuxiliaryValue> Emulator::generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, DeprecatedString const& executable_path, int executable_fd) const
Vector<ELF::AuxiliaryValue> Emulator::generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, ByteString const& executable_path, int executable_fd) const
{
// FIXME: This is not fully compatible with the auxiliary vector the kernel generates, this is just the bare
// minimum to get the loader going.
@ -227,7 +227,7 @@ int Emulator::exec()
size_t instructions_until_next_profile_dump = profile_instruction_interval();
if (is_profiling() && m_loader_text_size.has_value())
emit_profile_event(profile_stream(), "mmap"sv, DeprecatedString::formatted(R"("ptr": {}, "size": {}, "name": "/usr/lib/Loader.so")", *m_loader_text_base, *m_loader_text_size));
emit_profile_event(profile_stream(), "mmap"sv, ByteString::formatted(R"("ptr": {}, "size": {}, "name": "/usr/lib/Loader.so")", *m_loader_text_base, *m_loader_text_size));
while (!m_shutdown) {
if (m_steps_til_pause) [[likely]] {
@ -235,7 +235,7 @@ int Emulator::exec()
auto insn = X86::Instruction::from_stream(*m_cpu, X86::ProcessorMode::Protected);
// Exec cycle
if constexpr (trace) {
outln("{:p} \033[33;1m{}\033[0m", m_cpu->base_eip(), insn.to_deprecated_string(m_cpu->base_eip(), symbol_provider));
outln("{:p} \033[33;1m{}\033[0m", m_cpu->base_eip(), insn.to_byte_string(m_cpu->base_eip(), symbol_provider));
}
(m_cpu->*insn.handler())(insn);
@ -419,13 +419,13 @@ MmapRegion const* Emulator::load_library_from_address(FlatPtr address)
if (!region)
return {};
DeprecatedString lib_name = region->lib_name();
ByteString lib_name = region->lib_name();
if (lib_name.is_null())
return {};
DeprecatedString lib_path = lib_name;
ByteString lib_path = lib_name;
if (FileSystem::looks_like_shared_library(lib_name))
lib_path = DeprecatedString::formatted("/usr/lib/{}", lib_path);
lib_path = ByteString::formatted("/usr/lib/{}", lib_path);
if (!m_dynamic_library_cache.contains(lib_path)) {
auto file_or_error = Core::MappedFile::map(lib_path);
@ -463,7 +463,7 @@ Optional<Emulator::SymbolInfo> Emulator::symbol_at(FlatPtr address)
VERIFY(first_region);
auto lib_path = lib_name;
if (FileSystem::looks_like_shared_library(lib_name)) {
lib_path = DeprecatedString::formatted("/usr/lib/{}", lib_name);
lib_path = ByteString::formatted("/usr/lib/{}", lib_name);
}
auto it = m_dynamic_library_cache.find(lib_path);
@ -474,18 +474,18 @@ Optional<Emulator::SymbolInfo> Emulator::symbol_at(FlatPtr address)
return { { lib_name, symbol, source_position } };
}
DeprecatedString Emulator::create_backtrace_line(FlatPtr address)
ByteString Emulator::create_backtrace_line(FlatPtr address)
{
auto maybe_symbol = symbol_at(address);
if (!maybe_symbol.has_value()) {
return DeprecatedString::formatted("=={}== {:p}", getpid(), address);
return ByteString::formatted("=={}== {:p}", getpid(), address);
}
if (!maybe_symbol->source_position.has_value()) {
return DeprecatedString::formatted("=={}== {:p} [{}]: {}", getpid(), address, maybe_symbol->lib_name, maybe_symbol->symbol);
return ByteString::formatted("=={}== {:p} [{}]: {}", getpid(), address, maybe_symbol->lib_name, maybe_symbol->symbol);
}
auto const& source_position = maybe_symbol->source_position.value();
return DeprecatedString::formatted("=={}== {:p} [{}]: {} (\e[34;1m{}\e[0m:{})", getpid(), address, maybe_symbol->lib_name, maybe_symbol->symbol, LexicalPath::basename(source_position.file_path), source_position.line_number);
return ByteString::formatted("=={}== {:p} [{}]: {} (\e[34;1m{}\e[0m:{})", getpid(), address, maybe_symbol->lib_name, maybe_symbol->symbol, LexicalPath::basename(source_position.file_path), source_position.line_number);
}
void Emulator::dump_backtrace(Vector<FlatPtr> const& backtrace)
@ -513,7 +513,7 @@ void Emulator::emit_profile_sample(Stream& output)
output.write_until_depleted(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors();
}
void Emulator::emit_profile_event(Stream& output, StringView event_name, DeprecatedString const& contents)
void Emulator::emit_profile_event(Stream& output, StringView event_name, ByteString const& contents)
{
StringBuilder builder;
timeval tv {};
@ -523,13 +523,13 @@ void Emulator::emit_profile_event(Stream& output, StringView event_name, Depreca
output.write_until_depleted(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors();
}
DeprecatedString Emulator::create_instruction_line(FlatPtr address, X86::Instruction const& insn)
ByteString Emulator::create_instruction_line(FlatPtr address, X86::Instruction const& insn)
{
auto symbol = symbol_at(address);
if (!symbol.has_value() || !symbol->source_position.has_value())
return DeprecatedString::formatted("{:p}: {}", address, insn.to_deprecated_string(address));
return ByteString::formatted("{:p}: {}", address, insn.to_byte_string(address));
return DeprecatedString::formatted("{:p}: {} \e[34;1m{}\e[0m:{}", address, insn.to_deprecated_string(address), LexicalPath::basename(symbol->source_position->file_path), symbol->source_position.value().line_number);
return ByteString::formatted("{:p}: {} \e[34;1m{}\e[0m:{}", address, insn.to_byte_string(address), LexicalPath::basename(symbol->source_position->file_path), symbol->source_position.value().line_number);
}
static void emulator_signal_handler(int signum, siginfo_t* signal_info, void* context)

View file

@ -30,9 +30,9 @@ class Emulator {
public:
static Emulator& the();
Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment);
Emulator(ByteString const& executable_path, Vector<StringView> const& arguments, Vector<ByteString> const& environment);
void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Stream* profile_stream, Vector<NonnullOwnPtr<DeprecatedString>>* profiler_strings, Vector<int>* profiler_string_id_map)
void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Stream* profile_stream, Vector<NonnullOwnPtr<ByteString>>* profiler_strings, Vector<int>* profiler_string_id_map)
{
m_is_profiling = should_dump_profile;
m_profile_instruction_interval = instruction_interval;
@ -47,7 +47,7 @@ public:
}
Stream& profile_stream() { return *m_profile_stream; }
Vector<NonnullOwnPtr<DeprecatedString>>& profiler_strings() { return *m_profiler_strings; }
Vector<NonnullOwnPtr<ByteString>>& profiler_strings() { return *m_profiler_strings; }
Vector<int>& profiler_string_id_map() { return *m_profiler_string_id_map; }
bool is_profiling() const { return m_is_profiling; }
@ -113,8 +113,8 @@ public:
}
struct SymbolInfo {
DeprecatedString lib_name;
DeprecatedString symbol;
ByteString lib_name;
ByteString symbol;
Optional<Debug::DebugInfo::SourcePosition> source_position;
};
@ -123,9 +123,9 @@ public:
void dump_regions() const;
private:
const DeprecatedString m_executable_path;
const ByteString m_executable_path;
Vector<StringView> const m_arguments;
Vector<DeprecatedString> const m_environment;
Vector<ByteString> const m_environment;
SoftMMU m_mmu;
NonnullOwnPtr<SoftCPU> m_cpu;
@ -133,14 +133,14 @@ private:
OwnPtr<MallocTracer> m_malloc_tracer;
void setup_stack(Vector<ELF::AuxiliaryValue>);
Vector<ELF::AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, DeprecatedString const& executable_path, int executable_fd) const;
Vector<ELF::AuxiliaryValue> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, ByteString const& executable_path, int executable_fd) const;
void register_signal_handlers();
void setup_signal_trampoline();
void send_signal(int);
void emit_profile_sample(Stream&);
void emit_profile_event(Stream&, StringView event_name, DeprecatedString const& contents);
void emit_profile_event(Stream&, StringView event_name, ByteString const& contents);
int virt$accept4(FlatPtr);
u32 virt$allocate_tls(FlatPtr, size_t);
@ -254,8 +254,8 @@ private:
MmapRegion const* find_text_region(FlatPtr address);
MmapRegion const* load_library_from_address(FlatPtr address);
MmapRegion const* first_region_for_object(StringView name);
DeprecatedString create_backtrace_line(FlatPtr address);
DeprecatedString create_instruction_line(FlatPtr address, X86::Instruction const& insn);
ByteString create_backtrace_line(FlatPtr address);
ByteString create_instruction_line(FlatPtr address, X86::Instruction const& insn);
bool m_shutdown { false };
int m_exit_status { 0 };
@ -290,13 +290,13 @@ private:
NonnullOwnPtr<ELF::Image> image;
};
HashMap<DeprecatedString, CachedELF> m_dynamic_library_cache;
HashMap<ByteString, CachedELF> m_dynamic_library_cache;
RangeAllocator m_range_allocator;
Stream* m_profile_stream { nullptr };
Vector<int>* m_profiler_string_id_map { nullptr };
Vector<NonnullOwnPtr<DeprecatedString>>* m_profiler_strings { nullptr };
Vector<NonnullOwnPtr<ByteString>>* m_profiler_strings { nullptr };
bool m_is_profiling { false };
size_t m_profile_instruction_interval { 0 };

View file

@ -292,7 +292,7 @@ FlatPtr Emulator::virt$perf_event(int event, FlatPtr arg1, FlatPtr arg2)
if (event == PERF_EVENT_SIGNPOST) {
if (is_profiling()) {
if (profiler_string_id_map().size() > arg1)
emit_profile_event(profile_stream(), "signpost"sv, DeprecatedString::formatted("\"arg1\": {}, \"arg2\": {}", arg1, arg2));
emit_profile_event(profile_stream(), "signpost"sv, ByteString::formatted("\"arg1\": {}, \"arg2\": {}", arg1, arg2));
syscall(SC_perf_event, PERF_EVENT_SIGNPOST, profiler_string_id_map().at(arg1), arg2);
} else {
syscall(SC_perf_event, PERF_EVENT_SIGNPOST, arg1, arg2);
@ -311,7 +311,7 @@ FlatPtr Emulator::virt$perf_register_string(FlatPtr string, size_t size)
auto ret = (int)syscall(SC_perf_register_string, buffer, size + 4);
if (ret >= 0 && is_profiling()) {
profiler_strings().append(make<DeprecatedString>(StringView { buffer + 4, size }));
profiler_strings().append(make<ByteString>(StringView { buffer + 4, size }));
profiler_string_id_map().append(ret);
ret = profiler_string_id_map().size() - 1;
}
@ -564,7 +564,7 @@ int Emulator::virt$set_mmap_name(FlatPtr params_addr)
auto* region = mmu().find_region({ 0x23, (FlatPtr)params.addr });
if (!region || !is<MmapRegion>(*region))
return -EINVAL;
static_cast<MmapRegion&>(*region).set_name(DeprecatedString::copy(name));
static_cast<MmapRegion&>(*region).set_name(ByteString::copy(name));
return 0;
}
@ -802,7 +802,7 @@ static void round_to_page_size(FlatPtr& address, size_t& size)
u32 Emulator::virt$munmap(FlatPtr address, size_t size)
{
if (is_profiling())
emit_profile_event(profile_stream(), "munmap"sv, DeprecatedString::formatted("\"ptr\": {}, \"size\": {}", address, size));
emit_profile_event(profile_stream(), "munmap"sv, ByteString::formatted("\"ptr\": {}, \"size\": {}", address, size));
round_to_page_size(address, size);
Vector<Region*, 4> marked_for_deletion;
bool has_non_mmap_region = false;
@ -861,7 +861,7 @@ u32 Emulator::virt$mmap(u32 params_addr)
final_address = result.value().base().get();
auto final_size = result.value().size();
DeprecatedString name_str;
ByteString name_str;
if (params.name.characters) {
auto buffer_result = ByteBuffer::create_uninitialized(params.name.length);
if (buffer_result.is_error())
@ -872,7 +872,7 @@ u32 Emulator::virt$mmap(u32 params_addr)
}
if (is_profiling())
emit_profile_event(profile_stream(), "mmap"sv, DeprecatedString::formatted(R"("ptr": {}, "size": {}, "name": "{}")", final_address, final_size, name_str));
emit_profile_event(profile_stream(), "mmap"sv, ByteString::formatted(R"("ptr": {}, "size": {}, "name": "{}")", final_address, final_size, name_str));
if (params.flags & MAP_ANONYMOUS) {
mmu().add_region(MmapRegion::create_anonymous(final_address, final_size, params.prot, move(name_str)));
@ -1216,15 +1216,15 @@ int Emulator::virt$execve(FlatPtr params_addr)
Syscall::SC_execve_params params;
mmu().copy_from_vm(&params, params_addr, sizeof(params));
auto path = DeprecatedString::copy(mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length));
Vector<DeprecatedString> arguments;
Vector<DeprecatedString> environment;
auto path = ByteString::copy(mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length));
Vector<ByteString> arguments;
Vector<ByteString> environment;
auto copy_string_list = [this](auto& output_vector, auto& string_list) {
for (size_t i = 0; i < string_list.length; ++i) {
Syscall::StringArgument string;
mmu().copy_from_vm(&string, (FlatPtr)&string_list.strings[i], sizeof(string));
output_vector.append(DeprecatedString::copy(mmu().copy_buffer_from_vm((FlatPtr)string.characters, string.length)));
output_vector.append(ByteString::copy(mmu().copy_buffer_from_vm((FlatPtr)string.characters, string.length)));
}
};
@ -1270,7 +1270,7 @@ int Emulator::virt$stat(FlatPtr params_addr)
Syscall::SC_stat_params params;
mmu().copy_from_vm(&params, params_addr, sizeof(params));
auto path = DeprecatedString::copy(mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length));
auto path = ByteString::copy(mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length));
struct stat host_statbuf;
int rc;
if (params.follow_symlinks)

View file

@ -26,20 +26,20 @@ static void free_pages(void* ptr, size_t bytes)
VERIFY(rc == 0);
}
NonnullOwnPtr<MmapRegion> MmapRegion::create_anonymous(u32 base, u32 size, u32 prot, DeprecatedString name)
NonnullOwnPtr<MmapRegion> MmapRegion::create_anonymous(u32 base, u32 size, u32 prot, ByteString name)
{
auto* data = (u8*)mmap_initialized(size, 0, DeprecatedString::formatted("(UE) {}", name).characters());
auto* data = (u8*)mmap_initialized(size, 0, ByteString::formatted("(UE) {}", name).characters());
auto* shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
region->m_name = move(name);
return region;
}
NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, DeprecatedString name)
NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, ByteString name)
{
// Since we put the memory to an arbitrary location, do not pass MAP_FIXED and MAP_FIXED_NOREPLACE to the Kernel.
auto real_flags = flags & ~(MAP_FIXED | MAP_FIXED_NOREPLACE);
auto* data = (u8*)mmap_with_name(nullptr, size, prot, real_flags, fd, offset, name.is_empty() ? nullptr : DeprecatedString::formatted("(UE) {}", name).characters());
auto* data = (u8*)mmap_with_name(nullptr, size, prot, real_flags, fd, offset, name.is_empty() ? nullptr : ByteString::formatted("(UE) {}", name).characters());
VERIFY(data != MAP_FAILED);
auto* shadow_data = (u8*)mmap_initialized(size, 1, "MmapRegion ShadowData");
auto region = adopt_own(*new MmapRegion(base, size, prot, data, shadow_data));
@ -318,10 +318,10 @@ void MmapRegion::set_prot(int prot)
}
}
void MmapRegion::set_name(DeprecatedString name)
void MmapRegion::set_name(ByteString name)
{
m_name = move(name);
set_mmap_name(range().base().as_ptr(), range().size(), DeprecatedString::formatted("(UE) {}", m_name).characters());
set_mmap_name(range().base().as_ptr(), range().size(), ByteString::formatted("(UE) {}", m_name).characters());
}
}

View file

@ -16,8 +16,8 @@ class MallocTracer;
class MmapRegion final : public Region {
public:
static NonnullOwnPtr<MmapRegion> create_anonymous(u32 base, u32 size, u32 prot, DeprecatedString name);
static NonnullOwnPtr<MmapRegion> create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, DeprecatedString name);
static NonnullOwnPtr<MmapRegion> create_anonymous(u32 base, u32 size, u32 prot, ByteString name);
static NonnullOwnPtr<MmapRegion> create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset, ByteString name);
virtual ~MmapRegion() override;
virtual ValueWithShadow<u8> read8(u32 offset) override;
@ -51,8 +51,8 @@ public:
MallocRegionMetadata* malloc_metadata() { return m_malloc_metadata; }
void set_malloc_metadata(Badge<MallocTracer>, NonnullOwnPtr<MallocRegionMetadata> metadata) { m_malloc_metadata = move(metadata); }
DeprecatedString const& name() const { return m_name; }
DeprecatedString lib_name() const
ByteString const& name() const { return m_name; }
ByteString lib_name() const
{
if (m_name.contains("Loader.so"sv))
return "Loader.so";
@ -61,7 +61,7 @@ public:
return {};
return m_name.substring(0, *maybe_separator);
}
void set_name(DeprecatedString name);
void set_name(ByteString name);
private:
MmapRegion(u32 base, u32 size, int prot, u8* data, u8* shadow_data);
@ -72,7 +72,7 @@ private:
bool m_malloc { false };
OwnPtr<MallocRegionMetadata> m_malloc_metadata;
DeprecatedString m_name;
ByteString m_name;
};
template<>

View file

@ -114,7 +114,7 @@ private:
}
}
DeprecatedString fpu_exception_string(FPU_Exception ex)
ByteString fpu_exception_string(FPU_Exception ex)
{
switch (ex) {
case FPU_Exception::StackFault:

View file

@ -23,7 +23,7 @@ int main(int argc, char** argv, char** env)
{
Vector<StringView> arguments;
bool pause_on_startup { false };
DeprecatedString profile_dump_path;
ByteString profile_dump_path;
bool enable_roi_mode { false };
bool dump_profile { false };
unsigned profile_instruction_interval { 0 };
@ -51,13 +51,13 @@ int main(int argc, char** argv, char** env)
reportln("Cannot find executable for '{}'."sv, arguments[0]);
return 1;
}
auto executable_path = executable_path_or_error.release_value().to_deprecated_string();
auto executable_path = executable_path_or_error.release_value().to_byte_string();
if (dump_profile && profile_dump_path.is_empty())
profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid());
profile_dump_path = ByteString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid());
OwnPtr<Stream> profile_stream;
OwnPtr<Vector<NonnullOwnPtr<DeprecatedString>>> profile_strings;
OwnPtr<Vector<NonnullOwnPtr<ByteString>>> profile_strings;
OwnPtr<Vector<int>> profile_string_id_map;
if (dump_profile) {
@ -67,21 +67,21 @@ int main(int argc, char** argv, char** env)
return 1;
}
profile_stream = profile_stream_or_error.release_value();
profile_strings = make<Vector<NonnullOwnPtr<DeprecatedString>>>();
profile_strings = make<Vector<NonnullOwnPtr<ByteString>>>();
profile_string_id_map = make<Vector<int>>();
profile_stream->write_until_depleted(R"({"events":[)"sv.bytes()).release_value_but_fixme_should_propagate_errors();
timeval tv {};
gettimeofday(&tv, nullptr);
profile_stream->write_until_depleted(
DeprecatedString::formatted(
ByteString::formatted(
R"~({{"type": "process_create", "parent_pid": 1, "executable": "{}", "pid": {}, "tid": {}, "timestamp": {}, "lost_samples": 0, "stack": []}})~",
executable_path, getpid(), gettid(), tv.tv_sec * 1000 + tv.tv_usec / 1000)
.bytes())
.release_value_but_fixme_should_propagate_errors();
}
Vector<DeprecatedString> environment;
Vector<ByteString> environment;
for (int i = 0; env[i]; ++i) {
environment.append(env[i]);
}
@ -112,8 +112,8 @@ int main(int argc, char** argv, char** env)
emulator.profile_stream().write_until_depleted("], \"strings\": ["sv.bytes()).release_value_but_fixme_should_propagate_errors();
if (emulator.profiler_strings().size()) {
for (size_t i = 0; i < emulator.profiler_strings().size() - 1; ++i)
emulator.profile_stream().write_until_depleted(DeprecatedString::formatted("\"{}\", ", emulator.profiler_strings().at(i)).bytes()).release_value_but_fixme_should_propagate_errors();
emulator.profile_stream().write_until_depleted(DeprecatedString::formatted("\"{}\"", emulator.profiler_strings().last()).bytes()).release_value_but_fixme_should_propagate_errors();
emulator.profile_stream().write_until_depleted(ByteString::formatted("\"{}\", ", emulator.profiler_strings().at(i)).bytes()).release_value_but_fixme_should_propagate_errors();
emulator.profile_stream().write_until_depleted(ByteString::formatted("\"{}\"", emulator.profiler_strings().last()).bytes()).release_value_but_fixme_should_propagate_errors();
}
emulator.profile_stream().write_until_depleted("]}"sv.bytes()).release_value_but_fixme_should_propagate_errors();
}