mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Store the kernel command line in a StringView
The Raspberry Pi's mailbox interface does not guarantee that the returned command line is null-terminated. This commit removes that assumption from the current code, allowing the next commit to add support for reading it on the Pi. This also lets us eliminate a few manual `strlen()` calls :^)
This commit is contained in:
parent
c911fb0150
commit
6aa392f6e4
Notes:
sideshowbarker
2024-07-17 07:20:49 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/6aa392f6e4 Pull-request: https://github.com/SerenityOS/serenity/pull/18557 Reviewed-by: https://github.com/FireFox317 Reviewed-by: https://github.com/nico ✅
4 changed files with 10 additions and 14 deletions
|
@ -133,7 +133,7 @@ READONLY_AFTER_INIT PhysicalAddress boot_pdpt;
|
|||
READONLY_AFTER_INIT PhysicalAddress boot_pd0;
|
||||
READONLY_AFTER_INIT PhysicalAddress boot_pd_kernel;
|
||||
READONLY_AFTER_INIT Memory::PageTableEntry* boot_pd_kernel_pt1023;
|
||||
READONLY_AFTER_INIT char const* kernel_cmdline;
|
||||
READONLY_AFTER_INIT StringView kernel_cmdline;
|
||||
READONLY_AFTER_INIT u32 multiboot_flags;
|
||||
READONLY_AFTER_INIT multiboot_memory_map_t* multiboot_memory_map;
|
||||
READONLY_AFTER_INIT size_t multiboot_memory_map_count;
|
||||
|
@ -166,7 +166,8 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init([[maybe_unused]] BootInfo con
|
|||
boot_pd0 = PhysicalAddress { boot_info.boot_pd0 };
|
||||
boot_pd_kernel = PhysicalAddress { boot_info.boot_pd_kernel };
|
||||
boot_pd_kernel_pt1023 = (Memory::PageTableEntry*)boot_info.boot_pd_kernel_pt1023;
|
||||
kernel_cmdline = (char const*)boot_info.kernel_cmdline;
|
||||
char const* cmdline = (char const*)boot_info.kernel_cmdline;
|
||||
kernel_cmdline = StringView { cmdline, strlen(cmdline) };
|
||||
multiboot_flags = boot_info.multiboot_flags;
|
||||
multiboot_memory_map = (multiboot_memory_map_t*)boot_info.multiboot_memory_map;
|
||||
multiboot_memory_map_count = boot_info.multiboot_memory_map_count;
|
||||
|
@ -192,7 +193,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init([[maybe_unused]] BootInfo con
|
|||
multiboot_module_entry_t modules[] = {};
|
||||
multiboot_modules = modules;
|
||||
multiboot_modules_count = 0;
|
||||
kernel_cmdline = "";
|
||||
kernel_cmdline = ""sv;
|
||||
#endif
|
||||
|
||||
setup_serial_debug();
|
||||
|
@ -442,7 +443,7 @@ UNMAP_AFTER_INIT void setup_serial_debug()
|
|||
// serial_debug will output all the dbgln() data to COM1 at
|
||||
// 8-N-1 57600 baud. this is particularly useful for debugging the boot
|
||||
// process on live hardware.
|
||||
if (StringView { kernel_cmdline, strlen(kernel_cmdline) }.contains("serial_debug"sv)) {
|
||||
if (kernel_cmdline.contains("serial_debug"sv)) {
|
||||
set_serial_debug_enabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Multiboot.h>
|
||||
#include <Kernel/PhysicalAddress.h>
|
||||
#include <Kernel/VirtualAddress.h>
|
||||
|
@ -28,7 +29,7 @@ extern "C" PhysicalAddress boot_pdpt;
|
|||
extern "C" PhysicalAddress boot_pd0;
|
||||
extern "C" PhysicalAddress boot_pd_kernel;
|
||||
extern "C" Kernel::Memory::PageTableEntry* boot_pd_kernel_pt1023;
|
||||
extern "C" char const* kernel_cmdline;
|
||||
extern "C" StringView kernel_cmdline;
|
||||
extern "C" u32 multiboot_flags;
|
||||
extern "C" multiboot_memory_map_t* multiboot_memory_map;
|
||||
extern "C" size_t multiboot_memory_map_count;
|
||||
|
|
|
@ -16,15 +16,9 @@ static char s_cmd_line[1024];
|
|||
static constexpr StringView s_embedded_cmd_line = ""sv;
|
||||
static CommandLine* s_the;
|
||||
|
||||
UNMAP_AFTER_INIT void CommandLine::early_initialize(char const* cmd_line)
|
||||
UNMAP_AFTER_INIT void CommandLine::early_initialize(StringView cmd_line)
|
||||
{
|
||||
if (!cmd_line)
|
||||
return;
|
||||
size_t length = strlen(cmd_line);
|
||||
if (length >= sizeof(s_cmd_line))
|
||||
length = sizeof(s_cmd_line) - 1;
|
||||
memcpy(s_cmd_line, cmd_line, length);
|
||||
s_cmd_line[length] = '\0';
|
||||
(void)cmd_line.copy_characters_to_buffer(s_cmd_line, sizeof(s_cmd_line));
|
||||
}
|
||||
|
||||
bool CommandLine::was_initialized()
|
||||
|
|
|
@ -52,7 +52,7 @@ enum class AHCIResetMode {
|
|||
class CommandLine {
|
||||
|
||||
public:
|
||||
static void early_initialize(char const* cmd_line);
|
||||
static void early_initialize(StringView cmd_line);
|
||||
static void initialize();
|
||||
static bool was_initialized();
|
||||
|
||||
|
|
Loading…
Reference in a new issue