ProcFS.cpp 38 KB

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