2021-06-22 21:24:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
2022-05-28 20:14:08 +00:00
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2021-06-22 21:24:25 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/JsonObjectSerializer.h>
|
2022-02-04 17:48:13 +00:00
|
|
|
#include <AK/Try.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <AK/UBSanitizer.h>
|
2022-05-16 12:42:49 +00:00
|
|
|
#include <Kernel/Arch/InterruptDisabler.h>
|
2022-05-30 07:04:37 +00:00
|
|
|
#include <Kernel/Arch/InterruptManagement.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
Kernel/PCI: Simplify the entire subsystem
A couple of things were changed:
1. Semantic changes - PCI segments are now called PCI domains, to better
match what they are really. It's also the name that Linux gave, and it
seems that Wikipedia also uses this name.
We also remove PCI::ChangeableAddress, because it was used in the past
but now it's no longer being used.
2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as
they made a bunch of unnecessary complexity. Instead, Windowed access is
removed entirely (this was tested, but never was benchmarked), so we are
left with IO access and memory access options. The memory access option
is essentially mapping the PCI bus (from the chosen PCI domain), to
virtual memory as-is. This means that unless needed, at any time, there
is only one PCI bus being mapped, and this is changed if access to
another PCI bus in the same PCI domain is needed. For now, we don't
support mapping of different PCI buses from different PCI domains at the
same time, because basically it's still a non-issue for most machines
out there.
2. OOM-safety is increased, especially when constructing the Access
object. It means that we pre-allocating any needed resources, and we try
to find PCI domains (if requested to initialize memory access) after we
attempt to construct the Access object, so it's possible to fail at this
point "gracefully".
3. All PCI API functions are now separated into a different header file,
which means only "clients" of the PCI subsystem API will need to include
that header file.
4. Functional changes - we only allow now to enumerate the bus after
a hardware scan. This means that the old method "enumerate_hardware"
is removed, so, when initializing an Access object, the initializing
function must call rescan on it to force it to find devices. This makes
it possible to fail rescan, and also to defer it after construction from
both OOM-safety terms and hotplug capabilities.
2021-09-07 09:08:38 +00:00
|
|
|
#include <Kernel/Bus/PCI/API.h>
|
2022-01-21 16:09:21 +00:00
|
|
|
#include <Kernel/Bus/PCI/Access.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/CommandLine.h>
|
2021-09-11 06:19:20 +00:00
|
|
|
#include <Kernel/Devices/DeviceManagement.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/Devices/HID/HIDManagement.h>
|
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
|
|
|
#include <Kernel/FileSystem/FileBackedFileSystem.h>
|
2021-09-07 11:39:11 +00:00
|
|
|
#include <Kernel/FileSystem/OpenFileDescription.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/Heap/kmalloc.h>
|
|
|
|
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
|
|
|
#include <Kernel/KBufferBuilder.h>
|
|
|
|
#include <Kernel/Net/LocalSocket.h>
|
|
|
|
#include <Kernel/Net/NetworkingManagement.h>
|
|
|
|
#include <Kernel/Net/Routing.h>
|
|
|
|
#include <Kernel/Net/TCPSocket.h>
|
|
|
|
#include <Kernel/Net/UDPSocket.h>
|
2021-08-10 17:51:28 +00:00
|
|
|
#include <Kernel/Process.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/ProcessExposed.h>
|
2022-01-29 12:08:37 +00:00
|
|
|
#include <Kernel/Scheduler.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
#include <Kernel/Sections.h>
|
2021-07-10 23:12:29 +00:00
|
|
|
#include <Kernel/TTY/TTY.h>
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class ProcFSAdapters final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSAdapters> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSAdapters();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(NetworkingManagement::the().try_for_each([&array](auto& adapter) -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("name"sv, adapter.name()));
|
|
|
|
TRY(obj.add("class_name"sv, adapter.class_name()));
|
2022-04-27 02:04:29 +00:00
|
|
|
auto mac_address = TRY(adapter.mac_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("mac_address"sv, mac_address->view()));
|
2021-06-22 21:24:25 +00:00
|
|
|
if (!adapter.ipv4_address().is_zero()) {
|
2022-04-27 02:04:29 +00:00
|
|
|
auto ipv4_address = TRY(adapter.ipv4_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("ipv4_address"sv, ipv4_address->view()));
|
2022-04-27 02:04:29 +00:00
|
|
|
auto ipv4_netmask = TRY(adapter.ipv4_netmask().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("ipv4_netmask"sv, ipv4_netmask->view()));
|
2022-02-15 17:35:32 +00:00
|
|
|
}
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("packets_in"sv, adapter.packets_in()));
|
|
|
|
TRY(obj.add("bytes_in"sv, adapter.bytes_in()));
|
|
|
|
TRY(obj.add("packets_out"sv, adapter.packets_out()));
|
|
|
|
TRY(obj.add("bytes_out"sv, adapter.bytes_out()));
|
|
|
|
TRY(obj.add("link_up"sv, adapter.link_up()));
|
|
|
|
TRY(obj.add("link_speed"sv, adapter.link_speed()));
|
|
|
|
TRY(obj.add("link_full_duplex"sv, adapter.link_full_duplex()));
|
|
|
|
TRY(obj.add("mtu"sv, adapter.mtu()));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSARP final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSARP> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSARP();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
2022-04-01 17:58:27 +00:00
|
|
|
TRY(arp_table().with([&](auto const& table) -> ErrorOr<void> {
|
2022-02-24 18:08:48 +00:00
|
|
|
for (auto& it : table) {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-04-27 02:04:29 +00:00
|
|
|
auto mac_address = TRY(it.value.to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("mac_address"sv, mac_address->view()));
|
2022-04-27 02:04:29 +00:00
|
|
|
auto ip_address = TRY(it.key.to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("ip_address"sv, ip_address->view()));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-12 19:16:44 +00:00
|
|
|
class ProcFSRoute final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSRoute> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSRoute();
|
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
|
|
|
{
|
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(routing_table().with([&](auto const& table) -> ErrorOr<void> {
|
|
|
|
for (auto& it : table) {
|
|
|
|
auto obj = TRY(array.add_object());
|
|
|
|
auto destination = TRY(it.destination.to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("destination"sv, destination->view()));
|
2022-03-12 19:16:44 +00:00
|
|
|
auto gateway = TRY(it.gateway.to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("gateway"sv, gateway->view()));
|
2022-03-12 19:16:44 +00:00
|
|
|
auto netmask = TRY(it.netmask.to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("genmask"sv, netmask->view()));
|
|
|
|
TRY(obj.add("flags"sv, it.flags));
|
|
|
|
TRY(obj.add("interface"sv, it.adapter->name()));
|
2022-03-12 19:16:44 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-22 21:24:25 +00:00
|
|
|
class ProcFSTCP final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSTCP> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSTCP();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(TCPSocket::try_for_each([&array](auto& socket) -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-04-27 02:04:29 +00:00
|
|
|
auto local_address = TRY(socket.local_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("local_address"sv, local_address->view()));
|
|
|
|
TRY(obj.add("local_port"sv, socket.local_port()));
|
2022-04-27 02:04:29 +00:00
|
|
|
auto peer_address = TRY(socket.peer_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("peer_address"sv, peer_address->view()));
|
|
|
|
TRY(obj.add("peer_port"sv, socket.peer_port()));
|
|
|
|
TRY(obj.add("state"sv, TCPSocket::to_string(socket.state())));
|
|
|
|
TRY(obj.add("ack_number"sv, socket.ack_number()));
|
|
|
|
TRY(obj.add("sequence_number"sv, socket.sequence_number()));
|
|
|
|
TRY(obj.add("packets_in"sv, socket.packets_in()));
|
|
|
|
TRY(obj.add("bytes_in"sv, socket.bytes_in()));
|
|
|
|
TRY(obj.add("packets_out"sv, socket.packets_out()));
|
|
|
|
TRY(obj.add("bytes_out"sv, socket.bytes_out()));
|
2021-08-19 19:45:07 +00:00
|
|
|
if (Process::current().is_superuser() || Process::current().uid() == socket.origin_uid()) {
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("origin_pid"sv, socket.origin_pid().value()));
|
|
|
|
TRY(obj.add("origin_uid"sv, socket.origin_uid().value()));
|
|
|
|
TRY(obj.add("origin_gid"sv, socket.origin_gid().value()));
|
2021-07-13 00:48:31 +00:00
|
|
|
}
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSLocalNet final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSLocalNet> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSLocalNet();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(LocalSocket::try_for_each([&array](auto& socket) -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("path"sv, socket.socket_path()));
|
|
|
|
TRY(obj.add("origin_pid"sv, socket.origin_pid().value()));
|
|
|
|
TRY(obj.add("origin_uid"sv, socket.origin_uid().value()));
|
|
|
|
TRY(obj.add("origin_gid"sv, socket.origin_gid().value()));
|
|
|
|
TRY(obj.add("acceptor_pid"sv, socket.acceptor_pid().value()));
|
|
|
|
TRY(obj.add("acceptor_uid"sv, socket.acceptor_uid().value()));
|
|
|
|
TRY(obj.add("acceptor_gid"sv, socket.acceptor_gid().value()));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSUDP final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSUDP> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSUDP();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(UDPSocket::try_for_each([&array](auto& socket) -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-04-27 02:04:29 +00:00
|
|
|
auto local_address = TRY(socket.local_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("local_address"sv, local_address->view()));
|
|
|
|
TRY(obj.add("local_port"sv, socket.local_port()));
|
2022-04-27 02:04:29 +00:00
|
|
|
auto peer_address = TRY(socket.peer_address().to_string());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("peer_address"sv, peer_address->view()));
|
|
|
|
TRY(obj.add("peer_port"sv, socket.peer_port()));
|
2021-08-19 19:45:07 +00:00
|
|
|
if (Process::current().is_superuser() || Process::current().uid() == socket.origin_uid()) {
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("origin_pid"sv, socket.origin_pid().value()));
|
|
|
|
TRY(obj.add("origin_uid"sv, socket.origin_uid().value()));
|
|
|
|
TRY(obj.add("origin_gid"sv, socket.origin_gid().value()));
|
2021-07-13 00:48:31 +00:00
|
|
|
}
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
class ProcFSNetworkDirectory : public ProcFSExposedDirectory {
|
2021-06-22 21:24:25 +00:00
|
|
|
public:
|
2022-04-01 17:58:27 +00:00
|
|
|
static NonnullRefPtr<ProcFSNetworkDirectory> must_create(ProcFSRootDirectory const& parent_directory);
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-01 17:58:27 +00:00
|
|
|
ProcFSNetworkDirectory(ProcFSRootDirectory const& parent_directory);
|
2021-06-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
class ProcFSSystemDirectory : public ProcFSExposedDirectory {
|
2021-06-22 21:24:25 +00:00
|
|
|
public:
|
2022-04-01 17:58:27 +00:00
|
|
|
static NonnullRefPtr<ProcFSSystemDirectory> must_create(ProcFSRootDirectory const& parent_directory);
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-01 17:58:27 +00:00
|
|
|
ProcFSSystemDirectory(ProcFSRootDirectory const& parent_directory);
|
2021-06-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSAdapters> ProcFSAdapters::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSAdapters).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSARP> ProcFSARP::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSARP).release_nonnull();
|
|
|
|
}
|
2022-03-12 19:16:44 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRoute> ProcFSRoute::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSRoute).release_nonnull();
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSTCP> ProcFSTCP::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSTCP).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSLocalNet> ProcFSLocalNet::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSLocalNet).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSUDP> ProcFSUDP::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSUDP).release_nonnull();
|
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSNetworkDirectory> ProcFSNetworkDirectory::must_create(ProcFSRootDirectory const& parent_directory)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-07-17 21:15:52 +00:00
|
|
|
auto directory = adopt_ref(*new (nothrow) ProcFSNetworkDirectory(parent_directory));
|
|
|
|
directory->m_components.append(ProcFSAdapters::must_create());
|
|
|
|
directory->m_components.append(ProcFSARP::must_create());
|
2022-03-12 19:16:44 +00:00
|
|
|
directory->m_components.append(ProcFSRoute::must_create());
|
2021-07-17 21:15:52 +00:00
|
|
|
directory->m_components.append(ProcFSTCP::must_create());
|
|
|
|
directory->m_components.append(ProcFSLocalNet::must_create());
|
|
|
|
directory->m_components.append(ProcFSUDP::must_create());
|
|
|
|
return directory;
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT ProcFSAdapters::ProcFSAdapters()
|
|
|
|
: ProcFSGlobalInformation("adapters"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSARP::ProcFSARP()
|
|
|
|
: ProcFSGlobalInformation("arp"sv)
|
|
|
|
{
|
|
|
|
}
|
2022-03-12 19:16:44 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSRoute::ProcFSRoute()
|
|
|
|
: ProcFSGlobalInformation("route"sv)
|
|
|
|
{
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSTCP::ProcFSTCP()
|
|
|
|
: ProcFSGlobalInformation("tcp"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSLocalNet::ProcFSLocalNet()
|
|
|
|
: ProcFSGlobalInformation("local"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSUDP::ProcFSUDP()
|
|
|
|
: ProcFSGlobalInformation("udp"sv)
|
|
|
|
{
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSNetworkDirectory::ProcFSNetworkDirectory(ProcFSRootDirectory const& parent_directory)
|
2021-07-17 21:15:52 +00:00
|
|
|
: ProcFSExposedDirectory("net"sv, parent_directory)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProcFSDumpKmallocStacks : public ProcFSSystemBoolean {
|
|
|
|
public:
|
2022-04-01 17:58:27 +00:00
|
|
|
static NonnullRefPtr<ProcFSDumpKmallocStacks> must_create(ProcFSSystemDirectory const&);
|
2021-06-22 21:24:25 +00:00
|
|
|
virtual bool value() const override
|
|
|
|
{
|
2021-07-17 23:13:34 +00:00
|
|
|
MutexLocker locker(m_lock);
|
2021-06-22 21:24:25 +00:00
|
|
|
return g_dump_kmalloc_stacks;
|
|
|
|
}
|
|
|
|
virtual void set_value(bool new_value) override
|
|
|
|
{
|
2021-07-17 23:13:34 +00:00
|
|
|
MutexLocker locker(m_lock);
|
2021-06-22 21:24:25 +00:00
|
|
|
g_dump_kmalloc_stacks = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSDumpKmallocStacks();
|
2021-07-17 19:09:51 +00:00
|
|
|
mutable Mutex m_lock;
|
2021-06-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSUBSanDeadly : public ProcFSSystemBoolean {
|
|
|
|
public:
|
2022-04-01 17:58:27 +00:00
|
|
|
static NonnullRefPtr<ProcFSUBSanDeadly> must_create(ProcFSSystemDirectory const&);
|
2022-02-03 15:10:10 +00:00
|
|
|
|
|
|
|
virtual bool value() const override { return AK::UBSanitizer::g_ubsan_is_deadly; }
|
|
|
|
virtual void set_value(bool new_value) override { AK::UBSanitizer::g_ubsan_is_deadly = new_value; }
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSUBSanDeadly();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSCapsLockRemap : public ProcFSSystemBoolean {
|
|
|
|
public:
|
2022-04-01 17:58:27 +00:00
|
|
|
static NonnullRefPtr<ProcFSCapsLockRemap> must_create(ProcFSSystemDirectory const&);
|
2021-06-22 21:24:25 +00:00
|
|
|
virtual bool value() const override
|
|
|
|
{
|
2021-07-17 23:13:34 +00:00
|
|
|
MutexLocker locker(m_lock);
|
2021-06-22 21:24:25 +00:00
|
|
|
return g_caps_lock_remapped_to_ctrl.load();
|
|
|
|
}
|
|
|
|
virtual void set_value(bool new_value) override
|
|
|
|
{
|
2021-07-17 23:13:34 +00:00
|
|
|
MutexLocker locker(m_lock);
|
2021-06-22 21:24:25 +00:00
|
|
|
g_caps_lock_remapped_to_ctrl.exchange(new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSCapsLockRemap();
|
2021-07-17 19:09:51 +00:00
|
|
|
mutable Mutex m_lock;
|
2021-06-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSDumpKmallocStacks> ProcFSDumpKmallocStacks::must_create(ProcFSSystemDirectory const&)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSDumpKmallocStacks).release_nonnull();
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSUBSanDeadly> ProcFSUBSanDeadly::must_create(ProcFSSystemDirectory const&)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSUBSanDeadly).release_nonnull();
|
|
|
|
}
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSCapsLockRemap> ProcFSCapsLockRemap::must_create(ProcFSSystemDirectory const&)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSCapsLockRemap).release_nonnull();
|
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT ProcFSDumpKmallocStacks::ProcFSDumpKmallocStacks()
|
|
|
|
: ProcFSSystemBoolean("kmalloc_stacks"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT ProcFSUBSanDeadly::ProcFSUBSanDeadly()
|
|
|
|
: ProcFSSystemBoolean("ubsan_is_deadly"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT ProcFSCapsLockRemap::ProcFSCapsLockRemap()
|
|
|
|
: ProcFSSystemBoolean("caps_lock_to_ctrl"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
class ProcFSSelfProcessDirectory final : public ProcFSExposedLink {
|
2021-06-22 21:24:25 +00:00
|
|
|
public:
|
2021-07-10 23:33:40 +00:00
|
|
|
static NonnullRefPtr<ProcFSSelfProcessDirectory> must_create();
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
private:
|
2021-07-10 23:33:40 +00:00
|
|
|
ProcFSSelfProcessDirectory();
|
2021-06-22 21:24:25 +00:00
|
|
|
virtual bool acquire_link(KBufferBuilder& builder) override
|
|
|
|
{
|
2021-12-29 00:03:09 +00:00
|
|
|
return !builder.appendff("{}", Process::current().pid().value()).is_error();
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSDiskUsage final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSDiskUsage> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSDiskUsage();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(VirtualFileSystem::the().for_each_mount([&array](auto& mount) -> ErrorOr<void> {
|
2021-06-22 21:24:25 +00:00
|
|
|
auto& fs = mount.guest_fs();
|
2022-02-24 18:08:48 +00:00
|
|
|
auto fs_object = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(fs_object.add("class_name"sv, fs.class_name()));
|
|
|
|
TRY(fs_object.add("total_block_count"sv, fs.total_block_count()));
|
|
|
|
TRY(fs_object.add("free_block_count"sv, fs.free_block_count()));
|
|
|
|
TRY(fs_object.add("total_inode_count"sv, fs.total_inode_count()));
|
|
|
|
TRY(fs_object.add("free_inode_count"sv, fs.free_inode_count()));
|
2022-02-24 18:08:48 +00:00
|
|
|
auto mount_point = TRY(mount.absolute_path());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(fs_object.add("mount_point"sv, mount_point->view()));
|
|
|
|
TRY(fs_object.add("block_size"sv, static_cast<u64>(fs.block_size())));
|
|
|
|
TRY(fs_object.add("readonly"sv, fs.is_readonly()));
|
|
|
|
TRY(fs_object.add("mount_flags"sv, mount.flags()));
|
2021-06-22 21:24:25 +00:00
|
|
|
|
2021-10-29 22:45:23 +00:00
|
|
|
if (fs.is_file_backed()) {
|
2022-02-24 18:08:48 +00:00
|
|
|
auto pseudo_path = TRY(static_cast<const FileBackedFileSystem&>(fs).file_description().pseudo_path());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(fs_object.add("source"sv, pseudo_path->view()));
|
2021-10-29 22:45:23 +00:00
|
|
|
} else {
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(fs_object.add("source"sv, "none"));
|
2021-10-29 22:45:23 +00:00
|
|
|
}
|
2021-10-29 21:28:25 +00:00
|
|
|
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(fs_object.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSMemoryStatus final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSMemoryStatus> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSMemoryStatus();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
|
|
|
kmalloc_stats stats;
|
|
|
|
get_kmalloc_stats(stats);
|
|
|
|
|
2021-08-06 11:49:36 +00:00
|
|
|
auto system_memory = MM.get_system_memory_info();
|
2021-06-22 21:24:25 +00:00
|
|
|
|
2022-02-24 18:08:48 +00:00
|
|
|
auto json = TRY(JsonObjectSerializer<>::try_create(builder));
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(json.add("kmalloc_allocated"sv, stats.bytes_allocated));
|
|
|
|
TRY(json.add("kmalloc_available"sv, stats.bytes_free));
|
2022-07-14 12:27:22 +00:00
|
|
|
TRY(json.add("physical_allocated"sv, system_memory.physical_pages_used));
|
|
|
|
TRY(json.add("physical_available"sv, system_memory.physical_pages - system_memory.physical_pages_used));
|
|
|
|
TRY(json.add("physical_committed"sv, system_memory.physical_pages_committed));
|
|
|
|
TRY(json.add("physical_uncommitted"sv, system_memory.physical_pages_uncommitted));
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(json.add("kmalloc_call_count"sv, stats.kmalloc_call_count));
|
|
|
|
TRY(json.add("kfree_call_count"sv, stats.kfree_call_count));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(json.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-07 19:02:18 +00:00
|
|
|
class ProcFSSystemStatistics final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSSystemStatistics> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSSystemStatistics();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-10-07 19:02:18 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto json = TRY(JsonObjectSerializer<>::try_create(builder));
|
2021-10-07 19:02:18 +00:00
|
|
|
auto total_time_scheduled = Scheduler::get_total_time_scheduled();
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(json.add("total_time"sv, total_time_scheduled.total));
|
|
|
|
TRY(json.add("kernel_time"sv, total_time_scheduled.total_kernel));
|
|
|
|
TRY(json.add("user_time"sv, total_time_scheduled.total - total_time_scheduled.total_kernel));
|
2021-10-07 19:02:18 +00:00
|
|
|
u64 idle_time = 0;
|
|
|
|
Processor::for_each([&](Processor& processor) {
|
|
|
|
idle_time += processor.time_spent_idle();
|
|
|
|
});
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(json.add("idle_time"sv, idle_time));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(json.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-10-07 19:02:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-22 21:24:25 +00:00
|
|
|
class ProcFSOverallProcesses final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSOverallProcesses> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSOverallProcesses();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto json = TRY(JsonObjectSerializer<>::try_create(builder));
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
// Keep this in sync with CProcessStatistics.
|
2022-04-01 17:58:27 +00:00
|
|
|
auto build_process = [&](JsonArraySerializer<KBufferBuilder>& array, Process const& process) -> ErrorOr<void> {
|
2022-02-24 18:08:48 +00:00
|
|
|
auto process_object = TRY(array.add_object());
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
if (process.is_user_process()) {
|
|
|
|
StringBuilder pledge_builder;
|
|
|
|
|
2022-01-25 13:19:14 +00:00
|
|
|
#define __ENUMERATE_PLEDGE_PROMISE(promise) \
|
|
|
|
if (process.has_promised(Pledge::promise)) \
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(pledge_builder.try_append(#promise " "sv));
|
2021-06-22 21:24:25 +00:00
|
|
|
ENUMERATE_PLEDGE_PROMISES
|
|
|
|
#undef __ENUMERATE_PLEDGE_PROMISE
|
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("pledge"sv, pledge_builder.string_view()));
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
switch (process.veil_state()) {
|
|
|
|
case VeilState::None:
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("veil"sv, "None"));
|
2021-06-22 21:24:25 +00:00
|
|
|
break;
|
|
|
|
case VeilState::Dropped:
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("veil"sv, "Dropped"));
|
2021-06-22 21:24:25 +00:00
|
|
|
break;
|
|
|
|
case VeilState::Locked:
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("veil"sv, "Locked"));
|
2021-06-22 21:24:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("pledge"sv, ""sv));
|
|
|
|
TRY(process_object.add("veil"sv, ""sv));
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("pid"sv, process.pid().value()));
|
|
|
|
TRY(process_object.add("pgid"sv, process.tty() ? process.tty()->pgid().value() : 0));
|
|
|
|
TRY(process_object.add("pgp"sv, process.pgid().value()));
|
|
|
|
TRY(process_object.add("sid"sv, process.sid().value()));
|
|
|
|
TRY(process_object.add("uid"sv, process.uid().value()));
|
|
|
|
TRY(process_object.add("gid"sv, process.gid().value()));
|
|
|
|
TRY(process_object.add("ppid"sv, process.ppid().value()));
|
2022-03-26 06:06:30 +00:00
|
|
|
if (process.tty()) {
|
|
|
|
auto tty_pseudo_name = TRY(process.tty()->pseudo_name());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("tty"sv, tty_pseudo_name->view()));
|
2022-03-26 06:06:30 +00:00
|
|
|
} else {
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("tty"sv, ""));
|
2022-03-26 06:06:30 +00:00
|
|
|
}
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(process_object.add("nfds"sv, process.fds().with_shared([](auto& fds) { return fds.open_count(); })));
|
|
|
|
TRY(process_object.add("name"sv, process.name()));
|
|
|
|
TRY(process_object.add("executable"sv, process.executable() ? TRY(process.executable()->try_serialize_absolute_path())->view() : ""sv));
|
|
|
|
TRY(process_object.add("amount_virtual"sv, process.address_space().amount_virtual()));
|
|
|
|
TRY(process_object.add("amount_resident"sv, process.address_space().amount_resident()));
|
|
|
|
TRY(process_object.add("amount_dirty_private"sv, process.address_space().amount_dirty_private()));
|
|
|
|
TRY(process_object.add("amount_clean_inode"sv, TRY(process.address_space().amount_clean_inode())));
|
|
|
|
TRY(process_object.add("amount_shared"sv, process.address_space().amount_shared()));
|
|
|
|
TRY(process_object.add("amount_purgeable_volatile"sv, process.address_space().amount_purgeable_volatile()));
|
|
|
|
TRY(process_object.add("amount_purgeable_nonvolatile"sv, process.address_space().amount_purgeable_nonvolatile()));
|
|
|
|
TRY(process_object.add("dumpable"sv, process.is_dumpable()));
|
|
|
|
TRY(process_object.add("kernel"sv, process.is_kernel_process()));
|
|
|
|
auto thread_array = TRY(process_object.add_array("threads"sv));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(process.try_for_each_thread([&](const Thread& thread) -> ErrorOr<void> {
|
2021-08-21 23:49:22 +00:00
|
|
|
SpinlockLocker locker(thread.get_lock());
|
2022-02-24 18:08:48 +00:00
|
|
|
auto thread_object = TRY(thread_array.add_object());
|
2021-06-22 21:24:25 +00:00
|
|
|
#if LOCK_DEBUG
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(thread_object.add("lock_count"sv, thread.lock_count()));
|
2021-06-22 21:24:25 +00:00
|
|
|
#endif
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(thread_object.add("tid"sv, thread.tid().value()));
|
|
|
|
TRY(thread_object.add("name"sv, thread.name()));
|
|
|
|
TRY(thread_object.add("times_scheduled"sv, thread.times_scheduled()));
|
|
|
|
TRY(thread_object.add("time_user"sv, thread.time_in_user()));
|
|
|
|
TRY(thread_object.add("time_kernel"sv, thread.time_in_kernel()));
|
|
|
|
TRY(thread_object.add("state"sv, thread.state_string()));
|
|
|
|
TRY(thread_object.add("cpu"sv, thread.cpu()));
|
|
|
|
TRY(thread_object.add("priority"sv, thread.priority()));
|
|
|
|
TRY(thread_object.add("syscall_count"sv, thread.syscall_count()));
|
|
|
|
TRY(thread_object.add("inode_faults"sv, thread.inode_faults()));
|
|
|
|
TRY(thread_object.add("zero_faults"sv, thread.zero_faults()));
|
|
|
|
TRY(thread_object.add("cow_faults"sv, thread.cow_faults()));
|
|
|
|
TRY(thread_object.add("file_read_bytes"sv, thread.file_read_bytes()));
|
|
|
|
TRY(thread_object.add("file_write_bytes"sv, thread.file_write_bytes()));
|
|
|
|
TRY(thread_object.add("unix_socket_read_bytes"sv, thread.unix_socket_read_bytes()));
|
|
|
|
TRY(thread_object.add("unix_socket_write_bytes"sv, thread.unix_socket_write_bytes()));
|
|
|
|
TRY(thread_object.add("ipv4_socket_read_bytes"sv, thread.ipv4_socket_read_bytes()));
|
|
|
|
TRY(thread_object.add("ipv4_socket_write_bytes"sv, thread.ipv4_socket_write_bytes()));
|
2022-02-24 18:08:48 +00:00
|
|
|
|
|
|
|
TRY(thread_object.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(thread_array.finish());
|
|
|
|
TRY(process_object.finish());
|
2022-01-11 19:29:25 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
2021-07-14 18:05:59 +00:00
|
|
|
{
|
2022-07-14 09:42:05 +00:00
|
|
|
auto array = TRY(json.add_array("processes"sv));
|
|
|
|
TRY(build_process(array, *Scheduler::colonel()));
|
|
|
|
TRY(Process::all_instances().with([&](auto& processes) -> ErrorOr<void> {
|
|
|
|
for (auto& process : processes)
|
|
|
|
TRY(build_process(array, process));
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-07-14 18:05:59 +00:00
|
|
|
}
|
2022-07-14 09:42:05 +00:00
|
|
|
|
|
|
|
auto total_time_scheduled = Scheduler::get_total_time_scheduled();
|
|
|
|
TRY(json.add("total_time"sv, total_time_scheduled.total));
|
|
|
|
TRY(json.add("total_time_kernel"sv, total_time_scheduled.total_kernel));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(json.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSCPUInformation final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSCPUInformation> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSCPUInformation();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(Processor::try_for_each(
|
|
|
|
[&](Processor& proc) -> ErrorOr<void> {
|
2021-06-22 21:24:25 +00:00
|
|
|
auto& info = proc.info();
|
2022-02-24 18:08:48 +00:00
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("processor"sv, proc.id()));
|
|
|
|
TRY(obj.add("vendor_id"sv, info.vendor_id_string()));
|
|
|
|
TRY(obj.add("family"sv, info.display_family()));
|
2022-04-03 16:15:18 +00:00
|
|
|
if (!info.hypervisor_vendor_id_string().is_null())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("hypervisor_vendor_id"sv, info.hypervisor_vendor_id_string()));
|
2021-06-29 19:46:42 +00:00
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
auto features_array = TRY(obj.add_array("features"sv));
|
2022-01-10 08:52:21 +00:00
|
|
|
auto keep_empty = false;
|
2022-02-24 18:08:48 +00:00
|
|
|
|
|
|
|
ErrorOr<void> result; // FIXME: Make this nicer
|
2022-04-03 15:38:45 +00:00
|
|
|
info.features_string().for_each_split_view(' ', keep_empty, [&](StringView feature) {
|
2022-02-24 18:08:48 +00:00
|
|
|
if (result.is_error())
|
|
|
|
return;
|
|
|
|
result = features_array.add(feature);
|
2022-01-10 08:52:21 +00:00
|
|
|
});
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(result);
|
|
|
|
|
|
|
|
TRY(features_array.finish());
|
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("model"sv, info.display_model()));
|
|
|
|
TRY(obj.add("stepping"sv, info.stepping()));
|
|
|
|
TRY(obj.add("type"sv, info.type()));
|
|
|
|
TRY(obj.add("brand"sv, info.brand_string()));
|
2022-02-24 18:08:48 +00:00
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
auto caches = TRY(obj.add_object("caches"sv));
|
2022-05-28 20:14:08 +00:00
|
|
|
|
|
|
|
auto add_cache_info = [&](StringView name, ProcessorInfo::Cache const& cache) -> ErrorOr<void> {
|
|
|
|
auto cache_object = TRY(caches.add_object(name));
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(cache_object.add("size"sv, cache.size));
|
|
|
|
TRY(cache_object.add("line_size"sv, cache.line_size));
|
2022-05-28 20:14:08 +00:00
|
|
|
TRY(cache_object.finish());
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (info.l1_data_cache().has_value())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(add_cache_info("l1_data"sv, *info.l1_data_cache()));
|
2022-05-28 20:14:08 +00:00
|
|
|
if (info.l1_data_cache().has_value())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(add_cache_info("l1_instruction"sv, *info.l1_instruction_cache()));
|
2022-05-28 20:14:08 +00:00
|
|
|
if (info.l1_data_cache().has_value())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(add_cache_info("l2"sv, *info.l2_cache()));
|
2022-05-28 20:14:08 +00:00
|
|
|
if (info.l1_data_cache().has_value())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(add_cache_info("l3"sv, *info.l3_cache()));
|
2022-05-28 20:14:08 +00:00
|
|
|
|
|
|
|
TRY(caches.finish());
|
|
|
|
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSDmesg final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSDmesg> must_create();
|
|
|
|
|
2021-07-28 16:59:53 +00:00
|
|
|
virtual mode_t required_mode() const override { return 0400; }
|
|
|
|
|
2021-06-22 21:24:25 +00:00
|
|
|
private:
|
|
|
|
ProcFSDmesg();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-09-16 19:23:25 +00:00
|
|
|
VERIFY(DeviceManagement::the().is_console_device_attached());
|
2021-06-22 21:24:25 +00:00
|
|
|
InterruptDisabler disabler;
|
2021-09-16 19:23:25 +00:00
|
|
|
for (char ch : DeviceManagement::the().console_device().logbuffer()) {
|
2021-09-06 16:41:16 +00:00
|
|
|
TRY(builder.append(ch));
|
2021-09-06 16:24:13 +00:00
|
|
|
}
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSInterrupts final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSInterrupts> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSInterrupts();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
ErrorOr<void> result; // FIXME: Make this nicer
|
|
|
|
InterruptManagement::the().enumerate_interrupt_handlers([&array, &result](GenericInterruptHandler& handler) {
|
|
|
|
if (result.is_error())
|
|
|
|
return;
|
|
|
|
result = ([&]() -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("purpose"sv, handler.purpose()));
|
|
|
|
TRY(obj.add("interrupt_line"sv, handler.interrupt_number()));
|
|
|
|
TRY(obj.add("controller"sv, handler.controller()));
|
|
|
|
TRY(obj.add("cpu_handler"sv, 0)); // FIXME: Determine the responsible CPU for each interrupt handler.
|
|
|
|
TRY(obj.add("device_sharing"sv, (unsigned)handler.sharing_devices_count()));
|
|
|
|
TRY(obj.add("call_count"sv, (unsigned)handler.get_invoking_count()));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
})();
|
2021-06-22 21:24:25 +00:00
|
|
|
});
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(result);
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSKeymap final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSKeymap> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSKeymap();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto json = TRY(JsonObjectSerializer<>::try_create(builder));
|
2022-03-07 15:34:14 +00:00
|
|
|
TRY(HIDManagement::the().keymap_data().with([&](auto const& keymap_data) {
|
2022-07-11 17:32:29 +00:00
|
|
|
return json.add("keymap"sv, keymap_data.character_map_name->view());
|
2022-03-07 15:34:14 +00:00
|
|
|
}));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(json.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// FIXME: Remove this after we enumerate the SysFS from lspci and SystemMonitor
|
|
|
|
class ProcFSPCI final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSPCI> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSPCI();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
ErrorOr<void> result; // FIXME: Make this nicer
|
2022-02-04 17:48:13 +00:00
|
|
|
TRY(PCI::enumerate([&array, &result](PCI::DeviceIdentifier const& device_identifier) {
|
2022-02-24 18:08:48 +00:00
|
|
|
if (result.is_error())
|
|
|
|
return;
|
|
|
|
result = ([&]() -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("domain"sv, device_identifier.address().domain()));
|
|
|
|
TRY(obj.add("bus"sv, device_identifier.address().bus()));
|
|
|
|
TRY(obj.add("device"sv, device_identifier.address().device()));
|
|
|
|
TRY(obj.add("function"sv, device_identifier.address().function()));
|
|
|
|
TRY(obj.add("vendor_id"sv, device_identifier.hardware_id().vendor_id));
|
|
|
|
TRY(obj.add("device_id"sv, device_identifier.hardware_id().device_id));
|
|
|
|
TRY(obj.add("revision_id"sv, device_identifier.revision_id().value()));
|
|
|
|
TRY(obj.add("subclass"sv, device_identifier.subclass_code().value()));
|
|
|
|
TRY(obj.add("class"sv, device_identifier.class_code().value()));
|
|
|
|
TRY(obj.add("subsystem_id"sv, device_identifier.subsystem_id().value()));
|
|
|
|
TRY(obj.add("subsystem_vendor_id"sv, device_identifier.subsystem_vendor_id().value()));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
})();
|
2022-02-04 17:48:13 +00:00
|
|
|
}));
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(result);
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSDevices final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSDevices> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSDevices();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2022-02-24 18:08:48 +00:00
|
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
|
|
TRY(DeviceManagement::the().try_for_each([&array](auto& device) -> ErrorOr<void> {
|
|
|
|
auto obj = TRY(array.add_object());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("major"sv, device.major().value()));
|
|
|
|
TRY(obj.add("minor"sv, device.minor().value()));
|
|
|
|
TRY(obj.add("class_name"sv, device.class_name()));
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
if (device.is_block_device())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("type"sv, "block"));
|
2021-06-22 21:24:25 +00:00
|
|
|
else if (device.is_character_device())
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(obj.add("type"sv, "character"));
|
2021-06-22 21:24:25 +00:00
|
|
|
else
|
|
|
|
VERIFY_NOT_REACHED();
|
2022-02-24 18:08:48 +00:00
|
|
|
TRY(obj.finish());
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
TRY(array.finish());
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSUptime final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSUptime> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSUptime();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-09-06 16:41:16 +00:00
|
|
|
return builder.appendff("{}\n", TimeManagement::the().uptime_ms() / 1000);
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ProcFSCommandLine final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSCommandLine> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSCommandLine();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-09-06 16:41:16 +00:00
|
|
|
TRY(builder.append(kernel_command_line().string()));
|
|
|
|
TRY(builder.append('\n'));
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
2021-10-23 16:26:50 +00:00
|
|
|
class ProcFSSystemMode final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSSystemMode> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSSystemMode();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-10-23 16:26:50 +00:00
|
|
|
{
|
|
|
|
TRY(builder.append(kernel_command_line().system_mode()));
|
|
|
|
TRY(builder.append('\n'));
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-10-23 16:26:50 +00:00
|
|
|
}
|
|
|
|
};
|
2021-07-28 16:59:53 +00:00
|
|
|
|
2021-06-22 21:24:25 +00:00
|
|
|
class ProcFSProfile final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSProfile> must_create();
|
|
|
|
|
2021-07-28 16:59:53 +00:00
|
|
|
virtual mode_t required_mode() const override { return 0400; }
|
|
|
|
|
2021-06-22 21:24:25 +00:00
|
|
|
private:
|
|
|
|
ProcFSProfile();
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
if (!g_global_perf_events)
|
2021-09-06 16:41:16 +00:00
|
|
|
return ENOENT;
|
2021-09-07 16:21:37 +00:00
|
|
|
TRY(g_global_perf_events->to_json(builder));
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-22 12:18:36 +00:00
|
|
|
class ProcFSKernelBase final : public ProcFSGlobalInformation {
|
|
|
|
public:
|
|
|
|
static NonnullRefPtr<ProcFSKernelBase> must_create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSKernelBase();
|
|
|
|
|
|
|
|
virtual mode_t required_mode() const override { return 0400; }
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
2021-07-22 12:18:36 +00:00
|
|
|
{
|
2021-08-19 19:45:07 +00:00
|
|
|
if (!Process::current().is_superuser())
|
2021-09-06 16:41:16 +00:00
|
|
|
return EPERM;
|
2021-12-30 12:43:45 +00:00
|
|
|
return builder.appendff("{}", kernel_load_base);
|
2021-07-22 12:18:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSelfProcessDirectory> ProcFSSelfProcessDirectory::must_create()
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-07-10 23:33:40 +00:00
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSSelfProcessDirectory()).release_nonnull();
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSDiskUsage> ProcFSDiskUsage::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSDiskUsage).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSMemoryStatus> ProcFSMemoryStatus::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSMemoryStatus).release_nonnull();
|
|
|
|
}
|
2021-10-07 19:02:18 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemStatistics> ProcFSSystemStatistics::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSSystemStatistics).release_nonnull();
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSOverallProcesses> ProcFSOverallProcesses::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSOverallProcesses).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSCPUInformation> ProcFSCPUInformation::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSCPUInformation).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSDmesg> ProcFSDmesg::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSDmesg).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSInterrupts> ProcFSInterrupts::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSInterrupts).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSKeymap> ProcFSKeymap::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSKeymap).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSPCI> ProcFSPCI::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSPCI).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSDevices> ProcFSDevices::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSDevices).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSUptime> ProcFSUptime::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSUptime).release_nonnull();
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSCommandLine> ProcFSCommandLine::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSCommandLine).release_nonnull();
|
|
|
|
}
|
2021-10-23 16:26:50 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemMode> ProcFSSystemMode::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSSystemMode).release_nonnull();
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSProfile> ProcFSProfile::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSProfile).release_nonnull();
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:18:36 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSKernelBase> ProcFSKernelBase::must_create()
|
|
|
|
{
|
|
|
|
return adopt_ref_if_nonnull(new (nothrow) ProcFSKernelBase).release_nonnull();
|
|
|
|
}
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSSelfProcessDirectory::ProcFSSelfProcessDirectory()
|
2021-06-22 21:24:25 +00:00
|
|
|
: ProcFSExposedLink("self"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSDiskUsage::ProcFSDiskUsage()
|
|
|
|
: ProcFSGlobalInformation("df"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSMemoryStatus::ProcFSMemoryStatus()
|
|
|
|
: ProcFSGlobalInformation("memstat"sv)
|
|
|
|
{
|
|
|
|
}
|
2021-10-07 19:02:18 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSSystemStatistics::ProcFSSystemStatistics()
|
|
|
|
: ProcFSGlobalInformation("stat"sv)
|
|
|
|
{
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSOverallProcesses::ProcFSOverallProcesses()
|
|
|
|
: ProcFSGlobalInformation("all"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSCPUInformation::ProcFSCPUInformation()
|
|
|
|
: ProcFSGlobalInformation("cpuinfo"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSDmesg::ProcFSDmesg()
|
|
|
|
: ProcFSGlobalInformation("dmesg"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSInterrupts::ProcFSInterrupts()
|
|
|
|
: ProcFSGlobalInformation("interrupts"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSKeymap::ProcFSKeymap()
|
|
|
|
: ProcFSGlobalInformation("keymap"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSPCI::ProcFSPCI()
|
|
|
|
: ProcFSGlobalInformation("pci"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSDevices::ProcFSDevices()
|
|
|
|
: ProcFSGlobalInformation("devices"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSUptime::ProcFSUptime()
|
|
|
|
: ProcFSGlobalInformation("uptime"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UNMAP_AFTER_INIT ProcFSCommandLine::ProcFSCommandLine()
|
|
|
|
: ProcFSGlobalInformation("cmdline"sv)
|
|
|
|
{
|
|
|
|
}
|
2021-10-23 16:26:50 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSSystemMode::ProcFSSystemMode()
|
|
|
|
: ProcFSGlobalInformation("system_mode"sv)
|
|
|
|
{
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSProfile::ProcFSProfile()
|
|
|
|
: ProcFSGlobalInformation("profile"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-22 12:18:36 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSKernelBase::ProcFSKernelBase()
|
|
|
|
: ProcFSGlobalInformation("kernel_base"sv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemDirectory> ProcFSSystemDirectory::must_create(ProcFSRootDirectory const& parent_directory)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-07-17 21:15:52 +00:00
|
|
|
auto directory = adopt_ref(*new (nothrow) ProcFSSystemDirectory(parent_directory));
|
|
|
|
directory->m_components.append(ProcFSDumpKmallocStacks::must_create(directory));
|
|
|
|
directory->m_components.append(ProcFSUBSanDeadly::must_create(directory));
|
|
|
|
directory->m_components.append(ProcFSCapsLockRemap::must_create(directory));
|
|
|
|
return directory;
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSSystemDirectory::ProcFSSystemDirectory(ProcFSRootDirectory const& parent_directory)
|
2021-07-17 21:15:52 +00:00
|
|
|
: ProcFSExposedDirectory("sys"sv, parent_directory)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-21 16:09:21 +00:00
|
|
|
UNMAP_AFTER_INIT void ProcFSRootDirectory::add_pci_node(Badge<PCI::Access>)
|
|
|
|
{
|
|
|
|
m_components.append(ProcFSPCI::must_create());
|
|
|
|
}
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRootDirectory> ProcFSRootDirectory::must_create()
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-07-17 21:15:52 +00:00
|
|
|
auto directory = adopt_ref(*new (nothrow) ProcFSRootDirectory);
|
|
|
|
directory->m_components.append(ProcFSSelfProcessDirectory::must_create());
|
|
|
|
directory->m_components.append(ProcFSDiskUsage::must_create());
|
|
|
|
directory->m_components.append(ProcFSMemoryStatus::must_create());
|
2021-10-07 19:02:18 +00:00
|
|
|
directory->m_components.append(ProcFSSystemStatistics::must_create());
|
2021-07-17 21:15:52 +00:00
|
|
|
directory->m_components.append(ProcFSOverallProcesses::must_create());
|
|
|
|
directory->m_components.append(ProcFSCPUInformation::must_create());
|
|
|
|
directory->m_components.append(ProcFSDmesg::must_create());
|
|
|
|
directory->m_components.append(ProcFSInterrupts::must_create());
|
|
|
|
directory->m_components.append(ProcFSKeymap::must_create());
|
|
|
|
directory->m_components.append(ProcFSDevices::must_create());
|
|
|
|
directory->m_components.append(ProcFSUptime::must_create());
|
|
|
|
directory->m_components.append(ProcFSCommandLine::must_create());
|
2021-10-23 16:26:50 +00:00
|
|
|
directory->m_components.append(ProcFSSystemMode::must_create());
|
2021-07-17 21:15:52 +00:00
|
|
|
directory->m_components.append(ProcFSProfile::must_create());
|
2021-07-22 12:18:36 +00:00
|
|
|
directory->m_components.append(ProcFSKernelBase::must_create());
|
2021-07-17 21:15:52 +00:00
|
|
|
|
|
|
|
directory->m_components.append(ProcFSNetworkDirectory::must_create(*directory));
|
|
|
|
directory->m_components.append(ProcFSSystemDirectory::must_create(*directory));
|
|
|
|
return directory;
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 14:11:31 +00:00
|
|
|
ErrorOr<void> ProcFSRootDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-07-17 23:13:34 +00:00
|
|
|
MutexLocker locker(ProcFSComponentRegistry::the().get_lock());
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(callback({ "."sv, { fsid, component_index() }, 0 }));
|
|
|
|
TRY(callback({ ".."sv, { fsid, 0 }, 0 }));
|
2021-06-22 21:24:25 +00:00
|
|
|
|
2021-12-29 00:01:27 +00:00
|
|
|
for (auto const& component : m_components) {
|
2021-06-22 21:24:25 +00:00
|
|
|
InodeIdentifier identifier = { fsid, component.component_index() };
|
2021-11-10 14:42:39 +00:00
|
|
|
TRY(callback({ component.name(), identifier, 0 }));
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
2021-11-10 14:42:39 +00:00
|
|
|
|
2021-12-28 22:46:21 +00:00
|
|
|
return Process::all_instances().with([&](auto& list) -> ErrorOr<void> {
|
2021-11-10 14:42:39 +00:00
|
|
|
for (auto& process : list) {
|
|
|
|
VERIFY(!(process.pid() < 0));
|
|
|
|
u64 process_id = (u64)process.pid().value();
|
|
|
|
InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
|
2021-11-29 11:01:24 +00:00
|
|
|
auto process_id_string = TRY(KString::formatted("{:d}", process_id));
|
|
|
|
TRY(callback({ process_id_string->view(), identifier, 0 }));
|
2021-11-10 14:42:39 +00:00
|
|
|
}
|
|
|
|
return {};
|
2021-08-10 17:51:28 +00:00
|
|
|
});
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<NonnullRefPtr<ProcFSExposedComponent>> ProcFSRootDirectory::lookup(StringView name)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
2021-08-14 12:39:51 +00:00
|
|
|
auto maybe_candidate = ProcFSExposedDirectory::lookup(name);
|
|
|
|
if (maybe_candidate.is_error()) {
|
2021-11-07 23:51:39 +00:00
|
|
|
if (maybe_candidate.error().code() != ENOENT) {
|
|
|
|
return maybe_candidate.release_error();
|
2021-08-14 12:39:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return maybe_candidate.release_value();
|
|
|
|
}
|
2021-06-22 21:24:25 +00:00
|
|
|
|
2022-01-12 21:23:52 +00:00
|
|
|
auto pid = name.to_uint<unsigned>();
|
2021-08-10 17:51:28 +00:00
|
|
|
if (!pid.has_value())
|
2021-08-14 12:39:51 +00:00
|
|
|
return ESRCH;
|
2021-08-10 17:51:28 +00:00
|
|
|
auto actual_pid = pid.value();
|
2021-08-14 12:39:51 +00:00
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
if (auto maybe_process = Process::from_pid(actual_pid))
|
2021-08-14 12:43:34 +00:00
|
|
|
return maybe_process->procfs_traits();
|
2021-11-07 23:51:39 +00:00
|
|
|
|
2021-08-14 12:39:51 +00:00
|
|
|
return ENOENT;
|
2021-06-22 21:24:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 23:33:40 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSRootDirectory::ProcFSRootDirectory()
|
|
|
|
: ProcFSExposedDirectory("."sv)
|
2021-06-22 21:24:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-16 19:15:15 +00:00
|
|
|
UNMAP_AFTER_INIT ProcFSRootDirectory::~ProcFSRootDirectory() = default;
|
2021-06-22 21:24:25 +00:00
|
|
|
|
|
|
|
}
|