mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:07:45 +00:00
Kernel/SysFS: Prevent allocation for component name during construction
Instead, allocate before constructing the object and pass NonnullOwnPtr of KString to the object if needed. Some classes can determine their names as they have a known attribute to look for or have a static name.
This commit is contained in:
parent
4daf07e69f
commit
478f543899
17 changed files with 116 additions and 65 deletions
|
@ -34,9 +34,11 @@ void Parser::must_initialize(PhysicalAddress rsdp, PhysicalAddress fadt, u8 irq_
|
|||
VERIFY(s_acpi_parser);
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSComponent> ACPISysFSComponent::create(String name, PhysicalAddress paddr, size_t table_size)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSComponent> ACPISysFSComponent::create(StringView name, PhysicalAddress paddr, size_t table_size)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) ACPISysFSComponent(name, paddr, table_size));
|
||||
// FIXME: Handle allocation failure gracefully
|
||||
auto table_name = KString::must_create(name);
|
||||
return adopt_ref(*new (nothrow) ACPISysFSComponent(move(table_name), paddr, table_size));
|
||||
}
|
||||
|
||||
ErrorOr<size_t> ACPISysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const
|
||||
|
@ -57,10 +59,11 @@ ErrorOr<NonnullOwnPtr<KBuffer>> ACPISysFSComponent::try_to_generate_buffer() con
|
|||
return KBuffer::try_create_with_bytes(Span<u8> { acpi_blob.ptr(), m_length });
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(String name, PhysicalAddress paddr, size_t table_size)
|
||||
: SysFSComponent(name)
|
||||
UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(NonnullOwnPtr<KString> table_name, PhysicalAddress paddr, size_t table_size)
|
||||
: SysFSComponent()
|
||||
, m_paddr(paddr)
|
||||
, m_length(table_size)
|
||||
, m_table_name(move(table_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -71,7 +74,7 @@ UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> ACPISysFSDirectory::
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT ACPISysFSDirectory::ACPISysFSDirectory(FirmwareSysFSDirectory& firmware_directory)
|
||||
: SysFSDirectory("acpi", firmware_directory)
|
||||
: SysFSDirectory(firmware_directory)
|
||||
{
|
||||
NonnullRefPtrVector<SysFSComponent> components;
|
||||
size_t ssdt_count = 0;
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Kernel::ACPI {
|
|||
|
||||
class ACPISysFSDirectory : public SysFSDirectory {
|
||||
public:
|
||||
virtual StringView name() const override { return "acpi"sv; }
|
||||
static ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> try_create(FirmwareSysFSDirectory& firmware_directory);
|
||||
|
||||
private:
|
||||
|
@ -30,16 +31,17 @@ private:
|
|||
|
||||
class ACPISysFSComponent : public SysFSComponent {
|
||||
public:
|
||||
static NonnullRefPtr<ACPISysFSComponent> create(String name, PhysicalAddress, size_t table_size);
|
||||
|
||||
static NonnullRefPtr<ACPISysFSComponent> create(StringView name, PhysicalAddress, size_t table_size);
|
||||
virtual StringView name() const override { return m_table_name->view(); }
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
|
||||
|
||||
protected:
|
||||
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
|
||||
ACPISysFSComponent(String name, PhysicalAddress, size_t table_size);
|
||||
ACPISysFSComponent(NonnullOwnPtr<KString> table_name, PhysicalAddress, size_t table_size);
|
||||
|
||||
PhysicalAddress m_paddr;
|
||||
size_t m_length;
|
||||
NonnullOwnPtr<KString> m_table_name;
|
||||
};
|
||||
|
||||
class Parser final : public IRQHandler {
|
||||
|
|
|
@ -24,8 +24,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<DMIEntryPointExposedBlob> DMIEntryPointExposedBlo
|
|||
return adopt_ref(*new (nothrow) DMIEntryPointExposedBlob(dmi_entry_point, blob_size));
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT BIOSSysFSComponent::BIOSSysFSComponent(StringView name)
|
||||
: SysFSComponent(name)
|
||||
UNMAP_AFTER_INIT BIOSSysFSComponent::BIOSSysFSComponent()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,7 @@ ErrorOr<size_t> BIOSSysFSComponent::read_bytes(off_t offset, size_t count, UserO
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT DMIEntryPointExposedBlob::DMIEntryPointExposedBlob(PhysicalAddress dmi_entry_point, size_t blob_size)
|
||||
: BIOSSysFSComponent("smbios_entry_point"sv)
|
||||
: BIOSSysFSComponent()
|
||||
, m_dmi_entry_point(dmi_entry_point)
|
||||
, m_dmi_entry_point_length(blob_size)
|
||||
{
|
||||
|
@ -60,7 +59,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<SMBIOSExposedTable> SMBIOSExposedTable::create(Ph
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT SMBIOSExposedTable::SMBIOSExposedTable(PhysicalAddress smbios_structure_table, size_t smbios_structure_table_length)
|
||||
: BIOSSysFSComponent("DMI"sv)
|
||||
: BIOSSysFSComponent()
|
||||
, m_smbios_structure_table(smbios_structure_table)
|
||||
, m_smbios_structure_table_length(smbios_structure_table_length)
|
||||
{
|
||||
|
@ -127,7 +126,7 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer()
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT BIOSSysFSDirectory::BIOSSysFSDirectory(FirmwareSysFSDirectory& firmware_directory)
|
||||
: SysFSDirectory("bios", firmware_directory)
|
||||
: SysFSDirectory(firmware_directory)
|
||||
{
|
||||
auto entry_32bit = find_dmi_entry32bit_point();
|
||||
if (entry_32bit.has_value()) {
|
||||
|
|
|
@ -66,11 +66,12 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const = 0;
|
||||
explicit BIOSSysFSComponent(StringView name);
|
||||
BIOSSysFSComponent();
|
||||
};
|
||||
|
||||
class DMIEntryPointExposedBlob : public BIOSSysFSComponent {
|
||||
public:
|
||||
virtual StringView name() const override { return "smbios_entry_point"sv; }
|
||||
static NonnullRefPtr<DMIEntryPointExposedBlob> create(PhysicalAddress dmi_entry_point, size_t blob_size);
|
||||
|
||||
private:
|
||||
|
@ -82,6 +83,7 @@ private:
|
|||
|
||||
class SMBIOSExposedTable : public BIOSSysFSComponent {
|
||||
public:
|
||||
virtual StringView name() const override { return "DMI"sv; }
|
||||
static NonnullRefPtr<SMBIOSExposedTable> create(PhysicalAddress, size_t blob_size);
|
||||
|
||||
private:
|
||||
|
@ -94,6 +96,7 @@ private:
|
|||
|
||||
class BIOSSysFSDirectory : public SysFSDirectory {
|
||||
public:
|
||||
virtual StringView name() const override { return "bios"sv; }
|
||||
static ErrorOr<NonnullRefPtr<BIOSSysFSDirectory>> try_create(FirmwareSysFSDirectory&);
|
||||
|
||||
void create_components();
|
||||
|
|
|
@ -26,7 +26,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<PowerStateSwitchNode> PowerStateSwitchNode::must_
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT PowerStateSwitchNode::PowerStateSwitchNode(FirmwareSysFSDirectory&)
|
||||
: SysFSComponent("power_state")
|
||||
: SysFSComponent()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Kernel {
|
|||
|
||||
class PowerStateSwitchNode final : public SysFSComponent {
|
||||
public:
|
||||
virtual StringView name() const override { return "power_state"sv; }
|
||||
static NonnullRefPtr<PowerStateSwitchNode> must_create(FirmwareSysFSDirectory&);
|
||||
virtual mode_t permissions() const override;
|
||||
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
|
||||
|
|
|
@ -32,7 +32,7 @@ void FirmwareSysFSDirectory::create_components()
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT FirmwareSysFSDirectory::FirmwareSysFSDirectory()
|
||||
: SysFSDirectory("firmware", SysFSComponentRegistry::the().root_directory())
|
||||
: SysFSDirectory(SysFSComponentRegistry::the().root_directory())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Kernel {
|
|||
|
||||
class FirmwareSysFSDirectory : public SysFSDirectory {
|
||||
public:
|
||||
virtual StringView name() const override { return "firmware"sv; }
|
||||
static void initialize();
|
||||
|
||||
void create_components();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue