mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:05:07 +00:00
Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the kmalloc or eternal pool.
This commit is contained in:
parent
5a98e329d1
commit
41c005cb14
3 changed files with 22 additions and 4 deletions
|
@ -25,21 +25,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Kernel/CommandLine.h>
|
#include <Kernel/CommandLine.h>
|
||||||
|
#include <Kernel/StdLib.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
static char s_cmd_line[1024];
|
||||||
static CommandLine* s_the;
|
static CommandLine* s_the;
|
||||||
|
|
||||||
|
void CommandLine::early_initialize(const char* 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';
|
||||||
|
}
|
||||||
|
|
||||||
const CommandLine& kernel_command_line()
|
const CommandLine& kernel_command_line()
|
||||||
{
|
{
|
||||||
ASSERT(s_the);
|
ASSERT(s_the);
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLine::initialize(const String& string)
|
void CommandLine::initialize()
|
||||||
{
|
{
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = new CommandLine(string);
|
s_the = new CommandLine(s_cmd_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLine::CommandLine(const String& string)
|
CommandLine::CommandLine(const String& string)
|
||||||
|
|
|
@ -36,7 +36,8 @@ class CommandLine {
|
||||||
AK_MAKE_ETERNAL;
|
AK_MAKE_ETERNAL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void initialize(const String&);
|
static void early_initialize(const char* cmd_line);
|
||||||
|
static void initialize();
|
||||||
|
|
||||||
const String& string() const { return m_string; }
|
const String& string() const { return m_string; }
|
||||||
Optional<String> lookup(const String& key) const;
|
Optional<String> lookup(const String& key) const;
|
||||||
|
|
|
@ -113,6 +113,10 @@ extern "C" [[noreturn]] void init()
|
||||||
{
|
{
|
||||||
setup_serial_debug();
|
setup_serial_debug();
|
||||||
|
|
||||||
|
// We need to copy the command line before kmalloc is initialized,
|
||||||
|
// as it may overwrite parts of multiboot!
|
||||||
|
CommandLine::early_initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
|
||||||
|
|
||||||
s_bsp_processor.early_initialize(0);
|
s_bsp_processor.early_initialize(0);
|
||||||
|
|
||||||
// Invoke the constructors needed for the kernel heap
|
// Invoke the constructors needed for the kernel heap
|
||||||
|
@ -123,7 +127,7 @@ extern "C" [[noreturn]] void init()
|
||||||
|
|
||||||
s_bsp_processor.initialize(0);
|
s_bsp_processor.initialize(0);
|
||||||
|
|
||||||
CommandLine::initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
|
CommandLine::initialize();
|
||||||
MemoryManager::initialize(0);
|
MemoryManager::initialize(0);
|
||||||
|
|
||||||
// Invoke all static global constructors in the kernel.
|
// Invoke all static global constructors in the kernel.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue