summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-22 14:18:36 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-22 14:20:05 +0200
commit6115258a5c6fc12c7d8276938a14a2b6b2339fb4 (patch)
tree29aa9168934d81dea0c544acc708c5321f74b4b4
parent0642f8f2c64e873aa0c2abc7cde3fb767876548c (diff)
downloadserenity-6115258a5c6fc12c7d8276938a14a2b6b2339fb4.zip
Kernel: Add /proc/kernel_base (superuser only)
This file contains the kernel base address as a decimal integer.
-rw-r--r--Kernel/GlobalProcessExposed.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index eec1233ebf..5243264654 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -707,6 +707,24 @@ private:
}
};
+class ProcFSKernelBase final : public ProcFSGlobalInformation {
+public:
+ static NonnullRefPtr<ProcFSKernelBase> must_create();
+
+private:
+ ProcFSKernelBase();
+
+ virtual mode_t required_mode() const override { return 0400; }
+
+ virtual bool output(KBufferBuilder& builder) override
+ {
+ if (!Process::current()->is_superuser())
+ return false;
+ builder.append(String::number(kernel_base));
+ return true;
+ }
+};
+
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSelfProcessDirectory> ProcFSSelfProcessDirectory::must_create()
{
return adopt_ref_if_nonnull(new (nothrow) ProcFSSelfProcessDirectory()).release_nonnull();
@@ -764,6 +782,11 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSProfile> ProcFSProfile::must_create()
return adopt_ref_if_nonnull(new (nothrow) ProcFSProfile).release_nonnull();
}
+UNMAP_AFTER_INIT NonnullRefPtr<ProcFSKernelBase> ProcFSKernelBase::must_create()
+{
+ return adopt_ref_if_nonnull(new (nothrow) ProcFSKernelBase).release_nonnull();
+}
+
UNMAP_AFTER_INIT ProcFSSelfProcessDirectory::ProcFSSelfProcessDirectory()
: ProcFSExposedLink("self"sv)
{
@@ -821,6 +844,11 @@ UNMAP_AFTER_INIT ProcFSProfile::ProcFSProfile()
{
}
+UNMAP_AFTER_INIT ProcFSKernelBase::ProcFSKernelBase()
+ : ProcFSGlobalInformation("kernel_base"sv)
+{
+}
+
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemDirectory> ProcFSSystemDirectory::must_create(const ProcFSRootDirectory& parent_directory)
{
auto directory = adopt_ref(*new (nothrow) ProcFSSystemDirectory(parent_directory));
@@ -852,6 +880,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRootDirectory> ProcFSRootDirectory::must_cr
directory->m_components.append(ProcFSCommandLine::must_create());
directory->m_components.append(ProcFSModules::must_create());
directory->m_components.append(ProcFSProfile::must_create());
+ directory->m_components.append(ProcFSKernelBase::must_create());
directory->m_components.append(ProcFSNetworkDirectory::must_create(*directory));
directory->m_components.append(ProcFSSystemDirectory::must_create(*directory));