ProcFS.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. #include "ProcFS.h"
  2. #include "Process.h"
  3. #include <Kernel/FileSystem/VirtualFileSystem.h>
  4. #include <Kernel/VM/MemoryManager.h>
  5. #include "StdLib.h"
  6. #include "i386.h"
  7. #include "KSyms.h"
  8. #include "Console.h"
  9. #include "Scheduler.h"
  10. #include <Kernel/PCI.h>
  11. #include <Kernel/kmalloc.h>
  12. #include <AK/StringBuilder.h>
  13. #include <LibC/errno_numbers.h>
  14. enum ProcParentDirectory {
  15. PDI_AbstractRoot = 0,
  16. PDI_Root,
  17. PDI_Root_sys,
  18. PDI_PID,
  19. PDI_PID_fd,
  20. };
  21. enum ProcFileType {
  22. FI_Invalid = 0,
  23. FI_Root = 1, // directory
  24. __FI_Root_Start,
  25. FI_Root_mm,
  26. FI_Root_mounts,
  27. FI_Root_df,
  28. FI_Root_kmalloc,
  29. FI_Root_all,
  30. FI_Root_memstat,
  31. FI_Root_summary,
  32. FI_Root_cpuinfo,
  33. FI_Root_inodes,
  34. FI_Root_dmesg,
  35. FI_Root_pci,
  36. FI_Root_uptime,
  37. FI_Root_self, // symlink
  38. FI_Root_sys, // directory
  39. __FI_Root_End,
  40. FI_PID,
  41. __FI_PID_Start,
  42. FI_PID_vm,
  43. FI_PID_vmo,
  44. FI_PID_stack,
  45. FI_PID_regs,
  46. FI_PID_fds,
  47. FI_PID_exe, // symlink
  48. FI_PID_cwd, // symlink
  49. FI_PID_fd, // directory
  50. __FI_PID_End,
  51. FI_MaxStaticFileIndex,
  52. };
  53. static inline pid_t to_pid(const InodeIdentifier& identifier)
  54. {
  55. #ifdef PROCFS_DEBUG
  56. dbgprintf("to_pid, index=%08x -> %u\n", identifier.index(), identifier.index() >> 16);
  57. #endif
  58. return identifier.index() >> 16u;
  59. }
  60. static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier& identifier)
  61. {
  62. return (ProcParentDirectory)((identifier.index() >> 12) & 0xf);
  63. }
  64. static inline int to_fd(const InodeIdentifier& identifier)
  65. {
  66. ASSERT(to_proc_parent_directory(identifier) == PDI_PID_fd);
  67. return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
  68. }
  69. static inline unsigned to_sys_index(const InodeIdentifier& identifier)
  70. {
  71. ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
  72. return identifier.index() & 0xff;
  73. }
  74. static inline InodeIdentifier to_identifier(unsigned fsid, ProcParentDirectory parent, pid_t pid, ProcFileType proc_file_type)
  75. {
  76. return { fsid, ((unsigned)parent << 12u) | ((unsigned)pid << 16u) | (unsigned)proc_file_type };
  77. }
  78. static inline InodeIdentifier to_identifier_with_fd(unsigned fsid, pid_t pid, int fd)
  79. {
  80. return { fsid, (PDI_PID_fd << 12u) | ((unsigned)pid << 16u) | (FI_MaxStaticFileIndex + fd) };
  81. }
  82. static inline InodeIdentifier sys_var_to_identifier(unsigned fsid, unsigned index)
  83. {
  84. ASSERT(index < 256);
  85. return { fsid, (PDI_Root_sys << 12u) | index };
  86. }
  87. static inline InodeIdentifier to_parent_id(const InodeIdentifier& identifier)
  88. {
  89. switch (to_proc_parent_directory(identifier)) {
  90. case PDI_AbstractRoot:
  91. case PDI_Root:
  92. return { identifier.fsid(), FI_Root };
  93. case PDI_Root_sys:
  94. return { identifier.fsid(), FI_Root_sys };
  95. case PDI_PID:
  96. return to_identifier(identifier.fsid(), PDI_Root, to_pid(identifier), FI_PID);
  97. case PDI_PID_fd:
  98. return to_identifier(identifier.fsid(), PDI_PID, to_pid(identifier), FI_PID_fd);
  99. }
  100. ASSERT_NOT_REACHED();
  101. }
  102. #if 0
  103. static inline byte to_unused_metadata(const InodeIdentifier& identifier)
  104. {
  105. return (identifier.index() >> 8) & 0xf;
  106. }
  107. #endif
  108. static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
  109. {
  110. return (ProcFileType)(identifier.index() & 0xff);
  111. }
  112. static inline bool is_process_related_file(const InodeIdentifier& identifier)
  113. {
  114. if (to_proc_file_type(identifier) == FI_PID)
  115. return true;
  116. auto proc_parent_directory = to_proc_parent_directory(identifier);
  117. switch (proc_parent_directory) {
  118. case PDI_PID:
  119. case PDI_PID_fd:
  120. return true;
  121. default:
  122. return false;
  123. }
  124. }
  125. static inline bool is_directory(const InodeIdentifier& identifier)
  126. {
  127. auto proc_file_type = to_proc_file_type(identifier);
  128. switch (proc_file_type) {
  129. case FI_Root:
  130. case FI_Root_sys:
  131. case FI_PID:
  132. case FI_PID_fd:
  133. return true;
  134. default:
  135. return false;
  136. }
  137. }
  138. static inline bool is_persistent_inode(const InodeIdentifier& identifier)
  139. {
  140. return to_proc_parent_directory(identifier) == PDI_Root_sys;
  141. }
  142. static ProcFS* s_the;
  143. ProcFS& ProcFS::the()
  144. {
  145. ASSERT(s_the);
  146. return *s_the;
  147. }
  148. Retained<ProcFS> ProcFS::create()
  149. {
  150. return adopt(*new ProcFS);
  151. }
  152. ProcFS::~ProcFS()
  153. {
  154. }
  155. ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
  156. {
  157. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  158. if (!handle)
  159. return { };
  160. auto& process = handle->process();
  161. if (process.number_of_open_file_descriptors() == 0)
  162. return { };
  163. StringBuilder builder;
  164. for (size_t i = 0; i < process.max_open_file_descriptors(); ++i) {
  165. auto* descriptor = process.file_descriptor(i);
  166. if (!descriptor)
  167. continue;
  168. auto result = descriptor->absolute_path();
  169. if (result.is_error())
  170. continue;
  171. builder.appendf("% 3u %s\n", i, result.value().characters());
  172. }
  173. return builder.to_byte_buffer();
  174. }
  175. ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)
  176. {
  177. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  178. if (!handle)
  179. return { };
  180. auto& process = handle->process();
  181. int fd = to_fd(identifier);
  182. auto* descriptor = process.file_descriptor(fd);
  183. if (!descriptor)
  184. return { };
  185. auto result = descriptor->absolute_path();
  186. if (result.is_error())
  187. return { };
  188. return result.value().to_byte_buffer();
  189. }
  190. ByteBuffer procfs$pid_vm(InodeIdentifier identifier)
  191. {
  192. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  193. if (!handle)
  194. return { };
  195. auto& process = handle->process();
  196. StringBuilder builder;
  197. builder.appendf("BEGIN END SIZE COMMIT FLAGS NAME\n");
  198. for (auto& region : process.regions()) {
  199. StringBuilder flags_builder;
  200. if (region->is_readable())
  201. flags_builder.append('R');
  202. if (region->is_writable())
  203. flags_builder.append('W');
  204. if (region->is_bitmap())
  205. flags_builder.append('B');
  206. builder.appendf("%x -- %x %x %x % 4s %s\n",
  207. region->laddr().get(),
  208. region->laddr().offset(region->size() - 1).get(),
  209. region->size(),
  210. region->amount_resident(),
  211. flags_builder.to_string().characters(),
  212. region->name().characters());
  213. }
  214. return builder.to_byte_buffer();
  215. }
  216. ByteBuffer procfs$pci(InodeIdentifier)
  217. {
  218. StringBuilder builder;
  219. PCI::enumerate_all([&builder] (PCI::Address address, PCI::ID id) {
  220. builder.appendf("%b:%b.%b %w:%w\n", address.bus(), address.slot(), address.function(), id.vendor_id, id.device_id);
  221. });
  222. return builder.to_byte_buffer();
  223. }
  224. ByteBuffer procfs$uptime(InodeIdentifier)
  225. {
  226. StringBuilder builder;
  227. builder.appendf("%u\n", (dword)(g_uptime / 1000));
  228. return builder.to_byte_buffer();
  229. }
  230. ByteBuffer procfs$pid_vmo(InodeIdentifier identifier)
  231. {
  232. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  233. if (!handle)
  234. return { };
  235. auto& process = handle->process();
  236. StringBuilder builder;
  237. builder.appendf("BEGIN END SIZE NAME\n");
  238. for (auto& region : process.regions()) {
  239. builder.appendf("%x -- %x %x %s\n",
  240. region->laddr().get(),
  241. region->laddr().offset(region->size() - 1).get(),
  242. region->size(),
  243. region->name().characters());
  244. builder.appendf("VMO: %s \"%s\" @ %x(%u)\n",
  245. region->vmo().is_anonymous() ? "anonymous" : "file-backed",
  246. region->vmo().name().characters(),
  247. &region->vmo(),
  248. region->vmo().retain_count());
  249. for (size_t i = 0; i < region->vmo().page_count(); ++i) {
  250. auto& physical_page = region->vmo().physical_pages()[i];
  251. builder.appendf("P%x%s(%u) ",
  252. physical_page ? physical_page->paddr().get() : 0,
  253. region->cow_map().get(i) ? "!" : "",
  254. physical_page ? physical_page->retain_count() : 0
  255. );
  256. }
  257. builder.appendf("\n");
  258. }
  259. return builder.to_byte_buffer();
  260. }
  261. ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
  262. {
  263. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  264. if (!handle)
  265. return { };
  266. auto& process = handle->process();
  267. ProcessPagingScope paging_scope(process);
  268. struct RecognizedSymbol {
  269. dword address;
  270. const KSym* ksym;
  271. };
  272. StringBuilder builder;
  273. process.for_each_thread([&] (Thread& thread) {
  274. builder.appendf("Thread %d:\n", thread.tid());
  275. Vector<RecognizedSymbol> recognized_symbols;
  276. if (auto* eip_ksym = ksymbolicate(thread.tss().eip))
  277. recognized_symbols.append({ thread.tss().eip, eip_ksym });
  278. for (dword* stack_ptr = (dword*)thread.frame_ptr(); process.validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
  279. dword retaddr = stack_ptr[1];
  280. if (auto* ksym = ksymbolicate(retaddr))
  281. recognized_symbols.append({ retaddr, ksym });
  282. }
  283. for (auto& symbol : recognized_symbols) {
  284. unsigned offset = symbol.address - symbol.ksym->address;
  285. builder.appendf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
  286. }
  287. return IterationDecision::Continue;
  288. });
  289. return builder.to_byte_buffer();
  290. }
  291. ByteBuffer procfs$pid_regs(InodeIdentifier identifier)
  292. {
  293. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  294. if (!handle)
  295. return { };
  296. auto& process = handle->process();
  297. StringBuilder builder;
  298. process.for_each_thread([&] (Thread& thread) {
  299. builder.appendf("Thread %d:\n", thread.tid());
  300. auto& tss = thread.tss();
  301. builder.appendf("eax: %x\n", tss.eax);
  302. builder.appendf("ebx: %x\n", tss.ebx);
  303. builder.appendf("ecx: %x\n", tss.ecx);
  304. builder.appendf("edx: %x\n", tss.edx);
  305. builder.appendf("esi: %x\n", tss.esi);
  306. builder.appendf("edi: %x\n", tss.edi);
  307. builder.appendf("ebp: %x\n", tss.ebp);
  308. builder.appendf("cr3: %x\n", tss.cr3);
  309. builder.appendf("flg: %x\n", tss.eflags);
  310. builder.appendf("sp: %w:%x\n", tss.ss, tss.esp);
  311. builder.appendf("pc: %w:%x\n", tss.cs, tss.eip);
  312. return IterationDecision::Continue;
  313. });
  314. return builder.to_byte_buffer();
  315. }
  316. ByteBuffer procfs$pid_exe(InodeIdentifier identifier)
  317. {
  318. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  319. if (!handle)
  320. return { };
  321. auto& process = handle->process();
  322. auto inode = process.executable_inode();
  323. ASSERT(inode);
  324. auto result = VFS::the().absolute_path(*inode);
  325. if (result.is_error())
  326. return { };
  327. return result.value().to_byte_buffer();
  328. }
  329. ByteBuffer procfs$pid_cwd(InodeIdentifier identifier)
  330. {
  331. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  332. if (!handle)
  333. return { };
  334. auto result = VFS::the().absolute_path(handle->process().cwd_inode());
  335. if (result.is_error())
  336. return { };
  337. return result.value().to_byte_buffer();
  338. }
  339. ByteBuffer procfs$self(InodeIdentifier)
  340. {
  341. char buffer[16];
  342. ksprintf(buffer, "%u", current->pid());
  343. return ByteBuffer::copy((const byte*)buffer, strlen(buffer));
  344. }
  345. ByteBuffer procfs$mm(InodeIdentifier)
  346. {
  347. // FIXME: Implement
  348. InterruptDisabler disabler;
  349. StringBuilder builder;
  350. for (auto* vmo : MM.m_vmos) {
  351. builder.appendf("VMO: %p %s(%u): p:%4u %s\n",
  352. vmo,
  353. vmo->is_anonymous() ? "anon" : "file",
  354. vmo->retain_count(),
  355. vmo->page_count(),
  356. vmo->name().characters());
  357. }
  358. builder.appendf("VMO count: %u\n", MM.m_vmos.size());
  359. builder.appendf("Free physical pages: %u\n", MM.m_free_physical_pages.size());
  360. builder.appendf("Free supervisor physical pages: %u\n", MM.m_free_supervisor_physical_pages.size());
  361. return builder.to_byte_buffer();
  362. }
  363. ByteBuffer procfs$dmesg(InodeIdentifier)
  364. {
  365. InterruptDisabler disabler;
  366. StringBuilder builder;
  367. for (char ch : Console::the().logbuffer())
  368. builder.append(ch);
  369. return builder.to_byte_buffer();
  370. }
  371. ByteBuffer procfs$mounts(InodeIdentifier)
  372. {
  373. // FIXME: This is obviously racy against the VFS mounts changing.
  374. StringBuilder builder;
  375. VFS::the().for_each_mount([&builder] (auto& mount) {
  376. auto& fs = mount.guest_fs();
  377. builder.appendf("%s @ ", fs.class_name());
  378. if (!mount.host().is_valid())
  379. builder.appendf("/");
  380. else {
  381. builder.appendf("%u:%u", mount.host().fsid(), mount.host().index());
  382. builder.append(' ');
  383. auto result = VFS::the().absolute_path(mount.host());
  384. if (result.is_error())
  385. builder.append("[error]");
  386. else
  387. builder.append(result.value());
  388. }
  389. builder.append('\n');
  390. });
  391. return builder.to_byte_buffer();
  392. }
  393. ByteBuffer procfs$df(InodeIdentifier)
  394. {
  395. // FIXME: This is obviously racy against the VFS mounts changing.
  396. StringBuilder builder;
  397. VFS::the().for_each_mount([&builder] (auto& mount) {
  398. auto& fs = mount.guest_fs();
  399. builder.appendf("%s,", fs.class_name());
  400. builder.appendf("%u,", fs.total_block_count());
  401. builder.appendf("%u,", fs.free_block_count());
  402. builder.appendf("%u,", fs.total_inode_count());
  403. builder.appendf("%u,", fs.free_inode_count());
  404. if (!mount.host().is_valid())
  405. builder.append("/");
  406. else {
  407. auto result = VFS::the().absolute_path(mount.host());
  408. if (result.is_error())
  409. builder.append("[Error]");
  410. else
  411. builder.append(result.value());
  412. }
  413. builder.append('\n');
  414. });
  415. return builder.to_byte_buffer();
  416. }
  417. ByteBuffer procfs$cpuinfo(InodeIdentifier)
  418. {
  419. StringBuilder builder;
  420. {
  421. CPUID cpuid(0);
  422. builder.appendf("cpuid: ");
  423. auto emit_dword = [&] (dword value) {
  424. builder.appendf("%c%c%c%c",
  425. value & 0xff,
  426. (value >> 8) & 0xff,
  427. (value >> 16) & 0xff,
  428. (value >> 24) & 0xff);
  429. };
  430. emit_dword(cpuid.ebx());
  431. emit_dword(cpuid.edx());
  432. emit_dword(cpuid.ecx());
  433. builder.appendf("\n");
  434. }
  435. {
  436. CPUID cpuid(1);
  437. dword stepping = cpuid.eax() & 0xf;
  438. dword model = (cpuid.eax() >> 4) & 0xf;
  439. dword family = (cpuid.eax() >> 8) & 0xf;
  440. dword type = (cpuid.eax() >> 12) & 0x3;
  441. dword extended_model = (cpuid.eax() >> 16) & 0xf;
  442. dword extended_family = (cpuid.eax() >> 20) & 0xff;
  443. dword display_model;
  444. dword display_family;
  445. if (family == 15) {
  446. display_family = family + extended_family;
  447. display_model = model + (extended_model << 4);
  448. } else if (family == 6) {
  449. display_family = family;
  450. display_model = model + (extended_model << 4);
  451. } else {
  452. display_family = family;
  453. display_model = model;
  454. }
  455. builder.appendf("family: %u\n", display_family);
  456. builder.appendf("model: %u\n", display_model);
  457. builder.appendf("stepping: %u\n", stepping);
  458. builder.appendf("type: %u\n", type);
  459. }
  460. {
  461. // FIXME: Check first that this is supported by calling CPUID with eax=0x80000000
  462. // and verifying that the returned eax>=0x80000004.
  463. char buffer[48];
  464. dword* bufptr = reinterpret_cast<dword*>(buffer);
  465. auto copy_brand_string_part_to_buffer = [&] (dword i) {
  466. CPUID cpuid(0x80000002 + i);
  467. *bufptr++ = cpuid.eax();
  468. *bufptr++ = cpuid.ebx();
  469. *bufptr++ = cpuid.ecx();
  470. *bufptr++ = cpuid.edx();
  471. };
  472. copy_brand_string_part_to_buffer(0);
  473. copy_brand_string_part_to_buffer(1);
  474. copy_brand_string_part_to_buffer(2);
  475. builder.appendf("brandstr: \"%s\"\n", buffer);
  476. }
  477. return builder.to_byte_buffer();
  478. }
  479. ByteBuffer procfs$kmalloc(InodeIdentifier)
  480. {
  481. StringBuilder builder;
  482. builder.appendf(
  483. "eternal: %u\n"
  484. "allocated: %u\n"
  485. "free: %u\n",
  486. kmalloc_sum_eternal,
  487. sum_alloc,
  488. sum_free
  489. );
  490. return builder.to_byte_buffer();
  491. }
  492. ByteBuffer procfs$summary(InodeIdentifier)
  493. {
  494. InterruptDisabler disabler;
  495. auto processes = Process::all_processes();
  496. StringBuilder builder;
  497. builder.appendf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
  498. for (auto* process : processes) {
  499. builder.appendf("% 3u % 3u % 3u % 3u % 4u % 8s % 3u % 9u % 3u % 4s %s\n",
  500. process->pid(),
  501. process->tty() ? process->tty()->pgid() : 0,
  502. process->pgid(),
  503. process->sid(),
  504. process->uid(),
  505. to_string(process->state()),
  506. process->ppid(),
  507. process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process
  508. process->number_of_open_file_descriptors(),
  509. process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a",
  510. process->name().characters());
  511. }
  512. return builder.to_byte_buffer();
  513. }
  514. ByteBuffer procfs$memstat(InodeIdentifier)
  515. {
  516. InterruptDisabler disabler;
  517. StringBuilder builder;
  518. builder.appendf("%u,%u,%u,%u,%u,%u,%u,%u,%u\n",
  519. kmalloc_sum_eternal,
  520. sum_alloc,
  521. sum_free,
  522. MM.user_physical_pages_in_existence() - MM.m_free_physical_pages.size(),
  523. MM.m_free_physical_pages.size(),
  524. MM.super_physical_pages_in_existence() - MM.m_free_supervisor_physical_pages.size(),
  525. MM.m_free_supervisor_physical_pages.size(),
  526. g_kmalloc_call_count,
  527. g_kfree_call_count
  528. );
  529. return builder.to_byte_buffer();
  530. }
  531. ByteBuffer procfs$all(InodeIdentifier)
  532. {
  533. InterruptDisabler disabler;
  534. auto processes = Process::all_processes();
  535. StringBuilder builder;
  536. auto build_process_line = [&builder] (Process* process) {
  537. builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u,%s\n",
  538. process->pid(),
  539. process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process
  540. process->tty() ? process->tty()->pgid() : 0,
  541. process->pgid(),
  542. process->sid(),
  543. process->uid(),
  544. process->gid(),
  545. to_string(process->state()),
  546. process->ppid(),
  547. process->number_of_open_file_descriptors(),
  548. process->tty() ? process->tty()->tty_name().characters() : "notty",
  549. process->name().characters(),
  550. process->amount_virtual(),
  551. process->amount_resident(),
  552. process->amount_shared(),
  553. process->main_thread().ticks(), // FIXME(Thread): Bill all ticks to the process
  554. to_string(process->priority())
  555. );
  556. };
  557. build_process_line(Scheduler::colonel());
  558. for (auto* process : processes)
  559. build_process_line(process);
  560. return builder.to_byte_buffer();
  561. }
  562. ByteBuffer procfs$inodes(InodeIdentifier)
  563. {
  564. extern HashTable<Inode*>& all_inodes();
  565. StringBuilder builder;
  566. for (auto it : all_inodes()) {
  567. RetainPtr<Inode> inode = *it;
  568. auto result = VFS::the().absolute_path(*inode);
  569. if (result.is_error())
  570. continue;
  571. auto path = result.value();
  572. builder.appendf("Inode{K%x} %02u:%08u (%u) %s\n", inode.ptr(), inode->fsid(), inode->index(), inode->retain_count(), path.characters());
  573. }
  574. return builder.to_byte_buffer();
  575. }
  576. struct SysVariableData final : public ProcFSInodeCustomData {
  577. virtual ~SysVariableData() override { }
  578. enum Type {
  579. Invalid,
  580. Boolean,
  581. String,
  582. };
  583. Type type { Invalid };
  584. Function<void()> notify_callback;
  585. void* address;
  586. };
  587. static ByteBuffer read_sys_bool(InodeIdentifier inode_id)
  588. {
  589. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  590. if (!inode_ptr)
  591. return { };
  592. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  593. ASSERT(inode.custom_data());
  594. auto buffer = ByteBuffer::create_uninitialized(2);
  595. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  596. ASSERT(custom_data.type == SysVariableData::Boolean);
  597. ASSERT(custom_data.address);
  598. auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
  599. {
  600. LOCKER(lockable_bool->lock());
  601. buffer[0] = lockable_bool->resource() ? '1' : '0';
  602. }
  603. buffer[1] = '\n';
  604. return buffer;
  605. }
  606. static ssize_t write_sys_bool(InodeIdentifier inode_id, const ByteBuffer& data)
  607. {
  608. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  609. if (!inode_ptr)
  610. return { };
  611. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  612. ASSERT(inode.custom_data());
  613. if (data.is_empty() || !(data[0] == '0' || data[0] == '1'))
  614. return data.size();
  615. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  616. auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
  617. {
  618. LOCKER(lockable_bool->lock());
  619. lockable_bool->resource() = data[0] == '1';
  620. }
  621. if (custom_data.notify_callback)
  622. custom_data.notify_callback();
  623. return data.size();
  624. }
  625. static ByteBuffer read_sys_string(InodeIdentifier inode_id)
  626. {
  627. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  628. if (!inode_ptr)
  629. return { };
  630. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  631. ASSERT(inode.custom_data());
  632. auto buffer = ByteBuffer::create_uninitialized(2);
  633. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  634. ASSERT(custom_data.type == SysVariableData::String);
  635. ASSERT(custom_data.address);
  636. auto* lockable_string = reinterpret_cast<Lockable<String>*>(custom_data.address);
  637. LOCKER(lockable_string->lock());
  638. return lockable_string->resource().to_byte_buffer();
  639. }
  640. static ssize_t write_sys_string(InodeIdentifier inode_id, const ByteBuffer& data)
  641. {
  642. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  643. if (!inode_ptr)
  644. return { };
  645. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  646. ASSERT(inode.custom_data());
  647. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  648. ASSERT(custom_data.address);
  649. {
  650. auto* lockable_string = reinterpret_cast<Lockable<String>*>(custom_data.address);
  651. LOCKER(lockable_string->lock());
  652. lockable_string->resource() = String((const char*)data.pointer(), data.size());
  653. }
  654. if (custom_data.notify_callback)
  655. custom_data.notify_callback();
  656. return data.size();
  657. }
  658. void ProcFS::add_sys_bool(String&& name, Lockable<bool>& var, Function<void()>&& notify_callback)
  659. {
  660. InterruptDisabler disabler;
  661. unsigned index = m_sys_entries.size();
  662. auto inode = adopt(*new ProcFSInode(*this, sys_var_to_identifier(fsid(), index).index()));
  663. auto data = make<SysVariableData>();
  664. data->type = SysVariableData::Boolean;
  665. data->notify_callback = move(notify_callback);
  666. data->address = &var;
  667. inode->set_custom_data(move(data));
  668. m_sys_entries.append({ strdup(name.characters()), name.length(), read_sys_bool, write_sys_bool, move(inode) });
  669. }
  670. void ProcFS::add_sys_string(String&& name, Lockable<String>& var, Function<void()>&& notify_callback)
  671. {
  672. InterruptDisabler disabler;
  673. unsigned index = m_sys_entries.size();
  674. auto inode = adopt(*new ProcFSInode(*this, sys_var_to_identifier(fsid(), index).index()));
  675. auto data = make<SysVariableData>();
  676. data->type = SysVariableData::String;
  677. data->notify_callback = move(notify_callback);
  678. data->address = &var;
  679. inode->set_custom_data(move(data));
  680. m_sys_entries.append({ strdup(name.characters()), name.length(), read_sys_string, write_sys_string, move(inode) });
  681. }
  682. bool ProcFS::initialize()
  683. {
  684. return true;
  685. }
  686. const char* ProcFS::class_name() const
  687. {
  688. return "ProcFS";
  689. }
  690. RetainPtr<Inode> ProcFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, unsigned size, int& error)
  691. {
  692. (void) parentInode;
  693. (void) name;
  694. (void) mode;
  695. (void) size;
  696. (void) error;
  697. kprintf("FIXME: Implement ProcFS::create_inode()?\n");
  698. return { };
  699. }
  700. RetainPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
  701. {
  702. error = -EROFS;
  703. return nullptr;
  704. }
  705. RetainPtr<Inode> ProcFSInode::parent() const
  706. {
  707. return fs().get_inode(to_parent_id(identifier()));
  708. }
  709. InodeIdentifier ProcFS::root_inode() const
  710. {
  711. return { fsid(), FI_Root };
  712. }
  713. RetainPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
  714. {
  715. #ifdef PROCFS_DEBUG
  716. dbgprintf("ProcFS::get_inode(%u)\n", inode_id.index());
  717. #endif
  718. if (inode_id == root_inode())
  719. return m_root_inode;
  720. if (to_proc_parent_directory(inode_id) == ProcParentDirectory::PDI_Root_sys) {
  721. auto sys_index = to_sys_index(inode_id);
  722. if (sys_index < m_sys_entries.size())
  723. return m_sys_entries[sys_index].inode;
  724. }
  725. LOCKER(m_inodes_lock);
  726. auto it = m_inodes.find(inode_id.index());
  727. if (it == m_inodes.end()) {
  728. auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
  729. m_inodes.set(inode_id.index(), inode.ptr());
  730. return inode;
  731. }
  732. return (*it).value;
  733. }
  734. ProcFSInode::ProcFSInode(ProcFS& fs, unsigned index)
  735. : Inode(fs, index)
  736. {
  737. }
  738. ProcFSInode::~ProcFSInode()
  739. {
  740. LOCKER(fs().m_inodes_lock);
  741. fs().m_inodes.remove(index());
  742. }
  743. InodeMetadata ProcFSInode::metadata() const
  744. {
  745. #ifdef PROCFS_DEBUG
  746. dbgprintf("ProcFSInode::metadata(%u)\n", index());
  747. #endif
  748. InodeMetadata metadata;
  749. metadata.inode = identifier();
  750. metadata.ctime = mepoch;
  751. metadata.atime = mepoch;
  752. metadata.mtime = mepoch;
  753. auto proc_parent_directory = to_proc_parent_directory(identifier());
  754. auto pid = to_pid(identifier());
  755. auto proc_file_type = to_proc_file_type(identifier());
  756. #ifdef PROCFS_DEBUG
  757. dbgprintf(" -> pid: %d, fi: %u, pdi: %u\n", pid, proc_file_type, proc_parent_directory);
  758. #endif
  759. if (is_process_related_file(identifier())) {
  760. auto handle = ProcessInspectionHandle::from_pid(pid);
  761. metadata.uid = handle->process().sys$getuid();
  762. metadata.gid = handle->process().sys$getgid();
  763. }
  764. if (proc_parent_directory == PDI_PID_fd) {
  765. metadata.mode = 00120777;
  766. return metadata;
  767. }
  768. if (proc_parent_directory == PDI_Root_sys) {
  769. metadata.mode = 00100644;
  770. return metadata;
  771. }
  772. switch (proc_file_type) {
  773. case FI_Root_self:
  774. case FI_PID_cwd:
  775. case FI_PID_exe:
  776. metadata.mode = 0120777;
  777. break;
  778. case FI_Root:
  779. case FI_Root_sys:
  780. case FI_PID:
  781. case FI_PID_fd:
  782. metadata.mode = 040777;
  783. break;
  784. default:
  785. metadata.mode = 0100644;
  786. break;
  787. }
  788. #ifdef PROCFS_DEBUG
  789. dbgprintf("Returning mode %o\n", metadata.mode);
  790. #endif
  791. return metadata;
  792. }
  793. ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const
  794. {
  795. #ifdef PROCFS_DEBUG
  796. dbgprintf("ProcFS: read_bytes %u\n", index());
  797. #endif
  798. ASSERT(offset >= 0);
  799. ASSERT(buffer);
  800. auto* directory_entry = fs().get_directory_entry(identifier());
  801. Function<ByteBuffer(InodeIdentifier)> callback_tmp;
  802. Function<ByteBuffer(InodeIdentifier)>* read_callback { nullptr };
  803. if (directory_entry) {
  804. read_callback = &directory_entry->read_callback;
  805. } else {
  806. if (to_proc_parent_directory(identifier()) == PDI_PID_fd) {
  807. callback_tmp = procfs$pid_fd_entry;
  808. read_callback = &callback_tmp;
  809. }
  810. }
  811. ASSERT(read_callback);
  812. ByteBuffer generated_data;
  813. if (!descriptor) {
  814. generated_data = (*read_callback)(identifier());
  815. } else {
  816. if (!descriptor->generator_cache())
  817. descriptor->generator_cache() = (*read_callback)(identifier());
  818. generated_data = descriptor->generator_cache();
  819. }
  820. auto& data = generated_data;
  821. ssize_t nread = min(static_cast<off_t>(data.size() - offset), static_cast<off_t>(count));
  822. memcpy(buffer, data.pointer() + offset, nread);
  823. if (nread == 0 && descriptor && descriptor->generator_cache())
  824. descriptor->generator_cache().clear();
  825. return nread;
  826. }
  827. InodeIdentifier ProcFS::ProcFSDirectoryEntry::identifier(unsigned fsid) const
  828. {
  829. return to_identifier(fsid, PDI_Root, 0, (ProcFileType)proc_file_type);
  830. }
  831. bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
  832. {
  833. #ifdef PROCFS_DEBUG
  834. dbgprintf("ProcFS: traverse_as_directory %u\n", index());
  835. #endif
  836. if (!::is_directory(identifier()))
  837. return false;
  838. auto pid = to_pid(identifier());
  839. auto proc_file_type = to_proc_file_type(identifier());
  840. auto parent_id = to_parent_id(identifier());
  841. callback({ ".", 1, identifier(), 2 });
  842. callback({ "..", 2, parent_id, 2 });
  843. switch (proc_file_type) {
  844. case FI_Root:
  845. for (auto& entry : fs().m_entries) {
  846. // FIXME: strlen() here is sad.
  847. if (!entry.name)
  848. continue;
  849. if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End)
  850. callback({ entry.name, strlen(entry.name), to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type), 0 });
  851. }
  852. for (auto pid_child : Process::all_pids()) {
  853. char name[16];
  854. int name_length = ksprintf(name, "%u", pid_child);
  855. callback({ name, name_length, to_identifier(fsid(), PDI_Root, pid_child, FI_PID), 0 });
  856. }
  857. break;
  858. case FI_Root_sys:
  859. for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
  860. auto& entry = fs().m_sys_entries[i];
  861. callback({ entry.name, strlen(entry.name), sys_var_to_identifier(fsid(), i), 0 });
  862. }
  863. break;
  864. case FI_PID: {
  865. auto handle = ProcessInspectionHandle::from_pid(pid);
  866. if (!handle)
  867. return false;
  868. auto& process = handle->process();
  869. for (auto& entry : fs().m_entries) {
  870. if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
  871. if (entry.proc_file_type == FI_PID_exe && !process.executable_inode())
  872. continue;
  873. // FIXME: strlen() here is sad.
  874. callback({ entry.name, strlen(entry.name), to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 });
  875. }
  876. }
  877. }
  878. break;
  879. case FI_PID_fd: {
  880. auto handle = ProcessInspectionHandle::from_pid(pid);
  881. if (!handle)
  882. return false;
  883. auto& process = handle->process();
  884. for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
  885. auto* descriptor = process.file_descriptor(i);
  886. if (!descriptor)
  887. continue;
  888. char name[16];
  889. size_t name_length = ksprintf(name, "%u", i);
  890. callback({ name, name_length, to_identifier_with_fd(fsid(), pid, i), 0 });
  891. }
  892. }
  893. break;
  894. default:
  895. return true;
  896. }
  897. return true;
  898. }
  899. InodeIdentifier ProcFSInode::lookup(const String& name)
  900. {
  901. ASSERT(is_directory());
  902. if (name == ".")
  903. return identifier();
  904. if (name == "..")
  905. return to_parent_id(identifier());
  906. auto proc_file_type = to_proc_file_type(identifier());
  907. if (proc_file_type == FI_Root) {
  908. for (auto& entry : fs().m_entries) {
  909. if (entry.name == nullptr)
  910. continue;
  911. if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End) {
  912. if (!strcmp(entry.name, name.characters())) {
  913. return to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type);
  914. }
  915. }
  916. }
  917. bool ok;
  918. unsigned name_as_number = name.to_uint(ok);
  919. if (ok) {
  920. bool process_exists = false;
  921. {
  922. InterruptDisabler disabler;
  923. process_exists = Process::from_pid(name_as_number);
  924. }
  925. if (process_exists)
  926. return to_identifier(fsid(), PDI_Root, name_as_number, FI_PID);
  927. }
  928. return { };
  929. }
  930. if (proc_file_type == FI_Root_sys) {
  931. for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
  932. auto& entry = fs().m_sys_entries[i];
  933. if (!strcmp(entry.name, name.characters()))
  934. return sys_var_to_identifier(fsid(), i);
  935. }
  936. return { };
  937. }
  938. if (proc_file_type == FI_PID) {
  939. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier()));
  940. if (!handle)
  941. return { };
  942. auto& process = handle->process();
  943. for (auto& entry : fs().m_entries) {
  944. if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
  945. if (entry.proc_file_type == FI_PID_exe && !process.executable_inode())
  946. continue;
  947. if (entry.name == nullptr)
  948. continue;
  949. if (!strcmp(entry.name, name.characters())) {
  950. return to_identifier(fsid(), PDI_PID, to_pid(identifier()), (ProcFileType)entry.proc_file_type);
  951. }
  952. }
  953. }
  954. return { };
  955. }
  956. if (proc_file_type == FI_PID_fd) {
  957. bool ok;
  958. unsigned name_as_number = name.to_uint(ok);
  959. if (ok) {
  960. bool fd_exists = false;
  961. {
  962. InterruptDisabler disabler;
  963. if (auto* process = Process::from_pid(to_pid(identifier())))
  964. fd_exists = process->file_descriptor(name_as_number);
  965. }
  966. if (fd_exists)
  967. return to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number);
  968. }
  969. }
  970. return { };
  971. }
  972. String ProcFSInode::reverse_lookup(InodeIdentifier child_id)
  973. {
  974. ASSERT(is_directory());
  975. auto proc_file_type = to_proc_file_type(identifier());
  976. if (proc_file_type == FI_Root) {
  977. for (auto& entry : fs().m_entries) {
  978. if (child_id == to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type)) {
  979. return entry.name;
  980. }
  981. }
  982. auto child_proc_file_type = to_proc_file_type(child_id);
  983. if (child_proc_file_type == FI_PID)
  984. return String::format("%u", to_pid(child_id));
  985. return { };
  986. }
  987. // FIXME: Implement
  988. ASSERT_NOT_REACHED();
  989. return { };
  990. }
  991. void ProcFSInode::flush_metadata()
  992. {
  993. }
  994. ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*)
  995. {
  996. auto* directory_entry = fs().get_directory_entry(identifier());
  997. if (!directory_entry || !directory_entry->write_callback)
  998. return -EPERM;
  999. ASSERT(is_persistent_inode(identifier()));
  1000. // FIXME: Being able to write into ProcFS at a non-zero offset seems like something we should maybe support..
  1001. ASSERT(offset == 0);
  1002. bool success = directory_entry->write_callback(identifier(), ByteBuffer::wrap((byte*)buffer, size));
  1003. ASSERT(success);
  1004. return 0;
  1005. }
  1006. KResult ProcFSInode::add_child(InodeIdentifier child_id, const String& name, byte file_type)
  1007. {
  1008. (void)child_id;
  1009. (void)name;
  1010. (void)file_type;
  1011. return KResult(-EPERM);
  1012. }
  1013. KResult ProcFSInode::remove_child(const String& name)
  1014. {
  1015. (void)name;
  1016. return KResult(-EPERM);
  1017. }
  1018. ProcFSInodeCustomData::~ProcFSInodeCustomData()
  1019. {
  1020. }
  1021. size_t ProcFSInode::directory_entry_count() const
  1022. {
  1023. ASSERT(is_directory());
  1024. size_t count = 0;
  1025. traverse_as_directory([&count] (const FS::DirectoryEntry&) {
  1026. ++count;
  1027. return true;
  1028. });
  1029. return count;
  1030. }
  1031. KResult ProcFSInode::chmod(mode_t)
  1032. {
  1033. return KResult(-EPERM);
  1034. }
  1035. ProcFS::ProcFS()
  1036. {
  1037. s_the = this;
  1038. m_root_inode = adopt(*new ProcFSInode(*this, 1));
  1039. m_entries.resize(FI_MaxStaticFileIndex);
  1040. m_entries[FI_Root_mm] = { "mm", FI_Root_mm, procfs$mm };
  1041. m_entries[FI_Root_mounts] = { "mounts", FI_Root_mounts, procfs$mounts };
  1042. m_entries[FI_Root_df] = { "df", FI_Root_df, procfs$df };
  1043. m_entries[FI_Root_kmalloc] = { "kmalloc", FI_Root_kmalloc, procfs$kmalloc };
  1044. m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all };
  1045. m_entries[FI_Root_memstat] = { "memstat", FI_Root_memstat, procfs$memstat };
  1046. m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary };
  1047. m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, procfs$cpuinfo};
  1048. m_entries[FI_Root_inodes] = { "inodes", FI_Root_inodes, procfs$inodes };
  1049. m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg };
  1050. m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self };
  1051. m_entries[FI_Root_pci] = { "pci", FI_Root_pci, procfs$pci };
  1052. m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, procfs$uptime };
  1053. m_entries[FI_Root_sys] = { "sys", FI_Root_sys };
  1054. m_entries[FI_PID_vm] = { "vm", FI_PID_vm, procfs$pid_vm };
  1055. m_entries[FI_PID_vmo] = { "vmo", FI_PID_vmo, procfs$pid_vmo };
  1056. m_entries[FI_PID_stack] = { "stack", FI_PID_stack, procfs$pid_stack };
  1057. m_entries[FI_PID_regs] = { "regs", FI_PID_regs, procfs$pid_regs };
  1058. m_entries[FI_PID_fds] = { "fds", FI_PID_fds, procfs$pid_fds };
  1059. m_entries[FI_PID_exe] = { "exe", FI_PID_exe, procfs$pid_exe };
  1060. m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, procfs$pid_cwd };
  1061. m_entries[FI_PID_fd] = { "fd", FI_PID_fd };
  1062. }
  1063. ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identifier) const
  1064. {
  1065. if (to_proc_parent_directory(identifier) == PDI_Root_sys) {
  1066. auto sys_index = to_sys_index(identifier);
  1067. if (sys_index < m_sys_entries.size())
  1068. return const_cast<ProcFSDirectoryEntry*>(&m_sys_entries[sys_index]);
  1069. return nullptr;
  1070. }
  1071. auto proc_file_type = to_proc_file_type(identifier);
  1072. if (proc_file_type != FI_Invalid && proc_file_type < FI_MaxStaticFileIndex)
  1073. return const_cast<ProcFSDirectoryEntry*>(&m_entries[proc_file_type]);
  1074. return nullptr;
  1075. }
  1076. KResult ProcFSInode::chown(uid_t, gid_t)
  1077. {
  1078. return KResult(-EPERM);
  1079. }