2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-08-27 14:19:51 +03:00
|
|
|
#include <AK/JsonArraySerializer.h>
|
2019-06-29 09:04:45 +02:00
|
|
|
#include <AK/JsonObject.h>
|
2019-08-27 14:19:51 +03:00
|
|
|
#include <AK/JsonObjectSerializer.h>
|
2019-06-29 09:04:45 +02:00
|
|
|
#include <AK/JsonValue.h>
|
2019-06-07 20:02:01 +02:00
|
|
|
#include <Kernel/Arch/i386/CPU.h>
|
2020-06-27 17:06:33 -06:00
|
|
|
#include <Kernel/Arch/i386/ProcessorInfo.h>
|
2020-04-08 13:54:44 +02:00
|
|
|
#include <Kernel/CommandLine.h>
|
2020-05-26 00:35:11 -07:00
|
|
|
#include <Kernel/Console.h>
|
2020-02-16 01:50:16 +01:00
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2020-08-06 02:04:56 +03:00
|
|
|
#include <Kernel/Devices/KeyboardDevice.h>
|
2019-05-30 18:58:59 +02:00
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
2020-04-06 11:54:21 +03:00
|
|
|
#include <Kernel/FileSystem/FileBackedFileSystem.h>
|
2019-06-07 09:36:51 +02:00
|
|
|
#include <Kernel/FileSystem/FileDescription.h>
|
2020-05-06 18:40:06 +03:00
|
|
|
#include <Kernel/FileSystem/ProcFS.h>
|
2019-04-03 12:25:24 +02:00
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
2019-11-28 21:12:02 +01:00
|
|
|
#include <Kernel/Heap/kmalloc.h>
|
2020-02-22 20:51:50 +02:00
|
|
|
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
|
|
|
#include <Kernel/Interrupts/InterruptManagement.h>
|
2019-08-07 21:52:43 +02:00
|
|
|
#include <Kernel/KBufferBuilder.h>
|
2020-05-06 18:40:06 +03:00
|
|
|
#include <Kernel/KSyms.h>
|
2019-11-28 21:12:02 +01:00
|
|
|
#include <Kernel/Module.h>
|
2019-08-10 19:11:35 +03:00
|
|
|
#include <Kernel/Net/LocalSocket.h>
|
2019-06-16 07:06:49 +02:00
|
|
|
#include <Kernel/Net/NetworkAdapter.h>
|
2019-09-02 15:41:18 +10:00
|
|
|
#include <Kernel/Net/Routing.h>
|
2019-08-06 23:40:38 +10:00
|
|
|
#include <Kernel/Net/TCPSocket.h>
|
2019-08-09 13:27:40 +03:00
|
|
|
#include <Kernel/Net/UDPSocket.h>
|
2019-12-31 13:04:30 +02:00
|
|
|
#include <Kernel/PCI/Access.h>
|
2020-05-06 18:40:06 +03:00
|
|
|
#include <Kernel/Process.h>
|
2019-12-11 20:36:56 +01:00
|
|
|
#include <Kernel/Profiling.h>
|
2020-05-06 18:40:06 +03:00
|
|
|
#include <Kernel/Scheduler.h>
|
2020-05-26 00:35:11 -07:00
|
|
|
#include <Kernel/StdLib.h>
|
2020-02-16 02:01:42 +01:00
|
|
|
#include <Kernel/TTY/TTY.h>
|
2019-06-07 11:43:58 +02:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
2019-12-09 19:12:38 +01:00
|
|
|
#include <Kernel/VM/PurgeableVMObject.h>
|
2019-02-03 12:33:11 +01:00
|
|
|
#include <LibC/errno_numbers.h>
|
|
|
|
|
2020-08-27 00:58:09 +02:00
|
|
|
//#define PROCFS_DEBUG
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum ProcParentDirectory {
|
2019-02-03 12:33:11 +01:00
|
|
|
PDI_AbstractRoot = 0,
|
|
|
|
PDI_Root,
|
|
|
|
PDI_Root_sys,
|
2019-08-09 13:10:26 +03:00
|
|
|
PDI_Root_net,
|
2019-02-03 12:33:11 +01:00
|
|
|
PDI_PID,
|
|
|
|
PDI_PID_fd,
|
2020-08-09 19:59:26 +02:00
|
|
|
PDI_PID_stacks,
|
2019-02-03 12:33:11 +01:00
|
|
|
};
|
2020-08-09 19:59:26 +02:00
|
|
|
static_assert(PDI_PID_stacks < 16, "Too many directories for identifier scheme");
|
2019-02-03 12:33:11 +01:00
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum ProcFileType {
|
2019-02-03 12:33:11 +01:00
|
|
|
FI_Invalid = 0,
|
|
|
|
|
|
|
|
FI_Root = 1, // directory
|
|
|
|
|
|
|
|
__FI_Root_Start,
|
|
|
|
FI_Root_mm,
|
|
|
|
FI_Root_mounts,
|
2019-02-21 14:48:00 +01:00
|
|
|
FI_Root_df,
|
2019-02-03 18:53:18 +01:00
|
|
|
FI_Root_all,
|
2019-03-10 12:13:22 +01:00
|
|
|
FI_Root_memstat,
|
2019-02-03 12:33:11 +01:00
|
|
|
FI_Root_cpuinfo,
|
|
|
|
FI_Root_inodes,
|
|
|
|
FI_Root_dmesg,
|
2020-02-22 20:51:50 +02:00
|
|
|
FI_Root_interrupts,
|
2020-08-06 02:04:56 +03:00
|
|
|
FI_Root_keymap,
|
2019-02-06 10:29:35 +01:00
|
|
|
FI_Root_pci,
|
2019-08-18 14:58:47 +03:00
|
|
|
FI_Root_devices,
|
2019-04-14 15:19:45 +02:00
|
|
|
FI_Root_uptime,
|
2019-06-16 14:05:07 +02:00
|
|
|
FI_Root_cmdline,
|
2019-11-28 21:12:02 +01:00
|
|
|
FI_Root_modules,
|
2019-12-11 20:36:56 +01:00
|
|
|
FI_Root_profile,
|
2019-02-03 12:33:11 +01:00
|
|
|
FI_Root_self, // symlink
|
2019-06-07 11:43:58 +02:00
|
|
|
FI_Root_sys, // directory
|
2019-08-09 13:10:26 +03:00
|
|
|
FI_Root_net, // directory
|
2019-02-03 12:33:11 +01:00
|
|
|
__FI_Root_End,
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
FI_Root_sys_variable,
|
|
|
|
|
2019-08-09 13:10:26 +03:00
|
|
|
FI_Root_net_adapters,
|
2019-09-02 15:41:18 +10:00
|
|
|
FI_Root_net_arp,
|
2019-08-09 13:10:26 +03:00
|
|
|
FI_Root_net_tcp,
|
2019-08-09 13:27:40 +03:00
|
|
|
FI_Root_net_udp,
|
2019-08-10 19:11:35 +03:00
|
|
|
FI_Root_net_local,
|
2019-08-09 13:10:26 +03:00
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
FI_PID,
|
|
|
|
|
|
|
|
__FI_PID_Start,
|
|
|
|
FI_PID_vm,
|
2019-12-19 19:13:44 +01:00
|
|
|
FI_PID_vmobjects,
|
2020-08-09 19:59:26 +02:00
|
|
|
FI_PID_stacks, // directory
|
2019-02-03 12:33:11 +01:00
|
|
|
FI_PID_fds,
|
2020-01-20 22:19:02 +01:00
|
|
|
FI_PID_unveil,
|
2020-01-11 18:25:26 +03:00
|
|
|
FI_PID_exe, // symlink
|
|
|
|
FI_PID_cwd, // symlink
|
2020-01-10 23:48:44 +01:00
|
|
|
FI_PID_root, // symlink
|
2020-01-11 18:25:26 +03:00
|
|
|
FI_PID_fd, // directory
|
2019-02-03 12:33:11 +01:00
|
|
|
__FI_PID_End,
|
|
|
|
|
|
|
|
FI_MaxStaticFileIndex,
|
|
|
|
};
|
|
|
|
|
2020-08-08 17:32:34 +02:00
|
|
|
static inline ProcessID to_pid(const InodeIdentifier& identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "to_pid, index=" << String::format("%08x", identifier.index()) << " -> " << (identifier.index() >> 16);
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
return identifier.index() >> 16u;
|
|
|
|
}
|
|
|
|
|
2020-08-09 19:59:26 +02:00
|
|
|
static inline ThreadID to_tid(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
// Sneakily, use the exact same mechanism.
|
|
|
|
return to_pid(identifier).value();
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
return (ProcParentDirectory)((identifier.index() >> 12) & 0xf);
|
|
|
|
}
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
return (ProcFileType)(identifier.index() & 0xff);
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
static inline int to_fd(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
ASSERT(to_proc_parent_directory(identifier) == PDI_PID_fd);
|
|
|
|
return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
|
|
|
|
}
|
|
|
|
|
2020-02-25 14:49:47 +01:00
|
|
|
static inline size_t to_sys_index(const InodeIdentifier& identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
|
2019-08-16 16:35:02 +03:00
|
|
|
ASSERT(to_proc_file_type(identifier) == FI_Root_sys_variable);
|
|
|
|
return identifier.index() >> 16u;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 17:32:34 +02:00
|
|
|
static inline InodeIdentifier to_identifier(unsigned fsid, ProcParentDirectory parent, ProcessID pid, ProcFileType proc_file_type)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-08 17:32:34 +02:00
|
|
|
return { fsid, ((unsigned)parent << 12u) | ((unsigned)pid.value() << 16u) | (unsigned)proc_file_type };
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 17:32:34 +02:00
|
|
|
static inline InodeIdentifier to_identifier_with_fd(unsigned fsid, ProcessID pid, int fd)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-08 17:32:34 +02:00
|
|
|
return { fsid, (PDI_PID_fd << 12u) | ((unsigned)pid.value() << 16u) | (FI_MaxStaticFileIndex + fd) };
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-09 19:59:26 +02:00
|
|
|
static inline InodeIdentifier to_identifier_with_stack(unsigned fsid, ThreadID tid)
|
|
|
|
{
|
|
|
|
return { fsid, (PDI_PID_stacks << 12u) | ((unsigned)tid.value() << 16u) | FI_MaxStaticFileIndex };
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
static inline InodeIdentifier sys_var_to_identifier(unsigned fsid, unsigned index)
|
|
|
|
{
|
|
|
|
ASSERT(index < 256);
|
2019-08-16 16:35:02 +03:00
|
|
|
return { fsid, (PDI_Root_sys << 12u) | (index << 16u) | FI_Root_sys_variable };
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline InodeIdentifier to_parent_id(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
switch (to_proc_parent_directory(identifier)) {
|
|
|
|
case PDI_AbstractRoot:
|
|
|
|
case PDI_Root:
|
|
|
|
return { identifier.fsid(), FI_Root };
|
|
|
|
case PDI_Root_sys:
|
|
|
|
return { identifier.fsid(), FI_Root_sys };
|
2019-08-09 13:10:26 +03:00
|
|
|
case PDI_Root_net:
|
|
|
|
return { identifier.fsid(), FI_Root_net };
|
2019-02-03 12:33:11 +01:00
|
|
|
case PDI_PID:
|
|
|
|
return to_identifier(identifier.fsid(), PDI_Root, to_pid(identifier), FI_PID);
|
|
|
|
case PDI_PID_fd:
|
|
|
|
return to_identifier(identifier.fsid(), PDI_PID, to_pid(identifier), FI_PID_fd);
|
2020-08-09 19:59:26 +02:00
|
|
|
case PDI_PID_stacks:
|
|
|
|
return to_identifier(identifier.fsid(), PDI_PID, to_pid(identifier), FI_PID_stacks);
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-02-12 12:11:22 +01:00
|
|
|
ASSERT_NOT_REACHED();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2019-07-03 21:17:35 +02:00
|
|
|
static inline u8 to_unused_metadata(const InodeIdentifier& identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
return (identifier.index() >> 8) & 0xf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline bool is_process_related_file(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
if (to_proc_file_type(identifier) == FI_PID)
|
|
|
|
return true;
|
|
|
|
auto proc_parent_directory = to_proc_parent_directory(identifier);
|
|
|
|
switch (proc_parent_directory) {
|
|
|
|
case PDI_PID:
|
|
|
|
case PDI_PID_fd:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 19:59:26 +02:00
|
|
|
static inline bool is_thread_related_file(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
auto proc_parent_directory = to_proc_parent_directory(identifier);
|
|
|
|
return proc_parent_directory == PDI_PID_stacks;
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
static inline bool is_directory(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier);
|
|
|
|
switch (proc_file_type) {
|
|
|
|
case FI_Root:
|
|
|
|
case FI_Root_sys:
|
2019-08-09 13:10:26 +03:00
|
|
|
case FI_Root_net:
|
2019-02-03 12:33:11 +01:00
|
|
|
case FI_PID:
|
|
|
|
case FI_PID_fd:
|
2020-08-09 19:59:26 +02:00
|
|
|
case FI_PID_stacks:
|
2019-02-03 12:33:11 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool is_persistent_inode(const InodeIdentifier& identifier)
|
|
|
|
{
|
|
|
|
return to_proc_parent_directory(identifier) == PDI_Root_sys;
|
|
|
|
}
|
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
NonnullRefPtr<ProcFS> ProcFS::create()
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
return adopt(*new ProcFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcFS::~ProcFS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_fds(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-10-23 02:48:17 +13:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process) {
|
2019-10-23 02:48:17 +13:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
2020-08-01 20:04:56 -06:00
|
|
|
if (process->number_of_open_file_descriptors() == 0) {
|
2019-10-23 02:48:17 +13:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
2019-08-27 14:19:51 +03:00
|
|
|
|
2020-08-01 20:04:56 -06:00
|
|
|
for (int i = 0; i < process->max_open_file_descriptors(); ++i) {
|
|
|
|
auto description = process->file_description(i);
|
2019-06-13 22:03:04 +02:00
|
|
|
if (!description)
|
2019-02-03 12:33:11 +01:00
|
|
|
continue;
|
2020-08-01 20:04:56 -06:00
|
|
|
bool cloexec = process->fd_flags(i) & FD_CLOEXEC;
|
2019-09-28 23:00:38 +03:00
|
|
|
|
2019-11-04 18:02:27 +01:00
|
|
|
auto description_object = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
description_object.add("fd", i);
|
|
|
|
description_object.add("absolute_path", description->absolute_path());
|
|
|
|
description_object.add("seekable", description->file().is_seekable());
|
|
|
|
description_object.add("class", description->file().class_name());
|
|
|
|
description_object.add("offset", description->offset());
|
2019-09-28 23:00:38 +03:00
|
|
|
description_object.add("cloexec", cloexec);
|
|
|
|
description_object.add("blocking", description->is_blocking());
|
2019-11-09 22:15:35 +01:00
|
|
|
description_object.add("can_read", description->can_read());
|
|
|
|
description_object.add("can_write", description->can_write());
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_fd_entry(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
int fd = to_fd(identifier);
|
2020-08-01 20:04:56 -06:00
|
|
|
auto description = process->file_description(fd);
|
2019-06-13 22:03:04 +02:00
|
|
|
if (!description)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-06-13 22:03:04 +02:00
|
|
|
return description->absolute_path().to_byte_buffer();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_vm(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
2020-08-01 20:04:56 -06:00
|
|
|
{
|
|
|
|
ScopedSpinLock lock(process->get_lock());
|
|
|
|
for (auto& region : process->regions()) {
|
|
|
|
if (!region.is_user_accessible() && !Process::current()->is_superuser())
|
|
|
|
continue;
|
|
|
|
auto region_object = array.add_object();
|
|
|
|
region_object.add("readable", region.is_readable());
|
|
|
|
region_object.add("writable", region.is_writable());
|
|
|
|
region_object.add("executable", region.is_executable());
|
|
|
|
region_object.add("stack", region.is_stack());
|
|
|
|
region_object.add("shared", region.is_shared());
|
|
|
|
region_object.add("user_accessible", region.is_user_accessible());
|
|
|
|
region_object.add("purgeable", region.vmobject().is_purgeable());
|
|
|
|
if (region.vmobject().is_purgeable()) {
|
|
|
|
region_object.add("volatile", static_cast<const PurgeableVMObject&>(region.vmobject()).is_volatile());
|
|
|
|
}
|
|
|
|
region_object.add("purgeable", region.vmobject().is_purgeable());
|
|
|
|
region_object.add("address", region.vaddr().get());
|
|
|
|
region_object.add("size", region.size());
|
|
|
|
region_object.add("amount_resident", region.amount_resident());
|
|
|
|
region_object.add("amount_dirty", region.amount_dirty());
|
|
|
|
region_object.add("cow_pages", region.cow_pages());
|
|
|
|
region_object.add("name", region.name());
|
|
|
|
region_object.add("vmobject", region.vmobject().class_name());
|
2020-08-05 14:09:38 +02:00
|
|
|
|
2020-08-01 20:04:56 -06:00
|
|
|
StringBuilder pagemap_builder;
|
|
|
|
for (size_t i = 0; i < region.page_count(); ++i) {
|
|
|
|
auto* page = region.physical_page(i);
|
|
|
|
if (!page)
|
|
|
|
pagemap_builder.append('N');
|
|
|
|
else if (page->is_shared_zero_page())
|
|
|
|
pagemap_builder.append('Z');
|
|
|
|
else
|
|
|
|
pagemap_builder.append('P');
|
|
|
|
}
|
|
|
|
region_object.add("pagemap", pagemap_builder.to_string());
|
2020-02-25 21:38:03 +01:00
|
|
|
}
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pci(InodeIdentifier)
|
2019-02-06 10:29:35 +01:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
2020-04-10 20:25:03 +03:00
|
|
|
PCI::enumerate([&array](PCI::Address address, PCI::ID id) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-12-31 13:04:30 +02:00
|
|
|
obj.add("seg", address.seg());
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("bus", address.bus());
|
|
|
|
obj.add("slot", address.slot());
|
|
|
|
obj.add("function", address.function());
|
|
|
|
obj.add("vendor_id", id.vendor_id);
|
|
|
|
obj.add("device_id", id.device_id);
|
|
|
|
obj.add("revision_id", PCI::get_revision_id(address));
|
|
|
|
obj.add("subclass", PCI::get_subclass(address));
|
|
|
|
obj.add("class", PCI::get_class(address));
|
|
|
|
obj.add("subsystem_id", PCI::get_subsystem_id(address));
|
|
|
|
obj.add("subsystem_vendor_id", PCI::get_subsystem_vendor_id(address));
|
2019-02-06 10:29:35 +01:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-02-06 10:29:35 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$interrupts(InodeIdentifier)
|
2020-02-22 20:51:50 +02:00
|
|
|
{
|
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
InterruptManagement::the().enumerate_interrupt_handlers([&array](GenericInterruptHandler& handler) {
|
|
|
|
auto obj = array.add_object();
|
2020-03-05 19:15:38 +02:00
|
|
|
obj.add("purpose", handler.purpose());
|
2020-02-22 20:51:50 +02:00
|
|
|
obj.add("interrupt_line", handler.interrupt_number());
|
2020-03-05 19:15:38 +02:00
|
|
|
obj.add("controller", handler.controller());
|
2020-02-22 20:51:50 +02:00
|
|
|
obj.add("cpu_handler", 0); // FIXME: Determine the responsible CPU for each interrupt handler.
|
2020-02-23 14:14:01 +02:00
|
|
|
obj.add("device_sharing", (unsigned)handler.sharing_devices_count());
|
2020-02-22 20:51:50 +02:00
|
|
|
obj.add("call_count", (unsigned)handler.get_invoking_count());
|
|
|
|
});
|
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$keymap(InodeIdentifier)
|
2020-08-06 02:04:56 +03:00
|
|
|
{
|
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonObjectSerializer<KBufferBuilder> json { builder };
|
|
|
|
json.add("keymap", KeyboardDevice::the().keymap_name());
|
|
|
|
json.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$devices(InodeIdentifier)
|
2019-08-18 14:58:47 +03:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
Device::for_each([&array](auto& device) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("major", device.major());
|
|
|
|
obj.add("minor", device.minor());
|
|
|
|
obj.add("class_name", device.class_name());
|
2019-08-18 14:58:47 +03:00
|
|
|
|
|
|
|
if (device.is_block_device())
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("type", "block");
|
2019-08-18 14:58:47 +03:00
|
|
|
else if (device.is_character_device())
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("type", "character");
|
2019-08-18 14:58:47 +03:00
|
|
|
else
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-08-18 14:58:47 +03:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$uptime(InodeIdentifier)
|
2019-04-14 15:19:45 +02:00
|
|
|
{
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2020-05-22 13:58:37 +02:00
|
|
|
builder.appendf("%u\n", (g_uptime / 1000));
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-04-14 15:19:45 +02:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$cmdline(InodeIdentifier)
|
2019-06-16 14:05:07 +02:00
|
|
|
{
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2020-04-08 13:54:44 +02:00
|
|
|
builder.append(kernel_command_line().string());
|
|
|
|
builder.append('\n');
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-06-16 14:05:07 +02:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$modules(InodeIdentifier)
|
2019-11-28 21:12:02 +01:00
|
|
|
{
|
|
|
|
extern HashMap<String, OwnPtr<Module>>* g_modules;
|
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
for (auto& it : *g_modules) {
|
|
|
|
auto obj = array.add_object();
|
|
|
|
obj.add("name", it.value->name);
|
2020-05-22 13:58:37 +02:00
|
|
|
obj.add("module_init", it.value->module_init);
|
|
|
|
obj.add("module_fini", it.value->module_fini);
|
2019-11-29 21:18:37 +01:00
|
|
|
u32 size = 0;
|
|
|
|
for (auto& section : it.value->sections) {
|
|
|
|
size += section.capacity();
|
|
|
|
}
|
|
|
|
obj.add("size", size);
|
2019-11-28 21:12:02 +01:00
|
|
|
}
|
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$profile(InodeIdentifier)
|
2019-12-11 20:36:56 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
KBufferBuilder builder;
|
2020-02-22 10:05:03 +01:00
|
|
|
|
|
|
|
JsonObjectSerializer object(builder);
|
2020-08-09 01:08:24 +02:00
|
|
|
object.add("pid", Profiling::pid().value());
|
2020-02-22 10:05:03 +01:00
|
|
|
object.add("executable", Profiling::executable_path());
|
|
|
|
|
|
|
|
auto array = object.add_array("events");
|
2020-06-28 15:34:31 -06:00
|
|
|
bool mask_kernel_addresses = !Process::current()->is_superuser();
|
2019-12-11 20:36:56 +01:00
|
|
|
Profiling::for_each_sample([&](auto& sample) {
|
|
|
|
auto object = array.add_object();
|
2020-02-22 10:05:03 +01:00
|
|
|
object.add("type", "sample");
|
2020-08-09 01:08:24 +02:00
|
|
|
object.add("tid", sample.tid.value());
|
2019-12-11 20:36:56 +01:00
|
|
|
object.add("timestamp", sample.timestamp);
|
2020-02-22 10:05:03 +01:00
|
|
|
auto frames_array = object.add_array("stack");
|
2019-12-11 20:36:56 +01:00
|
|
|
for (size_t i = 0; i < Profiling::max_stack_frame_count; ++i) {
|
|
|
|
if (sample.frames[i] == 0)
|
|
|
|
break;
|
2020-01-02 20:49:21 +01:00
|
|
|
u32 address = (u32)sample.frames[i];
|
|
|
|
if (mask_kernel_addresses && !is_user_address(VirtualAddress(address)))
|
|
|
|
address = 0xdeadc0de;
|
2020-02-22 10:05:03 +01:00
|
|
|
frames_array.add(address);
|
2019-12-11 20:36:56 +01:00
|
|
|
}
|
2019-12-12 20:36:41 +01:00
|
|
|
frames_array.finish();
|
2019-12-11 20:36:56 +01:00
|
|
|
});
|
|
|
|
array.finish();
|
2020-02-22 10:05:03 +01:00
|
|
|
object.finish();
|
2019-12-11 20:36:56 +01:00
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$net_adapters(InodeIdentifier)
|
2019-06-16 07:06:49 +02:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
NetworkAdapter::for_each([&array](auto& adapter) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("name", adapter.name());
|
|
|
|
obj.add("class_name", adapter.class_name());
|
|
|
|
obj.add("mac_address", adapter.mac_address().to_string());
|
2019-08-28 11:01:16 +10:00
|
|
|
if (!adapter.ipv4_address().is_zero()) {
|
|
|
|
obj.add("ipv4_address", adapter.ipv4_address().to_string());
|
|
|
|
obj.add("ipv4_netmask", adapter.ipv4_netmask().to_string());
|
|
|
|
}
|
|
|
|
if (!adapter.ipv4_gateway().is_zero())
|
|
|
|
obj.add("ipv4_gateway", adapter.ipv4_gateway().to_string());
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("packets_in", adapter.packets_in());
|
|
|
|
obj.add("bytes_in", adapter.bytes_in());
|
|
|
|
obj.add("packets_out", adapter.packets_out());
|
|
|
|
obj.add("bytes_out", adapter.bytes_out());
|
|
|
|
obj.add("link_up", adapter.link_up());
|
2019-11-28 07:12:05 +01:00
|
|
|
obj.add("mtu", adapter.mtu());
|
2019-06-16 07:06:49 +02:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-06-16 07:06:49 +02:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$net_arp(InodeIdentifier)
|
2019-09-02 15:41:18 +10:00
|
|
|
{
|
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
2020-04-18 12:50:35 +03:00
|
|
|
LOCKER(arp_table().lock(), Lock::Mode::Shared);
|
2019-09-02 15:41:18 +10:00
|
|
|
for (auto& it : arp_table().resource()) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-09-02 15:41:18 +10:00
|
|
|
obj.add("mac_address", it.value.to_string());
|
|
|
|
obj.add("ip_address", it.key.to_string());
|
|
|
|
}
|
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
|
2019-08-06 23:40:38 +10:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
TCPSocket::for_each([&array](auto& socket) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("local_address", socket.local_address().to_string());
|
|
|
|
obj.add("local_port", socket.local_port());
|
|
|
|
obj.add("peer_address", socket.peer_address().to_string());
|
|
|
|
obj.add("peer_port", socket.peer_port());
|
|
|
|
obj.add("state", TCPSocket::to_string(socket.state()));
|
|
|
|
obj.add("ack_number", socket.ack_number());
|
|
|
|
obj.add("sequence_number", socket.sequence_number());
|
|
|
|
obj.add("packets_in", socket.packets_in());
|
|
|
|
obj.add("bytes_in", socket.bytes_in());
|
|
|
|
obj.add("packets_out", socket.packets_out());
|
|
|
|
obj.add("bytes_out", socket.bytes_out());
|
2019-08-06 23:40:38 +10:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-08-06 23:40:38 +10:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$net_udp(InodeIdentifier)
|
2019-08-09 13:27:40 +03:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
UDPSocket::for_each([&array](auto& socket) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("local_address", socket.local_address().to_string());
|
|
|
|
obj.add("local_port", socket.local_port());
|
|
|
|
obj.add("peer_address", socket.peer_address().to_string());
|
|
|
|
obj.add("peer_port", socket.peer_port());
|
2019-08-09 13:27:40 +03:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-08-09 13:27:40 +03:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$net_local(InodeIdentifier)
|
2019-08-10 19:11:35 +03:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
LocalSocket::for_each([&array](auto& socket) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto obj = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("path", String(socket.socket_path()));
|
|
|
|
obj.add("origin_pid", socket.origin_pid());
|
2019-12-06 18:38:36 +01:00
|
|
|
obj.add("origin_uid", socket.origin_uid());
|
|
|
|
obj.add("origin_gid", socket.origin_gid());
|
2019-08-27 14:19:51 +03:00
|
|
|
obj.add("acceptor_pid", socket.acceptor_pid());
|
2019-12-07 09:40:30 +01:00
|
|
|
obj.add("acceptor_uid", socket.acceptor_uid());
|
|
|
|
obj.add("acceptor_gid", socket.acceptor_gid());
|
2019-08-10 19:11:35 +03:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-08-10 19:11:35 +03:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_vmobjects(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2019-02-03 12:33:11 +01:00
|
|
|
builder.appendf("BEGIN END SIZE NAME\n");
|
2020-08-01 20:04:56 -06:00
|
|
|
{
|
|
|
|
ScopedSpinLock lock(process->get_lock());
|
|
|
|
for (auto& region : process->regions()) {
|
|
|
|
builder.appendf("%x -- %x %x %s\n",
|
|
|
|
region.vaddr().get(),
|
|
|
|
region.vaddr().offset(region.size() - 1).get(),
|
|
|
|
region.size(),
|
|
|
|
region.name().characters());
|
|
|
|
builder.appendf("VMO: %s @ %x(%u)\n",
|
|
|
|
region.vmobject().is_anonymous() ? "anonymous" : "file-backed",
|
|
|
|
®ion.vmobject(),
|
|
|
|
region.vmobject().ref_count());
|
|
|
|
for (size_t i = 0; i < region.vmobject().page_count(); ++i) {
|
|
|
|
auto& physical_page = region.vmobject().physical_pages()[i];
|
|
|
|
bool should_cow = false;
|
|
|
|
if (i >= region.first_page_index() && i <= region.last_page_index())
|
|
|
|
should_cow = region.should_cow(i - region.first_page_index());
|
|
|
|
builder.appendf("P%x%s(%u) ",
|
|
|
|
physical_page ? physical_page->paddr().get() : 0,
|
|
|
|
should_cow ? "!" : "",
|
|
|
|
physical_page ? physical_page->ref_count() : 0);
|
|
|
|
}
|
|
|
|
builder.appendf("\n");
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_unveil(InodeIdentifier identifier)
|
2020-01-20 22:19:02 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2020-01-20 22:19:02 +01:00
|
|
|
return {};
|
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
2020-08-01 20:04:56 -06:00
|
|
|
for (auto& unveiled_path : process->unveiled_paths()) {
|
2020-01-20 22:19:02 +01:00
|
|
|
auto obj = array.add_object();
|
|
|
|
obj.add("path", unveiled_path.path);
|
|
|
|
StringBuilder permissions_builder;
|
|
|
|
if (unveiled_path.permissions & UnveiledPath::Access::Read)
|
|
|
|
permissions_builder.append('r');
|
|
|
|
if (unveiled_path.permissions & UnveiledPath::Access::Write)
|
|
|
|
permissions_builder.append('w');
|
|
|
|
if (unveiled_path.permissions & UnveiledPath::Access::Execute)
|
|
|
|
permissions_builder.append('x');
|
|
|
|
if (unveiled_path.permissions & UnveiledPath::Access::CreateOrRemove)
|
|
|
|
permissions_builder.append('c');
|
|
|
|
obj.add("permissions", permissions_builder.to_string());
|
|
|
|
}
|
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$tid_stack(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-09 19:59:26 +02:00
|
|
|
auto thread = Thread::from_tid(to_tid(identifier));
|
|
|
|
if (!thread)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2020-08-09 19:59:26 +02:00
|
|
|
KBufferBuilder builder;
|
|
|
|
builder.appendf("Thread %d (%s):\n", thread->tid().value(), thread->name().characters());
|
|
|
|
builder.append(thread->backtrace());
|
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_exe(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2020-08-01 20:04:56 -06:00
|
|
|
auto* custody = process->executable();
|
2019-05-30 18:58:59 +02:00
|
|
|
ASSERT(custody);
|
|
|
|
return custody->absolute_path().to_byte_buffer();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_cwd(InodeIdentifier identifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2020-08-01 20:04:56 -06:00
|
|
|
return process->current_directory().absolute_path().to_byte_buffer();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$pid_root(InodeIdentifier identifier)
|
2020-01-10 23:48:44 +01:00
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier));
|
|
|
|
if (!process)
|
2020-01-10 23:48:44 +01:00
|
|
|
return {};
|
2020-08-01 20:04:56 -06:00
|
|
|
return process->root_directory_relative_to_global_root().absolute_path().to_byte_buffer();
|
2020-01-10 23:48:44 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$self(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
char buffer[16];
|
2020-08-16 07:51:56 +02:00
|
|
|
int written = snprintf(buffer, sizeof(buffer), "%d", Process::current()->pid().value());
|
|
|
|
return KBuffer::copy((const u8*)buffer, static_cast<size_t>(written));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-05 11:35:49 +02:00
|
|
|
Optional<KBuffer> procfs$mm(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2019-08-08 10:43:44 +02:00
|
|
|
u32 vmobject_count = 0;
|
|
|
|
MemoryManager::for_each_vmobject([&](auto& vmobject) {
|
|
|
|
++vmobject_count;
|
|
|
|
builder.appendf("VMObject: %p %s(%u): p:%4u\n",
|
|
|
|
&vmobject,
|
|
|
|
vmobject.is_anonymous() ? "anon" : "file",
|
|
|
|
vmobject.ref_count(),
|
|
|
|
vmobject.page_count());
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
|
|
|
builder.appendf("VMO count: %u\n", vmobject_count);
|
2019-06-11 21:13:02 +10:00
|
|
|
builder.appendf("Free physical pages: %u\n", MM.user_physical_pages() - MM.user_physical_pages_used());
|
|
|
|
builder.appendf("Free supervisor physical pages: %u\n", MM.super_physical_pages() - MM.super_physical_pages_used());
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$dmesg(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2019-02-03 12:33:11 +01:00
|
|
|
for (char ch : Console::the().logbuffer())
|
|
|
|
builder.append(ch);
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$mounts(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
// FIXME: This is obviously racy against the VFS mounts changing.
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2019-06-07 11:43:58 +02:00
|
|
|
VFS::the().for_each_mount([&builder](auto& mount) {
|
2019-02-03 12:33:11 +01:00
|
|
|
auto& fs = mount.guest_fs();
|
|
|
|
builder.appendf("%s @ ", fs.class_name());
|
2020-06-25 00:16:24 +03:00
|
|
|
if (mount.host() == nullptr)
|
2019-02-03 12:33:11 +01:00
|
|
|
builder.appendf("/");
|
|
|
|
else {
|
2020-06-25 00:16:24 +03:00
|
|
|
builder.appendf("%u:%u", mount.host()->fsid(), mount.host()->index());
|
2019-02-03 12:33:11 +01:00
|
|
|
builder.append(' ');
|
2019-05-30 21:29:26 +02:00
|
|
|
builder.append(mount.absolute_path());
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
builder.append('\n');
|
|
|
|
});
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$df(InodeIdentifier)
|
2019-02-21 14:48:00 +01:00
|
|
|
{
|
|
|
|
// FIXME: This is obviously racy against the VFS mounts changing.
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
|
|
|
VFS::the().for_each_mount([&array](auto& mount) {
|
2019-02-21 14:48:00 +01:00
|
|
|
auto& fs = mount.guest_fs();
|
2019-11-04 18:02:27 +01:00
|
|
|
auto fs_object = array.add_object();
|
2019-08-27 14:19:51 +03:00
|
|
|
fs_object.add("class_name", fs.class_name());
|
|
|
|
fs_object.add("total_block_count", fs.total_block_count());
|
|
|
|
fs_object.add("free_block_count", fs.free_block_count());
|
|
|
|
fs_object.add("total_inode_count", fs.total_inode_count());
|
|
|
|
fs_object.add("free_inode_count", fs.free_inode_count());
|
|
|
|
fs_object.add("mount_point", mount.absolute_path());
|
2020-05-18 21:46:47 +03:00
|
|
|
fs_object.add("block_size", static_cast<u64>(fs.block_size()));
|
2019-08-27 14:19:51 +03:00
|
|
|
fs_object.add("readonly", fs.is_readonly());
|
2020-01-11 18:25:26 +03:00
|
|
|
fs_object.add("mount_flags", mount.flags());
|
2019-08-17 12:17:36 +03:00
|
|
|
|
2020-04-06 11:54:21 +03:00
|
|
|
if (fs.is_file_backed())
|
|
|
|
fs_object.add("source", static_cast<const FileBackedFS&>(fs).file_description().absolute_path());
|
2019-08-17 12:17:36 +03:00
|
|
|
else
|
2020-05-28 17:27:30 +03:00
|
|
|
fs_object.add("source", "none");
|
2019-02-21 14:48:00 +01:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-02-21 14:48:00 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$cpuinfo(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2020-07-11 20:52:10 +01:00
|
|
|
JsonArraySerializer array { builder };
|
2020-06-27 17:06:33 -06:00
|
|
|
Processor::for_each(
|
2020-08-05 14:09:38 +02:00
|
|
|
[&](Processor& proc) -> IterationDecision {
|
2020-06-27 17:06:33 -06:00
|
|
|
auto& info = proc.info();
|
2020-07-11 20:52:10 +01:00
|
|
|
auto obj = array.add_object();
|
|
|
|
JsonArray features;
|
|
|
|
for (auto& feature : info.features().split(' '))
|
|
|
|
features.append(feature);
|
|
|
|
obj.add("processor", proc.id());
|
|
|
|
obj.add("cpuid", info.cpuid());
|
|
|
|
obj.add("family", info.display_family());
|
|
|
|
obj.add("features", features);
|
|
|
|
obj.add("model", info.display_model());
|
|
|
|
obj.add("stepping", info.stepping());
|
|
|
|
obj.add("type", info.type());
|
|
|
|
obj.add("brandstr", info.brandstr());
|
2020-06-27 17:06:33 -06:00
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
2020-07-11 20:52:10 +01:00
|
|
|
array.finish();
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-05 11:35:49 +02:00
|
|
|
Optional<KBuffer> procfs$memstat(InodeIdentifier)
|
2019-03-10 12:13:22 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2020-09-18 09:49:51 +02:00
|
|
|
|
2020-08-29 16:41:30 -06:00
|
|
|
kmalloc_stats stats;
|
|
|
|
get_kmalloc_stats(stats);
|
2020-09-18 09:49:51 +02:00
|
|
|
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
2019-11-04 18:02:27 +01:00
|
|
|
JsonObjectSerializer<KBufferBuilder> json { builder };
|
2020-08-29 16:41:30 -06:00
|
|
|
json.add("kmalloc_allocated", stats.bytes_allocated);
|
|
|
|
json.add("kmalloc_available", stats.bytes_free);
|
|
|
|
json.add("kmalloc_eternal_allocated", stats.bytes_eternal);
|
2019-08-27 14:19:51 +03:00
|
|
|
json.add("user_physical_allocated", MM.user_physical_pages_used());
|
2019-12-26 11:43:42 +01:00
|
|
|
json.add("user_physical_available", MM.user_physical_pages() - MM.user_physical_pages_used());
|
2019-08-27 14:19:51 +03:00
|
|
|
json.add("super_physical_allocated", MM.super_physical_pages_used());
|
2019-12-26 11:43:42 +01:00
|
|
|
json.add("super_physical_available", MM.super_physical_pages() - MM.super_physical_pages_used());
|
2020-08-29 16:41:30 -06:00
|
|
|
json.add("kmalloc_call_count", stats.kmalloc_call_count);
|
|
|
|
json.add("kfree_call_count", stats.kfree_call_count);
|
2019-09-16 10:19:44 +02:00
|
|
|
slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) {
|
|
|
|
auto prefix = String::format("slab_%zu", slab_size);
|
2020-05-22 13:58:37 +02:00
|
|
|
json.add(String::format("%s_num_allocated", prefix.characters()), num_allocated);
|
|
|
|
json.add(String::format("%s_num_free", prefix.characters()), num_free);
|
2019-09-16 10:19:44 +02:00
|
|
|
});
|
2019-08-27 14:19:51 +03:00
|
|
|
json.finish();
|
|
|
|
return builder.build();
|
2019-03-10 12:13:22 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$all(InodeIdentifier)
|
2019-02-03 18:53:18 +01:00
|
|
|
{
|
2019-08-27 14:19:51 +03:00
|
|
|
KBufferBuilder builder;
|
|
|
|
JsonArraySerializer array { builder };
|
2019-07-17 22:22:22 +02:00
|
|
|
|
|
|
|
// Keep this in sync with CProcessStatistics.
|
2019-06-29 09:04:45 +02:00
|
|
|
auto build_process = [&](const Process& process) {
|
2019-11-04 18:02:27 +01:00
|
|
|
auto process_object = array.add_object();
|
2020-01-11 21:07:00 +01:00
|
|
|
|
2020-09-10 09:46:24 -06:00
|
|
|
if (process.is_user_process()) {
|
2020-08-16 00:27:23 -07:00
|
|
|
StringBuilder pledge_builder;
|
|
|
|
|
2020-01-11 21:07:00 +01:00
|
|
|
#define __ENUMERATE_PLEDGE_PROMISE(promise) \
|
|
|
|
if (process.has_promised(Pledge::promise)) { \
|
|
|
|
pledge_builder.append(#promise " "); \
|
|
|
|
}
|
2020-08-16 00:27:23 -07:00
|
|
|
ENUMERATE_PLEDGE_PROMISES
|
2020-01-11 21:07:00 +01:00
|
|
|
#undef __ENUMERATE_PLEDGE_PROMISE
|
|
|
|
|
2020-08-16 00:27:23 -07:00
|
|
|
process_object.add("pledge", pledge_builder.to_string());
|
|
|
|
|
|
|
|
switch (process.veil_state()) {
|
|
|
|
case VeilState::None:
|
|
|
|
process_object.add("veil", "None");
|
|
|
|
break;
|
|
|
|
case VeilState::Dropped:
|
|
|
|
process_object.add("veil", "Dropped");
|
|
|
|
break;
|
|
|
|
case VeilState::Locked:
|
|
|
|
process_object.add("veil", "Locked");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
process_object.add("pledge", String());
|
|
|
|
process_object.add("veil", String());
|
2020-01-21 18:56:23 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 17:32:34 +02:00
|
|
|
process_object.add("pid", process.pid().value());
|
2020-08-08 22:04:20 +02:00
|
|
|
process_object.add("pgid", process.tty() ? process.tty()->pgid().value() : 0);
|
|
|
|
process_object.add("pgp", process.pgid().value());
|
|
|
|
process_object.add("sid", process.sid().value());
|
2019-08-27 14:19:51 +03:00
|
|
|
process_object.add("uid", process.uid());
|
|
|
|
process_object.add("gid", process.gid());
|
2020-08-08 17:32:34 +02:00
|
|
|
process_object.add("ppid", process.ppid().value());
|
2019-08-27 14:19:51 +03:00
|
|
|
process_object.add("nfds", process.number_of_open_file_descriptors());
|
|
|
|
process_object.add("name", process.name());
|
|
|
|
process_object.add("tty", process.tty() ? process.tty()->tty_name() : "notty");
|
2020-05-22 13:58:37 +02:00
|
|
|
process_object.add("amount_virtual", process.amount_virtual());
|
|
|
|
process_object.add("amount_resident", process.amount_resident());
|
|
|
|
process_object.add("amount_dirty_private", process.amount_dirty_private());
|
|
|
|
process_object.add("amount_clean_inode", process.amount_clean_inode());
|
|
|
|
process_object.add("amount_shared", process.amount_shared());
|
|
|
|
process_object.add("amount_purgeable_volatile", process.amount_purgeable_volatile());
|
|
|
|
process_object.add("amount_purgeable_nonvolatile", process.amount_purgeable_nonvolatile());
|
2019-08-27 14:19:51 +03:00
|
|
|
process_object.add("icon_id", process.icon_id());
|
2019-11-26 21:25:45 +01:00
|
|
|
auto thread_array = process_object.add_array("threads");
|
|
|
|
process.for_each_thread([&](const Thread& thread) {
|
|
|
|
auto thread_object = thread_array.add_object();
|
2020-08-08 17:32:34 +02:00
|
|
|
thread_object.add("tid", thread.tid().value());
|
2019-12-07 12:45:26 -07:00
|
|
|
thread_object.add("name", thread.name());
|
2019-11-26 21:25:45 +01:00
|
|
|
thread_object.add("times_scheduled", thread.times_scheduled());
|
|
|
|
thread_object.add("ticks", thread.ticks());
|
|
|
|
thread_object.add("state", thread.state_string());
|
2020-06-27 22:36:15 -06:00
|
|
|
thread_object.add("cpu", thread.cpu());
|
2019-12-30 18:46:17 +01:00
|
|
|
thread_object.add("priority", thread.priority());
|
|
|
|
thread_object.add("effective_priority", thread.effective_priority());
|
2019-11-26 21:35:24 +01:00
|
|
|
thread_object.add("syscall_count", thread.syscall_count());
|
|
|
|
thread_object.add("inode_faults", thread.inode_faults());
|
|
|
|
thread_object.add("zero_faults", thread.zero_faults());
|
|
|
|
thread_object.add("cow_faults", thread.cow_faults());
|
2019-12-01 17:36:06 +01:00
|
|
|
thread_object.add("file_read_bytes", thread.file_read_bytes());
|
|
|
|
thread_object.add("file_write_bytes", thread.file_write_bytes());
|
|
|
|
thread_object.add("unix_socket_read_bytes", thread.unix_socket_read_bytes());
|
|
|
|
thread_object.add("unix_socket_write_bytes", thread.unix_socket_write_bytes());
|
|
|
|
thread_object.add("ipv4_socket_read_bytes", thread.ipv4_socket_read_bytes());
|
|
|
|
thread_object.add("ipv4_socket_write_bytes", thread.ipv4_socket_write_bytes());
|
2019-11-26 21:25:45 +01:00
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
2019-02-04 10:28:12 +01:00
|
|
|
};
|
2020-08-01 20:04:56 -06:00
|
|
|
|
|
|
|
ScopedSpinLock lock(g_scheduler_lock);
|
|
|
|
auto processes = Process::all_processes();
|
2019-06-29 09:04:45 +02:00
|
|
|
build_process(*Scheduler::colonel());
|
2020-08-01 20:04:56 -06:00
|
|
|
for (auto& process : processes)
|
|
|
|
build_process(process);
|
2019-08-27 14:19:51 +03:00
|
|
|
array.finish();
|
|
|
|
return builder.build();
|
2019-02-03 18:53:18 +01:00
|
|
|
}
|
|
|
|
|
Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.
I found these places by using -Wmissing-declarations.
The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
Not sure how to tell the compiler that the compiler is already using them.
Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-10 21:12:13 +02:00
|
|
|
static Optional<KBuffer> procfs$inodes(InodeIdentifier)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-08-07 21:52:43 +02:00
|
|
|
KBufferBuilder builder;
|
2019-08-08 11:08:27 +02:00
|
|
|
InterruptDisabler disabler;
|
2020-08-10 23:55:10 +02:00
|
|
|
for (auto& inode : Inode::all_with_lock()) {
|
2019-08-08 13:40:58 +02:00
|
|
|
builder.appendf("Inode{K%x} %02u:%08u (%u)\n", &inode, inode.fsid(), inode.index(), inode.ref_count());
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-08-07 21:52:43 +02:00
|
|
|
return builder.build();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
struct SysVariable {
|
|
|
|
String name;
|
|
|
|
enum class Type : u8 {
|
2019-02-03 12:33:11 +01:00
|
|
|
Invalid,
|
|
|
|
Boolean,
|
2019-02-08 09:46:46 +01:00
|
|
|
String,
|
2019-02-03 12:33:11 +01:00
|
|
|
};
|
2019-08-16 16:35:02 +03:00
|
|
|
Type type { Type::Invalid };
|
2019-02-03 12:33:11 +01:00
|
|
|
Function<void()> notify_callback;
|
2019-08-16 16:35:02 +03:00
|
|
|
void* address { nullptr };
|
|
|
|
|
|
|
|
static SysVariable& for_inode(InodeIdentifier);
|
|
|
|
|
|
|
|
void notify()
|
|
|
|
{
|
|
|
|
if (notify_callback)
|
|
|
|
notify_callback();
|
|
|
|
}
|
2019-02-03 12:33:11 +01:00
|
|
|
};
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
static Vector<SysVariable, 16>* s_sys_variables;
|
|
|
|
|
|
|
|
static inline Vector<SysVariable, 16>& sys_variables()
|
|
|
|
{
|
|
|
|
if (s_sys_variables == nullptr) {
|
|
|
|
s_sys_variables = new Vector<SysVariable, 16>;
|
|
|
|
s_sys_variables->append({ "", SysVariable::Type::Invalid, nullptr, nullptr });
|
|
|
|
}
|
|
|
|
return *s_sys_variables;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysVariable& SysVariable::for_inode(InodeIdentifier id)
|
|
|
|
{
|
|
|
|
auto index = to_sys_index(id);
|
|
|
|
if (index >= sys_variables().size())
|
|
|
|
return sys_variables()[0];
|
|
|
|
auto& variable = sys_variables()[index];
|
|
|
|
ASSERT(variable.address);
|
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2020-09-18 17:06:28 -06:00
|
|
|
static Optional<KBuffer> read_sys_bool(InodeIdentifier inode_id)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = SysVariable::for_inode(inode_id);
|
|
|
|
ASSERT(variable.type == SysVariable::Type::Boolean);
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
auto buffer = ByteBuffer::create_uninitialized(2);
|
2019-08-16 16:35:02 +03:00
|
|
|
auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(variable.address);
|
2019-02-08 16:18:24 +01:00
|
|
|
{
|
2020-04-18 12:50:35 +03:00
|
|
|
LOCKER(lockable_bool->lock(), Lock::Mode::Shared);
|
2019-02-08 16:18:24 +01:00
|
|
|
buffer[0] = lockable_bool->resource() ? '1' : '0';
|
|
|
|
}
|
2019-02-03 12:33:11 +01:00
|
|
|
buffer[1] = '\n';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
static ssize_t write_sys_bool(InodeIdentifier inode_id, const UserOrKernelBuffer& buffer, size_t size)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = SysVariable::for_inode(inode_id);
|
|
|
|
ASSERT(variable.type == SysVariable::Type::Boolean);
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
char value = 0;
|
|
|
|
bool did_read = false;
|
|
|
|
ssize_t nread = buffer.read_buffered<1>(1, [&](const u8* data, size_t) {
|
|
|
|
if (did_read)
|
|
|
|
return 0;
|
|
|
|
value = (char)data[0];
|
|
|
|
did_read = true;
|
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
if (nread < 0)
|
|
|
|
return nread;
|
|
|
|
ASSERT(nread == 0 || (nread == 1 && did_read));
|
|
|
|
if (nread == 0 || !(value == '0' || value == '1'))
|
|
|
|
return (ssize_t)size;
|
2019-02-08 16:18:24 +01:00
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(variable.address);
|
2019-02-08 16:18:24 +01:00
|
|
|
{
|
|
|
|
LOCKER(lockable_bool->lock());
|
2020-09-11 21:11:07 -06:00
|
|
|
lockable_bool->resource() = value == '1';
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-08-16 16:35:02 +03:00
|
|
|
variable.notify();
|
2020-09-11 21:11:07 -06:00
|
|
|
return (ssize_t)size;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-09-18 17:06:28 -06:00
|
|
|
static Optional<KBuffer> read_sys_string(InodeIdentifier inode_id)
|
2019-02-08 09:46:46 +01:00
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = SysVariable::for_inode(inode_id);
|
|
|
|
ASSERT(variable.type == SysVariable::Type::String);
|
|
|
|
|
|
|
|
auto* lockable_string = reinterpret_cast<Lockable<String>*>(variable.address);
|
2020-04-18 12:50:35 +03:00
|
|
|
LOCKER(lockable_string->lock(), Lock::Mode::Shared);
|
2019-02-08 09:46:46 +01:00
|
|
|
return lockable_string->resource().to_byte_buffer();
|
|
|
|
}
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
static ssize_t write_sys_string(InodeIdentifier inode_id, const UserOrKernelBuffer& buffer, size_t size)
|
2019-02-08 09:46:46 +01:00
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = SysVariable::for_inode(inode_id);
|
|
|
|
ASSERT(variable.type == SysVariable::Type::String);
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
auto string_copy = buffer.copy_into_string(size);
|
|
|
|
if (string_copy.is_null())
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-02-08 09:46:46 +01:00
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
auto* lockable_string = reinterpret_cast<Lockable<String>*>(variable.address);
|
2019-02-08 09:46:46 +01:00
|
|
|
LOCKER(lockable_string->lock());
|
2020-09-11 21:11:07 -06:00
|
|
|
lockable_string->resource() = move(string_copy);
|
2019-02-08 09:46:46 +01:00
|
|
|
}
|
2019-08-16 16:35:02 +03:00
|
|
|
variable.notify();
|
2020-09-11 21:11:07 -06:00
|
|
|
return (ssize_t)size;
|
2019-02-08 09:46:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:18:24 +01:00
|
|
|
void ProcFS::add_sys_bool(String&& name, Lockable<bool>& var, Function<void()>&& notify_callback)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
SysVariable variable;
|
|
|
|
variable.name = move(name);
|
|
|
|
variable.type = SysVariable::Type::Boolean;
|
|
|
|
variable.notify_callback = move(notify_callback);
|
|
|
|
variable.address = &var;
|
|
|
|
|
|
|
|
sys_variables().append(move(variable));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 09:46:46 +01:00
|
|
|
void ProcFS::add_sys_string(String&& name, Lockable<String>& var, Function<void()>&& notify_callback)
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
2019-08-16 16:35:02 +03:00
|
|
|
SysVariable variable;
|
|
|
|
variable.name = move(name);
|
|
|
|
variable.type = SysVariable::Type::String;
|
|
|
|
variable.notify_callback = move(notify_callback);
|
|
|
|
variable.address = &var;
|
|
|
|
|
|
|
|
sys_variables().append(move(variable));
|
2019-02-08 09:46:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
bool ProcFS::initialize()
|
|
|
|
{
|
2019-08-16 16:35:02 +03:00
|
|
|
static Lockable<bool>* kmalloc_stack_helper;
|
|
|
|
|
|
|
|
if (kmalloc_stack_helper == nullptr) {
|
|
|
|
kmalloc_stack_helper = new Lockable<bool>();
|
|
|
|
kmalloc_stack_helper->resource() = g_dump_kmalloc_stacks;
|
|
|
|
ProcFS::add_sys_bool("kmalloc_stacks", *kmalloc_stack_helper, [] {
|
|
|
|
g_dump_kmalloc_stacks = kmalloc_stack_helper->resource();
|
|
|
|
});
|
|
|
|
}
|
2019-02-03 12:33:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* ProcFS::class_name() const
|
|
|
|
{
|
|
|
|
return "ProcFS";
|
|
|
|
}
|
|
|
|
|
2020-06-24 23:35:56 +03:00
|
|
|
NonnullRefPtr<Inode> ProcFS::root_inode() const
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-06-24 23:35:56 +03:00
|
|
|
return *m_root_inode;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "ProcFS::get_inode(" << inode_id.index() << ")";
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
2020-06-24 23:35:56 +03:00
|
|
|
if (inode_id == root_inode()->identifier())
|
2019-02-03 12:33:11 +01:00
|
|
|
return m_root_inode;
|
|
|
|
|
|
|
|
LOCKER(m_inodes_lock);
|
|
|
|
auto it = m_inodes.find(inode_id.index());
|
|
|
|
if (it == m_inodes.end()) {
|
|
|
|
auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
|
|
|
|
m_inodes.set(inode_id.index(), inode.ptr());
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
return (*it).value;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcFSInode::ProcFSInode(ProcFS& fs, unsigned index)
|
|
|
|
: Inode(fs, index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcFSInode::~ProcFSInode()
|
|
|
|
{
|
|
|
|
LOCKER(fs().m_inodes_lock);
|
|
|
|
fs().m_inodes.remove(index());
|
|
|
|
}
|
|
|
|
|
|
|
|
InodeMetadata ProcFSInode::metadata() const
|
|
|
|
{
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "ProcFSInode::metadata(" << index() << ")";
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
InodeMetadata metadata;
|
|
|
|
metadata.inode = identifier();
|
|
|
|
metadata.ctime = mepoch;
|
|
|
|
metadata.atime = mepoch;
|
|
|
|
metadata.mtime = mepoch;
|
|
|
|
auto proc_parent_directory = to_proc_parent_directory(identifier());
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier());
|
|
|
|
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-08-27 00:58:09 +02:00
|
|
|
dbg() << " -> pid: " << to_pid(identifier()).value() << ", fi: " << proc_file_type << ", pdi: " << proc_parent_directory;
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (is_process_related_file(identifier())) {
|
2020-08-09 19:59:26 +02:00
|
|
|
ProcessID pid = to_pid(identifier());
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(pid);
|
|
|
|
if (process) {
|
|
|
|
metadata.uid = process->sys$getuid();
|
|
|
|
metadata.gid = process->sys$getgid();
|
|
|
|
} else {
|
|
|
|
// TODO: How to handle this?
|
|
|
|
metadata.uid = 0;
|
|
|
|
metadata.gid = 0;
|
|
|
|
}
|
2020-08-09 19:59:26 +02:00
|
|
|
} else if (is_thread_related_file(identifier())) {
|
|
|
|
ThreadID tid = to_tid(identifier());
|
|
|
|
auto thread = Thread::from_tid(tid);
|
|
|
|
if (thread) {
|
|
|
|
metadata.uid = thread->process().sys$getuid();
|
|
|
|
metadata.gid = thread->process().sys$getgid();
|
|
|
|
} else {
|
|
|
|
// TODO: How to handle this?
|
|
|
|
metadata.uid = 0;
|
|
|
|
metadata.gid = 0;
|
|
|
|
}
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_parent_directory == PDI_PID_fd) {
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFLNK | S_IRUSR | S_IWUSR | S_IXUSR;
|
2019-02-03 12:33:11 +01:00
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (proc_file_type) {
|
|
|
|
case FI_Root_self:
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH;
|
2019-12-31 01:23:03 +01:00
|
|
|
break;
|
2019-02-03 12:33:11 +01:00
|
|
|
case FI_PID_cwd:
|
|
|
|
case FI_PID_exe:
|
2020-01-10 23:48:44 +01:00
|
|
|
case FI_PID_root:
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFLNK | S_IRUSR;
|
2019-02-03 12:33:11 +01:00
|
|
|
break;
|
|
|
|
case FI_Root:
|
|
|
|
case FI_Root_sys:
|
2019-08-09 13:10:26 +03:00
|
|
|
case FI_Root_net:
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
2019-12-31 01:23:03 +01:00
|
|
|
break;
|
2019-02-03 12:33:11 +01:00
|
|
|
case FI_PID:
|
|
|
|
case FI_PID_fd:
|
2020-08-09 19:59:26 +02:00
|
|
|
case FI_PID_stacks:
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFDIR | S_IRUSR | S_IXUSR;
|
2019-02-03 12:33:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
2020-06-16 22:03:51 +03:00
|
|
|
metadata.mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
2019-02-03 12:33:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-12-31 01:23:03 +01:00
|
|
|
|
|
|
|
if (proc_file_type > FI_Invalid && proc_file_type < FI_MaxStaticFileIndex) {
|
2019-12-31 13:22:43 +01:00
|
|
|
if (fs().m_entries[proc_file_type].supervisor_only) {
|
|
|
|
metadata.uid = 0;
|
|
|
|
metadata.gid = 0;
|
2019-12-31 01:23:03 +01:00
|
|
|
metadata.mode &= ~077;
|
2019-12-31 13:22:43 +01:00
|
|
|
}
|
2019-12-31 01:23:03 +01:00
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "Returning mode " << String::format("%o", metadata.mode);
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer& buffer, FileDescription* description) const
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "ProcFS: read_bytes " << index();
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
ASSERT(offset >= 0);
|
2020-09-11 21:11:07 -06:00
|
|
|
ASSERT(buffer.user_or_kernel_ptr());
|
2019-02-03 12:33:11 +01:00
|
|
|
|
|
|
|
auto* directory_entry = fs().get_directory_entry(identifier());
|
|
|
|
|
2020-09-18 09:49:51 +02:00
|
|
|
Optional<KBuffer> (*read_callback)(InodeIdentifier) = nullptr;
|
2019-08-16 16:35:02 +03:00
|
|
|
if (directory_entry)
|
2020-09-18 17:06:28 -06:00
|
|
|
read_callback = directory_entry->read_callback;
|
2019-08-16 16:35:02 +03:00
|
|
|
else
|
|
|
|
switch (to_proc_parent_directory(identifier())) {
|
|
|
|
case PDI_PID_fd:
|
2020-09-18 17:06:28 -06:00
|
|
|
read_callback = procfs$pid_fd_entry;
|
2019-08-16 16:35:02 +03:00
|
|
|
break;
|
2020-08-09 19:59:26 +02:00
|
|
|
case PDI_PID_stacks:
|
2020-09-18 17:06:28 -06:00
|
|
|
read_callback = procfs$tid_stack;
|
2020-08-09 19:59:26 +02:00
|
|
|
break;
|
2019-08-16 16:35:02 +03:00
|
|
|
case PDI_Root_sys:
|
|
|
|
switch (SysVariable::for_inode(identifier()).type) {
|
|
|
|
case SysVariable::Type::Invalid:
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
case SysVariable::Type::Boolean:
|
2020-09-18 17:06:28 -06:00
|
|
|
read_callback = read_sys_bool;
|
2019-08-16 16:35:02 +03:00
|
|
|
break;
|
|
|
|
case SysVariable::Type::String:
|
2020-09-18 17:06:28 -06:00
|
|
|
read_callback = read_sys_string;
|
2019-08-16 16:35:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT_NOT_REACHED();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(read_callback);
|
|
|
|
|
2019-08-05 11:35:49 +02:00
|
|
|
Optional<KBuffer> generated_data;
|
2019-06-13 22:03:04 +02:00
|
|
|
if (!description) {
|
2020-09-18 17:06:28 -06:00
|
|
|
generated_data = read_callback(identifier());
|
2019-02-03 12:33:11 +01:00
|
|
|
} else {
|
2020-03-06 10:26:05 +01:00
|
|
|
if (!description->generator_cache().has_value())
|
2019-06-13 22:03:04 +02:00
|
|
|
description->generator_cache() = (*read_callback)(identifier());
|
|
|
|
generated_data = description->generator_cache();
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto& data = generated_data;
|
2020-01-08 12:49:36 +01:00
|
|
|
if (!data.has_value())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((size_t)offset >= data.value().size())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
|
2020-09-11 21:11:07 -06:00
|
|
|
if (!buffer.write(data.value().data() + offset, nread))
|
|
|
|
return -EFAULT;
|
2020-03-06 10:26:05 +01:00
|
|
|
if (nread == 0 && description && description->generator_cache().has_value())
|
2020-01-08 12:49:36 +01:00
|
|
|
description->generator_cache().clear();
|
2019-10-22 22:45:48 +13:00
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
InodeIdentifier ProcFS::ProcFSDirectoryEntry::identifier(unsigned fsid) const
|
|
|
|
{
|
|
|
|
return to_identifier(fsid, PDI_Root, 0, (ProcFileType)proc_file_type);
|
|
|
|
}
|
|
|
|
|
2020-08-18 12:41:27 +02:00
|
|
|
KResult ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntryView&)> callback) const
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
#ifdef PROCFS_DEBUG
|
2020-02-24 17:29:26 +02:00
|
|
|
dbg() << "ProcFS: traverse_as_directory " << index();
|
2019-02-03 12:33:11 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
if (!Kernel::is_directory(identifier()))
|
2020-05-26 00:36:11 -07:00
|
|
|
return KResult(-ENOTDIR);
|
2019-02-03 12:33:11 +01:00
|
|
|
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier());
|
|
|
|
auto parent_id = to_parent_id(identifier());
|
|
|
|
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ ".", identifier(), 2 });
|
|
|
|
callback({ "..", parent_id, 2 });
|
2019-02-03 12:33:11 +01:00
|
|
|
|
|
|
|
switch (proc_file_type) {
|
|
|
|
case FI_Root:
|
|
|
|
for (auto& entry : fs().m_entries) {
|
|
|
|
// FIXME: strlen() here is sad.
|
|
|
|
if (!entry.name)
|
|
|
|
continue;
|
|
|
|
if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End)
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ { entry.name, strlen(entry.name) }, to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type), 0 });
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
for (auto pid_child : Process::all_pids()) {
|
|
|
|
char name[16];
|
2020-08-16 07:51:56 +02:00
|
|
|
size_t name_length = (size_t)snprintf(name, sizeof(name), "%d", pid_child.value());
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ { name, name_length }, to_identifier(fsid(), PDI_Root, pid_child, FI_PID), 0 });
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FI_Root_sys:
|
2020-02-25 14:49:47 +01:00
|
|
|
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = sys_variables()[i];
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ variable.name, sys_var_to_identifier(fsid(), i), 0 });
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-08-09 13:10:26 +03:00
|
|
|
case FI_Root_net:
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ "adapters", to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_adapters), 0 });
|
|
|
|
callback({ "arp", to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_arp), 0 });
|
|
|
|
callback({ "tcp", to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_tcp), 0 });
|
|
|
|
callback({ "udp", to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_udp), 0 });
|
|
|
|
callback({ "local", to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_local), 0 });
|
2019-08-09 13:10:26 +03:00
|
|
|
break;
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
case FI_PID: {
|
2020-08-09 19:59:26 +02:00
|
|
|
auto pid = to_pid(identifier());
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(pid);
|
|
|
|
if (!process)
|
2020-05-26 00:36:11 -07:00
|
|
|
return KResult(-ENOENT);
|
2019-02-03 12:33:11 +01:00
|
|
|
for (auto& entry : fs().m_entries) {
|
|
|
|
if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
|
2020-08-01 20:04:56 -06:00
|
|
|
if (entry.proc_file_type == FI_PID_exe && !process->executable())
|
2019-02-21 16:19:07 +01:00
|
|
|
continue;
|
2019-02-03 12:33:11 +01:00
|
|
|
// FIXME: strlen() here is sad.
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ { entry.name, strlen(entry.name) }, to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 });
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-07 11:43:58 +02:00
|
|
|
} break;
|
2019-02-03 12:33:11 +01:00
|
|
|
|
|
|
|
case FI_PID_fd: {
|
2020-08-09 19:59:26 +02:00
|
|
|
auto pid = to_pid(identifier());
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(pid);
|
|
|
|
if (!process)
|
2020-05-26 00:36:11 -07:00
|
|
|
return KResult(-ENOENT);
|
2020-08-01 20:04:56 -06:00
|
|
|
for (int i = 0; i < process->max_open_file_descriptors(); ++i) {
|
|
|
|
auto description = process->file_description(i);
|
2019-06-13 22:03:04 +02:00
|
|
|
if (!description)
|
2019-02-03 12:33:11 +01:00
|
|
|
continue;
|
|
|
|
char name[16];
|
2020-08-16 07:51:56 +02:00
|
|
|
size_t name_length = (size_t)snprintf(name, sizeof(name), "%d", i);
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ { name, name_length }, to_identifier_with_fd(fsid(), pid, i), 0 });
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-06-07 11:43:58 +02:00
|
|
|
} break;
|
2020-08-09 19:59:26 +02:00
|
|
|
|
|
|
|
case FI_PID_stacks: {
|
|
|
|
auto pid = to_pid(identifier());
|
|
|
|
auto process = Process::from_pid(pid);
|
|
|
|
if (!process)
|
|
|
|
return KResult(-ENOENT);
|
|
|
|
process->for_each_thread([&](Thread& thread) -> IterationDecision {
|
|
|
|
int tid = thread.tid().value();
|
|
|
|
char name[16];
|
2020-08-16 07:51:56 +02:00
|
|
|
size_t name_length = (size_t)snprintf(name, sizeof(name), "%d", tid);
|
2020-08-18 12:41:27 +02:00
|
|
|
callback({ { name, name_length }, to_identifier_with_stack(fsid(), tid), 0 });
|
2020-08-09 19:59:26 +02:00
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
|
|
|
} break;
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
default:
|
2020-05-26 00:36:11 -07:00
|
|
|
return KSuccess;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-05-26 00:36:11 -07:00
|
|
|
return KSuccess;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 09:23:46 +01:00
|
|
|
RefPtr<Inode> ProcFSInode::lookup(StringView name)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
ASSERT(is_directory());
|
|
|
|
if (name == ".")
|
2020-06-24 23:35:56 +03:00
|
|
|
return this;
|
2019-02-03 12:33:11 +01:00
|
|
|
if (name == "..")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_parent_id(identifier()));
|
2019-02-03 12:33:11 +01:00
|
|
|
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier());
|
|
|
|
|
|
|
|
if (proc_file_type == FI_Root) {
|
|
|
|
for (auto& entry : fs().m_entries) {
|
|
|
|
if (entry.name == nullptr)
|
|
|
|
continue;
|
|
|
|
if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End) {
|
2019-06-12 16:25:28 +03:00
|
|
|
if (name == entry.name) {
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 21:07:52 +02:00
|
|
|
auto name_as_number = name.to_uint();
|
|
|
|
if (!name_as_number.has_value())
|
|
|
|
return {};
|
|
|
|
bool process_exists = false;
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
process_exists = Process::from_pid(name_as_number.value());
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2020-06-12 21:07:52 +02:00
|
|
|
if (process_exists)
|
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, name_as_number.value(), FI_PID));
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_file_type == FI_Root_sys) {
|
2020-02-25 14:49:47 +01:00
|
|
|
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
2019-08-16 16:35:02 +03:00
|
|
|
auto& variable = sys_variables()[i];
|
|
|
|
if (name == variable.name)
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(sys_var_to_identifier(fsid(), i));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-09 13:10:26 +03:00
|
|
|
if (proc_file_type == FI_Root_net) {
|
|
|
|
if (name == "adapters")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, FI_Root_net_adapters));
|
2019-09-02 15:41:18 +10:00
|
|
|
if (name == "arp")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, FI_Root_net_arp));
|
2019-08-09 13:10:26 +03:00
|
|
|
if (name == "tcp")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, FI_Root_net_tcp));
|
2019-08-09 13:27:40 +03:00
|
|
|
if (name == "udp")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, FI_Root_net_udp));
|
2019-08-10 19:11:35 +03:00
|
|
|
if (name == "local")
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_Root, 0, FI_Root_net_local));
|
2019-08-09 13:10:26 +03:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
if (proc_file_type == FI_PID) {
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(to_pid(identifier()));
|
|
|
|
if (!process)
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
for (auto& entry : fs().m_entries) {
|
|
|
|
if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
|
2020-08-01 20:04:56 -06:00
|
|
|
if (entry.proc_file_type == FI_PID_exe && !process->executable())
|
2019-02-21 16:19:07 +01:00
|
|
|
continue;
|
2019-02-03 12:33:11 +01:00
|
|
|
if (entry.name == nullptr)
|
|
|
|
continue;
|
2019-06-12 16:25:28 +03:00
|
|
|
if (name == entry.name) {
|
2020-02-01 09:23:46 +01:00
|
|
|
return fs().get_inode(to_identifier(fsid(), PDI_PID, to_pid(identifier()), (ProcFileType)entry.proc_file_type));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_file_type == FI_PID_fd) {
|
2020-06-12 21:07:52 +02:00
|
|
|
auto name_as_number = name.to_uint();
|
|
|
|
if (!name_as_number.has_value())
|
|
|
|
return {};
|
|
|
|
bool fd_exists = false;
|
|
|
|
{
|
2020-08-01 20:04:56 -06:00
|
|
|
if (auto process = Process::from_pid(to_pid(identifier())))
|
2020-06-12 21:07:52 +02:00
|
|
|
fd_exists = process->file_description(name_as_number.value());
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2020-06-12 21:07:52 +02:00
|
|
|
if (fd_exists)
|
|
|
|
return fs().get_inode(to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number.value()));
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
2020-08-09 19:59:26 +02:00
|
|
|
|
|
|
|
if (proc_file_type == FI_PID_stacks) {
|
|
|
|
auto name_as_number = name.to_int();
|
|
|
|
if (!name_as_number.has_value())
|
|
|
|
return {};
|
|
|
|
int tid = name_as_number.value();
|
|
|
|
if (tid <= 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
bool thread_exists = false;
|
|
|
|
{
|
|
|
|
auto process = Process::from_pid(to_pid(identifier()));
|
|
|
|
auto thread = Thread::from_tid(tid);
|
|
|
|
thread_exists = process && thread && process->pid() == thread->pid();
|
|
|
|
}
|
|
|
|
if (thread_exists)
|
|
|
|
return fs().get_inode(to_identifier_with_stack(fsid(), tid));
|
|
|
|
}
|
|
|
|
|
2019-06-07 11:43:58 +02:00
|
|
|
return {};
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcFSInode::flush_metadata()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-11 21:11:07 -06:00
|
|
|
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const UserOrKernelBuffer& buffer, FileDescription*)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2020-04-04 19:46:55 +02:00
|
|
|
auto result = prepare_to_write_data();
|
|
|
|
if (result.is_error())
|
|
|
|
return result;
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
auto* directory_entry = fs().get_directory_entry(identifier());
|
2019-08-16 16:35:02 +03:00
|
|
|
|
2020-09-18 09:49:51 +02:00
|
|
|
ssize_t (*write_callback)(InodeIdentifier, const UserOrKernelBuffer&, size_t) = nullptr;
|
2019-08-16 16:35:02 +03:00
|
|
|
|
|
|
|
if (directory_entry == nullptr) {
|
|
|
|
if (to_proc_parent_directory(identifier()) == PDI_Root_sys) {
|
|
|
|
switch (SysVariable::for_inode(identifier()).type) {
|
|
|
|
case SysVariable::Type::Invalid:
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
case SysVariable::Type::Boolean:
|
2020-09-18 17:06:28 -06:00
|
|
|
write_callback = write_sys_bool;
|
2019-08-16 16:35:02 +03:00
|
|
|
break;
|
|
|
|
case SysVariable::Type::String:
|
2020-09-18 17:06:28 -06:00
|
|
|
write_callback = write_sys_string;
|
2019-08-16 16:35:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return -EPERM;
|
|
|
|
} else {
|
|
|
|
if (!directory_entry->write_callback)
|
|
|
|
return -EPERM;
|
2020-09-18 17:06:28 -06:00
|
|
|
write_callback = directory_entry->write_callback;
|
2019-08-16 16:35:02 +03:00
|
|
|
}
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
ASSERT(is_persistent_inode(identifier()));
|
|
|
|
// FIXME: Being able to write into ProcFS at a non-zero offset seems like something we should maybe support..
|
|
|
|
ASSERT(offset == 0);
|
2020-09-18 17:06:28 -06:00
|
|
|
ssize_t nwritten = write_callback(identifier(), buffer, (size_t)size);
|
2020-09-11 21:11:07 -06:00
|
|
|
if (nwritten < 0)
|
|
|
|
klog() << "ProcFS: Writing " << size << " bytes failed: " << nwritten;
|
|
|
|
return nwritten;
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:05:02 +03:00
|
|
|
KResultOr<NonnullRefPtr<Custody>> ProcFSInode::resolve_as_link(Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level) const
|
|
|
|
{
|
2020-08-09 19:59:26 +02:00
|
|
|
// The only links are in pid directories, so it's safe to ignore
|
|
|
|
// unrelated files and the thread-specific stacks/ directory.
|
2020-01-15 14:05:02 +03:00
|
|
|
if (!is_process_related_file(identifier()))
|
|
|
|
return Inode::resolve_as_link(base, out_parent, options, symlink_recursion_level);
|
|
|
|
|
|
|
|
// FIXME: We should return a custody for FI_PID or FI_PID_fd here
|
|
|
|
// for correctness. It's impossible to create files in ProcFS,
|
|
|
|
// so returning null shouldn't break much.
|
|
|
|
if (out_parent)
|
|
|
|
*out_parent = nullptr;
|
|
|
|
|
|
|
|
auto pid = to_pid(identifier());
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier());
|
2020-08-01 20:04:56 -06:00
|
|
|
auto process = Process::from_pid(pid);
|
|
|
|
if (!process)
|
2020-01-15 14:05:02 +03:00
|
|
|
return KResult(-ENOENT);
|
|
|
|
|
|
|
|
if (to_proc_parent_directory(identifier()) == PDI_PID_fd) {
|
|
|
|
if (out_parent)
|
|
|
|
*out_parent = base;
|
|
|
|
int fd = to_fd(identifier());
|
2020-08-01 20:04:56 -06:00
|
|
|
auto description = process->file_description(fd);
|
2020-01-15 14:05:02 +03:00
|
|
|
if (!description)
|
|
|
|
return KResult(-ENOENT);
|
|
|
|
auto proxy_inode = ProcFSProxyInode::create(const_cast<ProcFS&>(fs()), *description);
|
|
|
|
return Custody::create(&base, "", proxy_inode, base.mount_flags());
|
|
|
|
}
|
|
|
|
|
|
|
|
Custody* res = nullptr;
|
|
|
|
|
|
|
|
switch (proc_file_type) {
|
|
|
|
case FI_PID_cwd:
|
2020-08-01 20:04:56 -06:00
|
|
|
res = &process->current_directory();
|
2020-01-15 14:05:02 +03:00
|
|
|
break;
|
|
|
|
case FI_PID_exe:
|
2020-08-01 20:04:56 -06:00
|
|
|
res = process->executable();
|
2020-01-15 14:05:02 +03:00
|
|
|
break;
|
|
|
|
case FI_PID_root:
|
|
|
|
// Note: we open root_directory() here, not
|
|
|
|
// root_directory_relative_to_global_root().
|
|
|
|
// This seems more useful.
|
2020-08-01 20:04:56 -06:00
|
|
|
res = &process->root_directory();
|
2020-01-15 14:05:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
return KResult(-ENOENT);
|
|
|
|
|
|
|
|
return *res;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcFSProxyInode::ProcFSProxyInode(ProcFS& fs, FileDescription& fd)
|
|
|
|
: Inode(fs, 0)
|
|
|
|
, m_fd(fd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcFSProxyInode::~ProcFSProxyInode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InodeMetadata ProcFSProxyInode::metadata() const
|
|
|
|
{
|
|
|
|
InodeMetadata metadata = m_fd->metadata();
|
|
|
|
|
|
|
|
if (m_fd->is_readable())
|
|
|
|
metadata.mode |= 0444;
|
|
|
|
else
|
|
|
|
metadata.mode &= ~0444;
|
|
|
|
|
|
|
|
if (m_fd->is_writable())
|
|
|
|
metadata.mode |= 0222;
|
|
|
|
else
|
|
|
|
metadata.mode &= ~0222;
|
|
|
|
|
|
|
|
if (!metadata.is_directory())
|
|
|
|
metadata.mode &= ~0111;
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
2020-06-24 23:35:56 +03:00
|
|
|
KResultOr<NonnullRefPtr<Inode>> ProcFSProxyInode::create_child(const String& name, mode_t mode, dev_t dev, uid_t uid, gid_t gid)
|
|
|
|
{
|
|
|
|
if (!m_fd->inode())
|
|
|
|
return KResult(-EINVAL);
|
|
|
|
return m_fd->inode()->create_child(name, mode, dev, uid, gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
KResult ProcFSProxyInode::add_child(Inode& child, const StringView& name, mode_t mode)
|
2020-01-15 14:05:02 +03:00
|
|
|
{
|
|
|
|
if (!m_fd->inode())
|
|
|
|
return KResult(-EINVAL);
|
2020-06-24 23:35:56 +03:00
|
|
|
return m_fd->inode()->add_child(child, name, mode);
|
2020-01-15 14:05:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
KResult ProcFSProxyInode::remove_child(const StringView& name)
|
|
|
|
{
|
|
|
|
if (!m_fd->inode())
|
|
|
|
return KResult(-EINVAL);
|
|
|
|
return m_fd->inode()->remove_child(name);
|
|
|
|
}
|
|
|
|
|
2020-02-01 09:23:46 +01:00
|
|
|
RefPtr<Inode> ProcFSProxyInode::lookup(StringView name)
|
2020-01-15 14:05:02 +03:00
|
|
|
{
|
|
|
|
if (!m_fd->inode())
|
|
|
|
return {};
|
|
|
|
return m_fd->inode()->lookup(name);
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:00:18 -07:00
|
|
|
KResultOr<size_t> ProcFSProxyInode::directory_entry_count() const
|
2020-01-15 14:05:02 +03:00
|
|
|
{
|
|
|
|
if (!m_fd->inode())
|
2020-08-05 01:00:18 -07:00
|
|
|
return KResult(-EINVAL);
|
2020-01-15 14:05:02 +03:00
|
|
|
return m_fd->inode()->directory_entry_count();
|
|
|
|
}
|
|
|
|
|
2020-06-24 23:35:56 +03:00
|
|
|
KResultOr<NonnullRefPtr<Inode>> ProcFSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t)
|
|
|
|
{
|
|
|
|
return KResult(-EPERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
KResult ProcFSInode::add_child(Inode&, const StringView&, mode_t)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-02-27 15:31:26 +01:00
|
|
|
return KResult(-EPERM);
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2019-06-09 10:25:19 +02:00
|
|
|
KResult ProcFSInode::remove_child(const StringView& name)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-02-25 20:47:56 +01:00
|
|
|
(void)name;
|
2019-02-27 14:11:25 +01:00
|
|
|
return KResult(-EPERM);
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-05 01:00:18 -07:00
|
|
|
KResultOr<size_t> ProcFSInode::directory_entry_count() const
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
|
|
|
ASSERT(is_directory());
|
|
|
|
size_t count = 0;
|
2020-08-18 12:41:27 +02:00
|
|
|
KResult result = traverse_as_directory([&count](auto&) {
|
2019-02-03 12:33:11 +01:00
|
|
|
++count;
|
|
|
|
return true;
|
|
|
|
});
|
2020-08-05 01:00:18 -07:00
|
|
|
|
|
|
|
if (result.is_error())
|
|
|
|
return result;
|
|
|
|
|
2019-02-03 12:33:11 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-02-25 20:47:56 +01:00
|
|
|
KResult ProcFSInode::chmod(mode_t)
|
2019-02-03 12:33:11 +01:00
|
|
|
{
|
2019-02-25 20:47:56 +01:00
|
|
|
return KResult(-EPERM);
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcFS::ProcFS()
|
|
|
|
{
|
|
|
|
m_root_inode = adopt(*new ProcFSInode(*this, 1));
|
|
|
|
m_entries.resize(FI_MaxStaticFileIndex);
|
2019-12-31 01:23:03 +01:00
|
|
|
m_entries[FI_Root_mm] = { "mm", FI_Root_mm, true, procfs$mm };
|
|
|
|
m_entries[FI_Root_mounts] = { "mounts", FI_Root_mounts, false, procfs$mounts };
|
|
|
|
m_entries[FI_Root_df] = { "df", FI_Root_df, false, procfs$df };
|
|
|
|
m_entries[FI_Root_all] = { "all", FI_Root_all, false, procfs$all };
|
|
|
|
m_entries[FI_Root_memstat] = { "memstat", FI_Root_memstat, false, procfs$memstat };
|
|
|
|
m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, false, procfs$cpuinfo };
|
|
|
|
m_entries[FI_Root_inodes] = { "inodes", FI_Root_inodes, true, procfs$inodes };
|
|
|
|
m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, true, procfs$dmesg };
|
|
|
|
m_entries[FI_Root_self] = { "self", FI_Root_self, false, procfs$self };
|
|
|
|
m_entries[FI_Root_pci] = { "pci", FI_Root_pci, false, procfs$pci };
|
2020-02-22 20:51:50 +02:00
|
|
|
m_entries[FI_Root_interrupts] = { "interrupts", FI_Root_interrupts, false, procfs$interrupts };
|
2020-08-06 02:04:56 +03:00
|
|
|
m_entries[FI_Root_keymap] = { "keymap", FI_Root_keymap, false, procfs$keymap };
|
2019-12-31 01:23:03 +01:00
|
|
|
m_entries[FI_Root_devices] = { "devices", FI_Root_devices, false, procfs$devices };
|
|
|
|
m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, false, procfs$uptime };
|
|
|
|
m_entries[FI_Root_cmdline] = { "cmdline", FI_Root_cmdline, true, procfs$cmdline };
|
|
|
|
m_entries[FI_Root_modules] = { "modules", FI_Root_modules, true, procfs$modules };
|
|
|
|
m_entries[FI_Root_profile] = { "profile", FI_Root_profile, false, procfs$profile };
|
|
|
|
m_entries[FI_Root_sys] = { "sys", FI_Root_sys, true };
|
|
|
|
m_entries[FI_Root_net] = { "net", FI_Root_net, false };
|
|
|
|
|
|
|
|
m_entries[FI_Root_net_adapters] = { "adapters", FI_Root_net_adapters, false, procfs$net_adapters };
|
|
|
|
m_entries[FI_Root_net_arp] = { "arp", FI_Root_net_arp, true, procfs$net_arp };
|
|
|
|
m_entries[FI_Root_net_tcp] = { "tcp", FI_Root_net_tcp, false, procfs$net_tcp };
|
|
|
|
m_entries[FI_Root_net_udp] = { "udp", FI_Root_net_udp, false, procfs$net_udp };
|
|
|
|
m_entries[FI_Root_net_local] = { "local", FI_Root_net_local, false, procfs$net_local };
|
|
|
|
|
|
|
|
m_entries[FI_PID_vm] = { "vm", FI_PID_vm, false, procfs$pid_vm };
|
|
|
|
m_entries[FI_PID_vmobjects] = { "vmobjects", FI_PID_vmobjects, true, procfs$pid_vmobjects };
|
2020-08-09 19:59:26 +02:00
|
|
|
m_entries[FI_PID_stacks] = { "stacks", FI_PID_stacks, false };
|
2019-12-31 01:23:03 +01:00
|
|
|
m_entries[FI_PID_fds] = { "fds", FI_PID_fds, false, procfs$pid_fds };
|
|
|
|
m_entries[FI_PID_exe] = { "exe", FI_PID_exe, false, procfs$pid_exe };
|
|
|
|
m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, false, procfs$pid_cwd };
|
2020-01-20 22:19:02 +01:00
|
|
|
m_entries[FI_PID_unveil] = { "unveil", FI_PID_unveil, false, procfs$pid_unveil };
|
2020-01-10 23:48:44 +01:00
|
|
|
m_entries[FI_PID_root] = { "root", FI_PID_root, false, procfs$pid_root };
|
2019-12-31 01:23:03 +01:00
|
|
|
m_entries[FI_PID_fd] = { "fd", FI_PID_fd, false };
|
2019-02-03 12:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identifier) const
|
|
|
|
{
|
|
|
|
auto proc_file_type = to_proc_file_type(identifier);
|
2019-08-16 16:35:02 +03:00
|
|
|
if (proc_file_type != FI_Invalid && proc_file_type != FI_Root_sys_variable && proc_file_type < FI_MaxStaticFileIndex)
|
2019-02-03 12:33:11 +01:00
|
|
|
return const_cast<ProcFSDirectoryEntry*>(&m_entries[proc_file_type]);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-27 12:32:53 +01:00
|
|
|
|
|
|
|
KResult ProcFSInode::chown(uid_t, gid_t)
|
|
|
|
{
|
|
|
|
return KResult(-EPERM);
|
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|